本文整理汇总了C#中IRepository.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.GetById方法的具体用法?C# IRepository.GetById怎么用?C# IRepository.GetById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRepository
的用法示例。
在下文中一共展示了IRepository.GetById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchModule
public MatchModule(IRepository<Match> matchRepository, IRepository<Country> countryRepository)
: base("/matches")
{
Get["/"] = parameters =>
{
var matches = matchRepository.FindAll();
var resource = matches.ToArray().Select(
m => new MatchResource
{
Id = m.Id,
Date = m.Date,
Team1CountryId = m.Team1.Country.Id,
Team2CountryId = m.Team2.Country.Id
});
return Response.AsJson(resource);
};
Post["/"] = parameters =>
{
var resource = this.Bind<MatchResource>();
var country1 = countryRepository.GetById(resource.Team1CountryId);
if (country1 == null)
return HttpStatusCode.BadRequest;
var country2 = countryRepository.GetById(resource.Team2CountryId);
if (country2 == null)
return HttpStatusCode.BadRequest;
var match = Match.Create(
resource.Date,
country1,
country2);
matchRepository.Add(match);
return Response.AsRedirect("/matches/" + match.Id);
};
Get["/{id}"] = parameters =>
{
var match = matchRepository.GetById((int)parameters.Id);
if (match == null)
return HttpStatusCode.NotFound;
return Response.AsJson(new
{
Date = match.Date,
Team1 = match.Team1,
Team2 = match.Team2
});
};
}
示例2: CacheById
/// <summary>
/// 从缓存中读取指定实体类型的所有数据。
/// 如果缓存中不存在,或者缓存数据已经过期,则调用 GetByIdCore 方法获取数据,并把最终数据加入到缓存中。
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="id">The unique identifier.</param>
/// <returns></returns>
internal Entity CacheById(IRepository repository, object id)
{
Entity result = null;
var sd = repository.EntityMeta.ClientCacheDefinition;
if (sd != null)
{
var entityType = repository.EntityType;
var className = entityType.Name;
var key = GetCacheKey(id);
//AggregateChecker 不支持序列化,所以这里只用内在缓存即可。
result = this.Cache.Get(key, className) as Entity;
if (result == null)
{
result = repository.GetById(id);
if (result != null)
{
var policy = CreatePolicy(entityType, id);
this.Cache.Add(key, result, policy, className);
}
}
}
return result;
}
示例3: CleanImageData
public static void CleanImageData(IRepository<Immagine> repository, string id)
{
if (string.IsNullOrEmpty(id)) return;
RemoveFromDisk(id); //rimuove la cache da disco
var immagine = repository.GetById(id);
if (immagine == null) return;
RemoveFromCloudRepository(immagine); //rimuove dalla repository di azure
repository.DeleteOnSubmit(immagine); //rimuove dal db
}
示例4: NamePerson
private static void NamePerson(IRepository<PersonDTO> personReadModel)
{
Console.Write("Enter person's Name: ");
var name = Console.ReadLine();
var id = Guid.NewGuid();
var person = new Person(id);
person.NameMe(name);
var personDTO = personReadModel.GetById(id);
Console.WriteLine("Person ID: " + personDTO.Id);
Console.WriteLine("Person Name: " + personDTO.Name);
Console.WriteLine("Person Was Renamed: " + personDTO.WasRenamed);
}
示例5: SampleMethod
private static void SampleMethod(IRepository<Product,int?> productRepository)
{
SessionProvider.RebuildSchema();
//Create a Product
var pNew = new Product { ProductName = "Canned Salmon" };
productRepository.Save(pNew);
//Get a Product
var pGet = productRepository.GetById(pNew.ProductId);
//Update a Product
pGet.ProductName = "Canned Tuna";
productRepository.Save(pGet);
//Delete a Product
productRepository.Delete(pNew);
}
示例6: NameAndRenamePerson
private static void NameAndRenamePerson(IRepository<PersonDTO> personReadModel)
{
Console.Write("Enter person's Name: ");
var name = Console.ReadLine();
var id = Guid.NewGuid();
var person = new Person(id);
person.NameMe(name);
Console.Write("Enter person's Name: ");
var renamedName = Console.ReadLine();
person = EventStore.Instance.GetById<Person>(id);
//can also do this:
// person = MongoEventStore.Instance.GetById(id) as Person;
person.NameMe(renamedName);
var personDTO = personReadModel.GetById(id);
Console.WriteLine("Person ID: " + personDTO.Id);
Console.WriteLine("Person Name: " + personDTO.Name);
Console.WriteLine("Person Was Renamed: " + personDTO.WasRenamed);
}
示例7: App_Startup
void App_Startup(object sender, StartupEventArgs e)
{
IoCManager.Start();
_userRepository = IoCManager.Kernel.Get<IRepository<User>>();
//TO DO think how to improve quality of this solution.
//Perhaps create some buffer
//like LocalStorage or Cookies for registration purpose.
var currentUser = _userRepository.GetById(1);
if (currentUser != null)
{
CurrentUser = currentUser.Name;
MyBoooks myBoooks = new MyBoooks();
myBoooks.Show();
}
else
{
Registration window = new Registration();
window.Show();
}
}
示例8: UpdateSingleImage
public static Immagine UpdateSingleImage(IRepository<Immagine> immagineRepository,
IUploadImageService uploadImageService, string oldId, ImmagineRawViewModel img, string idPadre,
string tipoPadre)
{
if (img == null) return null;
if (img.File == null)
{ //aggiorno i POIPerc dell'immagine precedente
if (string.IsNullOrEmpty(oldId)) return null;
var oldImg = immagineRepository.GetById(oldId);
if (oldImg == null) return null;
oldImg.PoiPercX = img.PoiPercX;
oldImg.PoiPercY = img.PoiPercY;
return oldImg;
}
if (!string.IsNullOrEmpty(oldId))
CleanImageData(immagineRepository, oldId);
//inserisco la nuova immagine
var images = uploadImageService.UploadImages(new List<HttpPostedFileBase>{img.File}, idPadre,
tipoPadre, true);
var result = images != null && images.Any() ? images.First() : null;
if (result == null) return null;
result.PoiPercX = img.PoiPercX;
result.PoiPercY = img.PoiPercY;
return result;
}
示例9: Edit
public JsonResult Edit(BonusDto bonusDto)
{
if (bonusDto == null)
throw new ArgumentNullException("bonusDto can not be null in controller Edit");
Employee employee = null;
BonusAggregate bonus = null;
using (var dbContext = new DatabaseContext())
{
if (bonusDto.EmployeeId != 0)
{
var employeeRepository = new EmployeesRepository(dbContext);
employee = employeeRepository.GetById(bonusDto.EmployeeId);
}
BonusesRepository = new BonusesRepository(dbContext);
bonus = BonusesRepository.GetById(bonusDto.BonusId);
bonus.Comment = bonusDto.Comment;
bonus.Amount = bonusDto.Amount;
bonus.Date = bonusDto.Date;
bonus.IsActive = bonusDto.IsActive;
if (employee != null &&
employee.EmployeeId != bonus.EmployeeId)
{
bonus.Employee = employee;
}
BonusesRepository.Save(bonus);
}
return Json(bonus);
}
示例10: GetEmployeeById
/// <summary>
/// Gets the employee by id.
/// </summary>
/// <param name="id">The id.</param>
/// <returns>Employee.</returns>
private Employee GetEmployeeById(int id = 1)
{
Employee employee;
using (var dbContext = new DatabaseContext(TestUser, TestPass))
{
employeeRepository = new EmployeesRepository(dbContext);
employee = employeeRepository.GetById(id);
}
return employee;
}
示例11: Save_BonusesList_2BonusesUpdated
public void Save_BonusesList_2BonusesUpdated()
{
IList<BonusAggregate> bonusesToUpdate;
IList<BonusAggregate> updatedBonuses = new List<BonusAggregate>();
var bonusesIds = new int[2];
string newComment = "comment on " + DateTime.Now;
using (var dbContext = new DatabaseContext(TestUser, TestPass))
{
bonusRepository = new BonusesRepository(dbContext);
bonusesToUpdate = bonusRepository.FindAll().Take(2).ToList();
bonusesToUpdate[0].Comment = newComment;
bonusesToUpdate[1].Comment = newComment;
bonusesIds[0] = bonusesToUpdate[0].BonusId;
bonusesIds[1] = bonusesToUpdate[1].BonusId;
bonusRepository.Save(bonusesToUpdate);
}
using (var dbContext = new DatabaseContext(TestUser, TestPass))
{
bonusRepository = new BonusesRepository(dbContext);
updatedBonuses.Add(bonusRepository.GetById(bonusesIds[0]));
updatedBonuses.Add(bonusRepository.GetById(bonusesIds[1]));
}
Assert.AreEqual(updatedBonuses[0].Comment, newComment);
Assert.AreEqual(updatedBonuses[1].Comment, newComment);
}
示例12: Before_each
protected override void Before_each()
{
base.Before_each();
_repo = new Repository<AssaultItem>(CreateSessionFactory());
_itemToDelete = _repo.GetById(1);
}
示例13: Create
public static UserListViewModel Create(IUserBLL userBLL, IRepository<Project> projectRepository, int? filterProjectId)
{
var users = filterProjectId == null
? userBLL.GetAllUsers()
: userBLL.GetAllUsers().Where(x => x.Projects.Contains(projectRepository.GetById(filterProjectId.Value)));
var viewModel = new UserListViewModel
{
Users = users.ToList(),
Projects = userBLL.GetAllProjectsByUser(projectRepository).ToList(),
SelectedFilterProjectId = filterProjectId
};
return viewModel;
}
示例14: LoadReadingList
private void LoadReadingList()
{
_userRepository = IoCManager.Kernel.Get<IRepository<User>>();
_user = _userRepository.GetById(1);
_readinglistContent = _user.ReadingList.RadingList;
}
示例15: CountryModule
// TODO: let's do content negotiation ourselves unless there is a nice
// way to do it in Nancy like there seems to be for most things
public CountryModule(IRepository<Domain.Country> countryRepository, CountryFactory countryFactory)
: base("/countries")
{
Get["/"] = parameters =>
{
var countryResources = countryRepository.FindAll()
.Select(c => new Country {id = c.Id.ToString(), Name = c.Name});
var resource = countryResources.ToArray();
return Response.AsJson(resource);
};
Get["/{id}"] = parameters =>
{
var country = countryRepository.GetById((int)parameters.id);
if (country == null)
return HttpStatusCode.NotFound;
var resource = new Country {id = country.Id.ToString(), Name = country.Name};
return Response.AsJson(resource);
};
Post["/"] = parameters =>
{
var countryResource = this.Bind<Country>(blacklistedProperties:"id");
var validationResult = this.Validate(countryResource);
if (! validationResult.IsValid)
{
var response = Response.AsJson(validationResult.Errors);
response.StatusCode = HttpStatusCode.BadRequest;
return response;
}
var country = countryFactory.CreateCountry(countryResource.Name);
countryRepository.Add(country);
return Response.AsRedirect("/countries/"+country.Id);
};
Put["/{id}"] = parameters =>
{
var country = countryRepository.GetById((int) parameters.id);
if (country == null)
return HttpStatusCode.NotFound; // this correct for a put? should probably be some error
// we don't actually support updates to countries!
//country.Name = parameters.Name;
return Response.AsRedirect("/countries/" + country.Id);
};
Delete["/{id}"] = parameters =>
{
var country = countryRepository.GetById((int)parameters.id);
if (country == null)
return HttpStatusCode.NotFound; // this correct for a put? should probably be some error
countryRepository.Remove(country);
return HttpStatusCode.OK;
};
}