public IItem getItemByCode(string code) { DAL.Entities.Item found = repository.ItemRepository.GetAll(). Where(item => item.Code == code). Include(item => item.Names). FirstOrDefault(); return(Assembler.Assemble(found)); }
private DAL.Entities.OrderItem AssembleItem(ICreateOrderItemData item, IEnumerable <DAL.Entities.Item> items) { DAL.Entities.Item foundItem = items.First(i => i.Code == item.Code); return(new DAL.Entities.OrderItem { Item = foundItem, Count = item.Count, Price = foundItem.Price }); }
public string createItem(IBriefItem item) { DAL.Entities.Item assembled = new DAL.Entities.Item { Code = itemCodeGenerator.generateCode(), Price = item.Price, Category = Assembler.Assemble(item.Category), AddingTime = DateTime.UtcNow, Names = Assembler.Assemble(item.Names) }; repository.ItemRepository.Create(assembled); repository.Save(); return(assembled.Code); }
public void changeItem(IChangeItemData itemData) { DAL.Entities.Item foundItem = repository.ItemRepository.GetAll().Include(item => item.Names). First(item => item.Code == itemData.Code); if (itemData.NewPrice != null) { foundItem.Price = itemData.NewPrice.Value; } if (itemData.NewCategory != null) { foundItem.Category = Assembler.Assemble(itemData.NewCategory.Value); } foreach (DAL.Entities.ItemName itemName in foundItem.Names) { switch (itemName.LanguageType) { case DAL.Entities.LanguageType.English: if (!string.IsNullOrEmpty(itemData.NewEnName)) { itemName.Name = itemData.NewEnName; } break; case DAL.Entities.LanguageType.Russian: if (!string.IsNullOrEmpty(itemData.NewRuName)) { itemName.Name = itemData.NewRuName; } break; case DAL.Entities.LanguageType.Ukrainian: if (!string.IsNullOrEmpty(itemData.NewUkName)) { itemName.Name = itemData.NewUkName; } break; } } repository.ItemRepository.Update(foundItem); repository.Save(); }
public static IItem Assemble(DAL.Entities.Item item) { return(new Item(item.Code, item.Price, Assemble(item.Category), item.AddingTime, Assemble(item.Names))); }
public void deleteItemByCode(string code) { DAL.Entities.Item foundItem = repository.ItemRepository.GetAll().First(item => item.Code == code); repository.ItemRepository.Delete(foundItem.Id); repository.Save(); }