public ItemController(IItemRepository repository) { _repository = repository; var flourItem = new Item { Name = "Flour", Quantity = new Quantity() { Unit = "L", Total = 1 } }; _repository.Add(flourItem); var eggItem = new Item { Name = "Egg", Quantity = new Quantity() { Unit = "P", Total = 8 } }; _repository.Add(eggItem); _fridgeService = new FridgeService(_repository); }
public async Task ItemRepository_GetItems_Success() { // Arrange SetupEnvironment(); var item = new Item() { Id = "d3ab2dfa878227b15f1a0575", Name = "Rose", Description = "Thorns", Price = 12, Quantity = 5 }; await _itemRepository.Add(item); // Act var result = await _itemRepository.GetAll(); // Assert Assert.NotEmpty(result); Assert.Single(result.ToList()); Assert.Equal(item.Id, result.First().Id); Assert.Equal(item.Name, result.First().Name); Assert.Equal(item.Id, result.First().Id); _context.DropDatabase(); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public long Add(object model) { try { var itemObj = (dynamic)model; var product = itemObj.ProductId == null? _productService.GetByProductCode(itemObj.ProductCode.Value) : null; var brand = itemObj.BrandId == null? _brandService.GetByBrandCode(((dynamic)itemObj).BrandCode.Value) : null; var item = new Item { CustomerId = itemObj.CustomerId != null ? itemObj.CustomerId.Value : null, ProductId = itemObj.ProductId != null ? itemObj.ProductId.Value : product.Id, BrandId = itemObj.BrandId != null ? itemObj.BrandId.Value : brand.Id, ItemCode = itemObj.ItemCode != null ? itemObj.ItemCode.Value : "", Description = itemObj.Description != null ? itemObj.Description.Value : "", ReceivedBy = itemObj.ReceivedBy != null ? itemObj.ReceivedBy.Value : "", ReceivedDate = itemObj.ReceivedDate != null ? itemObj.ReceivedDate.Value : (DateTime?)null, ExpiryDate = itemObj.ExpiryDate != null ? itemObj.ExpiryDate.Value : (DateTime?)null, CreatedBy = itemObj.CreatedBy != null ? itemObj.CreatedBy.Value : "" }; long retId = 0; if (IsDuplicate(item.ItemCode, item.Id, item.CustomerId) == false) { retId = _itemRepository.Add(item); } else { Expression <Func <Item, bool> > res = x => x.ItemCode == item.ItemCode && x.CustomerId == item.CustomerId && x.IsActive == false; var obj = _itemRepository.Get(res); if (obj != null) { retId = obj.Id; item.Id = retId; item.IsActive = true; _itemRepository.Detach(obj); _itemRepository.Update(item); //return item.Id; } } return(retId); } catch (Exception ex) { throw; } }
public ItemViewModel AddItem(ItemViewModel item) { var newItem = ItemMapper.MapModelToEntity(item); newItem.CreatedBy = "TEST"; newItem.SeedData = false; var addedItem = _itemRepository.Add(newItem); return(ItemMapper.MapEntityToModel(addedItem)); }
public void SaveItem(Item item) { if (item.ItemID > 0) { ItemRepo.Update(item); } else { ItemRepo.Add(item); } ItemRepo.SaveChanges(); }
public void AddItem(Item newItem) { List <Item> data = new List <Item>(); data = _itemRepository.GetItems(); // fetch the entire database int Total = data.Where(x => x.AvailableDate == newItem.AvailableDate).Count(); var count = 0; var flag = 0; if (Total < 15) { foreach (var Element in data) { if (Element.ItemName == newItem.ItemName) { break; // " with same name already exist for the date"; } else { flag = 1; } } } if (flag == 1) { if (newItem.IsSpecial == true) { foreach (var Element in data) { if (Element.AvailableDate == newItem.AvailableDate) { if (Element.IsSpecial == true) { count++; } } } if (count < 4) { _itemRepository.Add(newItem); } } else { _itemRepository.Add(newItem); } } }
public Quantity AddItem(Item item) { _repository.Add(item); List <Item> items = _repository.GetAll(); return(items.FirstOrDefault(x => x.Name == item.Name).Quantity); }
public IActionResult AddNewItem(Item item) { item.ImgPath = imgPath; _itemRepository.Add(item); _itemRepository.Commit(); return(RedirectToAction("Details", new { id = item.Id })); }
public async Task <Guid> Handle(CreateItem command) { var id = Guid.NewGuid(); await _repo.Add(new Item(id, command.Name, command.Description, command.Traits)); return(id); }
public Item Add(Item Item) { var item = _ItemRepository.Add(Item); _unitOfWork.Commit(); if (!string.IsNullOrEmpty(Item.Tags)) { string[] tags = Item.Tags.Split(','); for (var i = 0; i < tags.Length; i++) { var tagId = StringHelper.ToUnsignString(tags[i]); if (_tagRepository.Count(x => x.ID == tagId) == 0) { Tag tag = new Tag(); tag.ID = tagId; tag.Name = tags[i]; tag.Type = CommonConstants.ProductTag; _tagRepository.Add(tag); } ProductTag productTag = new ProductTag(); productTag.ProductID = Item.ID; productTag.TagID = tagId; _ItemTagRepository.Add(productTag); } } return(Item); }
public Result <Item> Add(Item item) { var result = new Result <Item>(); if (item == null) { result.AddMessage("Item must not be null."); return(result); } if (string.IsNullOrWhiteSpace(item.Name)) { result.AddMessage("Item name is required."); } else if (repository.FindAll() .Any(i => i.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase))) { result.AddMessage($"Item '{item.Name}' is a duplicate."); } if (item.DollarsPerKilogram < 0M || item.DollarsPerKilogram > 7500M) { result.AddMessage("$/Kg must be between 0.00 and 7500.00."); } if (!result.Success) { return(result); } result.Value = repository.Add(item); return(result); }
public Task Handle(AddNewItemCommand request, CancellationToken cancellationToken) { var item = new Item(); item.Name = request.Name; item.Description = request.Description; item.Price = request.Price; var category = _categoryRepository.GetById(request.CategoryId); item.Category = category; var itemValues = new List <ItemValue>(); for (var i = 0; i < request.CategoryFieldIds.Count; i++) { var categoryField = _categoryFieldRepository.GetById(request.CategoryFieldIds[i]); itemValues.Add(new ItemValue { Field = categoryField, FieldValue = request.FieldValues[i] }); } item.ItemValues = itemValues; _itemRepository.Add(item); Commit(); return(Task.CompletedTask); }
public Item EnsureItemWithUnit(string itemDescription) { itemDescription = itemDescription ?? ""; var parts = itemDescription.Split(','); string name = parts[0].Trim(); string unit = parts.Count() > 1 ? parts[1] : null; if (string.IsNullOrWhiteSpace(name)) { throw new Exception($"Incorrect item description provided: {itemDescription}"); } var entity = _rep.GetByText(name); if (entity == null) { entity = new ItemEntity { Text = name, Unit = CodeUtils.CreateCode(unit), Code = CodeUtils.CreateCode(name) }; _rep.Add(entity); } return(ItemMapper.MapToModel(entity)); }
public IActionResult CreateItem(ItemCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(model); Item newItem = new Item { Category = model.Category, Name = model.Name, shortDescription = model.shortDescription, LongDescription = model.LongDescription, AllergyInformation = model.AllergyInformation, Price = model.Price, Discount = model.Discount, Size = model.Size, Quantity = model.Quantity, UnitsInOrder = model.UnitsInOrder, isItemOfTheWeek = model.isItemOfTheWeek, InStock = model.InStock, Customise = model.Customise, CustomisedType = model.CustomisedType, CustomisedOption = model.CustomisedOption, Discontinued = model.Discontinued }; _itemRepository.Add(newItem); return(RedirectToAction("Details", new { id = newItem.ItemId })); } return(View()); }
public void Post(List <Item> entity) { if (ModelState.IsValid) { _repository.Add(entity); } }
public IActionResult OnPost() { if (ModelState.IsValid) { Item.Topics = Topics; Item.Consumers = Consumers; if (ScreenShotPhoto != null) { if (Item.ScreenShotPath != null) { string filePath = Path.Combine(webHostEnvironment.WebRootPath, "catalogScreenShots", Item.ScreenShotPath); System.IO.File.Delete(filePath); } Item.ScreenShotPath = ProcessUploadedFile(ScreenShotPhoto); } if (Item.Id > 0) { Item = itemRepository.Update(Item); } else { Item = itemRepository.Add(Item); } return(RedirectToPage("index")); } // In the event there are validation issues we can re-render the page // so the user can correct any errors. return(Page()); }
public IActionResult Create([FromBody] TMeasurement item) { try { if (item == null || !ModelState.IsValid) { return(BadRequest("Invalid State")); } ItemRepository.Add(item); } catch (Exception) { return(BadRequest("Error while creating")); } return(Ok(item)); }
public async Task <ItemResponse> AddItemAsync(AddItemRequest request) { var item = _itemMapper.Map(request); var result = _itemRepository.Add(item); await _itemRepository.UnitOfWork.SaveChangesAsync(); return(_itemMapper.Map(result)); }
public async Task <IActionResult> CreateEntity([FromBody] ItemEntity item) { Console.WriteLine("Adding item with title: " + item.Title); item.DateCreated = DateTime.Now; _dbLogic.Add(item); _dbLogic.GenerateTags(item); unitOfWork.Commit(); return(Ok(item)); }
public async Task <IActionResult> Post([FromBody] ItemViewModel itemViewModel) { var item = mapper.Map <Item>(itemViewModel); itemRepository.Add(item, User.GetMuseumId()); await unitOfWork.SaveChangesAsync(); return(Ok(mapper.Map <ItemViewModel>(item))); }
public DomainItem CreateEntity(DomainItemUpdateModel item) { validator.ValidatePlayer(item); if (item == null) { throw new ArgumentNullException("Item is null"); } return(itemDB.Add(item)); }
public IActionResult AddItem(string value) { if (!string.IsNullOrEmpty(value)) { itemRepository.Add(value); } return(RedirectToAction("Todo")); }
public Item Add(Item item) { item.Id = Guid.NewGuid(); if (Validate(item)) { return(_itemRepository.Add(item)); } return(null); }
public async Task <IActionResult> Post(ItemForAddDTO model) { Item item = mapper.Map <Item>(model); await itemRepository.Add(item).ConfigureAwait(true); await unitOfWork.CompleteAsync().ConfigureAwait(true); return(Ok(mapper.Map <ItemForGetDTO>(await itemRepository.Get(item.Id).ConfigureAwait(true)))); }
public async Task <ItemResponse> Handle(AddItemCommand command, CancellationToken cancellationToken) { var item = _mapper.Map <Entities.Item>(command); var result = _itemRepository.Add(item); await _itemRepository.UnitOfWork.SaveChangesAsync(cancellationToken); return(_mapper.Map <ItemResponse>(result)); }
public ActionResult Create(LoanItem loanItem) { if (!ModelState.IsValid) { return(View("Create", loanItem)); } _itemRepository.Add(loanItem); return(RedirectToAction("Index")); }
public ValidationResult Add(Item item) { if (!item.IsValid) { return(item.ValidationErrors.ToValidationResult()); } _validationResult.Entity = _repository.Add(item); return(_validationResult); }
public async Task <ItemResponse> Add(ItemRequest itemRequest) { var item = _mapper.Map <Item>(itemRequest); await _itemRepository.Add(item); var itemResponse = _mapper.Map <ItemResponse>(item); return(itemResponse); }
/// <summary> /// This method adds a person to the server side repository. /// </summary> /// <param name="person">The person to add</param> /// <returns>A response message with the new id of the person added</returns> public HttpResponseMessage PostPerson(Person person) { person = repository.Add(person); var response = Request.CreateResponse(HttpStatusCode.Created, person); string uri = Url.Link("DefaultApi", new { id = person.Id }); response.Headers.Location = new Uri(uri); return(response); }
public Item Add(Item newItem) { Item resource = _itemRepo.Add(newItem); if (resource == null) { throw new ApplicationException("That resource already exists. You can't create a duplicate of the same resource."); } return(resource); }