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 }); }; }
/// <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; }
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 }
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); }
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); }
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); }
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(); } }
// 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; }; }
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; }
public ViewResult Details(int id) { var model = instructorRepo.GetById(id); return(View(model)); }
public virtual T GetById(int id) { return(_repository.GetById(id)); }
public ViewResult Details(int id) { var model = contentRepo.GetById(id); return(View(model)); }
public T GetById(int id) { return(GenericRepository.GetById(id)); }
protected override void Before_each() { base.Before_each(); _repo = new Repository<AssaultItem>(CreateSessionFactory()); _itemToDelete = _repo.GetById(1); }
public FormFieldsRecord GetFieldById(int Id) { return(_formFieldsRepository.GetById(Id)); }
public Domain.FormsRecord GetFormById(int FormId) { return(_formRepository.GetById(FormId)); }
public IActionResult GetById(int id) { var item = _mapper.Map <ToDoItem, ToDoItemDTO>(_todoRepository.GetById(id)); return(Ok(item)); }
public UserGroup GetById(object id) { return(_userGroupRepository.GetById(id)); }
public ProductCategoryModel Get(int id) { return(id > 0 ? _productCategoryRepository.GetById(id).ToModel() : new ProductCategoryModel()); }
public D_Item_Relationship GetChildItemByID(int id) { return _itemRelationshipRepository.GetById(id); }
public D_Item GetItemByID(int id) { var item = _itemRepository.GetById(id); return item; }
public virtual Tenant GetByID(int id) { return(_tenantRepository.GetById(id)); }
public User GetById(int id) { return(_ur.GetById(id)); }
public RedirectToRouteResult CompleteCart(CheckoutViewModel model) { DateTime orderTime = DateTime.Now; Order order = null; int addressId = -1; Order verifyInsertion = null; string name = this.HttpContext.User.Identity.Name; var currentUser = this.userRepo.GetAll().Where(u => u.UserName == name).First(); //Check if user entered new address or used old one if (model.Address == null || model.Address == string.Empty) { if (model.NewAddress != null && model.NewAddress != string.Empty) { Address addressToAdd = new Address() { Address1 = model.NewAddress }; //Add new address to address repo addressRepo.Insert(addressToAdd); addressRepo.Save(); currentUser.Addresses.Add(addressToAdd); userRepo.Save(); addressId = addressToAdd.AddressId; } } else { try { int.TryParse(model.Address, out addressId); } catch (Exception) { throw; } } if (addressId >= 1) { order = new Order() { ClientId = currentUser.Id, OrderTime = orderTime, DeliveryAddressId = addressId, OrderDeliverd = false, OrderPrice = ((Cart)Session["Cart"]).TotalPrice(), OrderPrepared = false, IsActive = true, ExtraSpecifications = model.ExtraSpecifications, }; //We add the order to the database. orderRepo.Insert(order); orderRepo.Save(); //We add the order reference to each of the dishes. foreach (CartLine line in ((Cart)Session["Cart"]).Lines) { //We add the order reference to the dishes in the //cart session to ensure the many to many relationship. var currentDish = dishRepo.GetById(line.Dish.DishId); currentDish.Orders.Add(order); orderRepo.Save(); } orderRepo.Save(); dishRepo.Save(); verifyInsertion = orderRepo.GetById(order.OrderId); Debug.WriteLine($"{order.Dishes.Count()}"); } else { return(RedirectToAction("CompleteCart")); } //check if order got registered. if (verifyInsertion != null) { return(RedirectToAction("Completed", new { orderId = order.OrderId })); } else { return(RedirectToAction("CompleteCart")); } }
public IngredientModel GetIngredientById(int id) { return(IngredientMapper.IngredientToIngredientModel(_ingredientRepo.GetById(id))); }
public BusinessAdmin GetById(int id) { return(_BusinessAdRepository.GetById(id)); }
public Comment Get(int id) { return(CommentRepo.GetById(id)); }
public Book GetById(int id) { return(_bookRepository.GetById(id)); }
public User GetUser(long id) { return(_userRepository.GetById(id)); }
/// <summary> /// Gets a category template /// </summary> /// <param name="categoryTemplateId">Category template identifier</param> /// <returns>Category template</returns> public virtual CategoryTemplate GetCategoryTemplateById(string categoryTemplateId) { return(_categoryTemplateRepository.GetById(categoryTemplateId)); }
public Product GetById(int id) { return(_productRepository.GetById(id)); }
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); }
public TEntity GetById(object id) { var entity = _repository.GetById(id); return(entity); }
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); }
/// <summary> /// Gets the by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public async Task <Transaction> GetById(Guid id) { return(_transactionRepository.GetById(id)); }
private void LoadReadingList() { _userRepository = IoCManager.Kernel.Get<IRepository<User>>(); _user = _userRepository.GetById(1); _readinglistContent = _user.ReadingList.RadingList; }
public virtual TEntity FindBy(TKey id) { return(_repository.GetById(id)); }
public Category GetCategory(int id) { var category = _categoryRepo.GetById(id); return(category); }
public void GetById_NoParams_Bonus() { BonusAggregate bonusAggregate; using (var dbContext = new DatabaseContext(TestUser, TestPass)) { bonusRepository = new BonusesRepository(dbContext); bonusAggregate = bonusRepository.GetById(1); } Assert.AreEqual(1, bonusAggregate.BonusId); }
public User Get(int id) { return(_userRepository.GetById(id)); }
/// <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; }
public T GetById(int id) { return(_repository.GetById(id)); }
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; }
/// <summary> /// Gets a banner by identifier /// </summary> /// <param name="bannerId">Banner identifier</param> /// <returns>Banner</returns> public virtual Banner GetBannerById(string bannerId) { return(_bannerRepository.GetById(bannerId)); }
public Artist Get(int id) { return(artistRepo.GetById(id)); }
public PersonnelShiftAssignmentDisplayDto GetById(int id) { var assignment = _personnelShiftAssignmentRepository.GetById(id); return(Mapper.Map <PersonnelShiftAssignmentDisplayDto>(assignment)); }
public Stock(IRepository<Product, int> repository, int id) { this.repository = repository; this.product = repository.GetById(id); }
protected override void Before_each() { base.Before_each(); _repo = new Repository<AssaultItem>(CreateSessionFactory()); _item = _repo.GetById(2); _item.Description = _descUpdate; }