public async Task <IActionResult> Edit(int id, [Bind("Id,FlowerId,SupplyId,Amount")] SupplyFlower supplyFlower) { if (id != supplyFlower.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _unitOfWork.SupplyFlowers.Update(supplyFlower); await _unitOfWork.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SupplyFlowerExists(supplyFlower.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", supplyFlower.FlowerId); ViewData["SupplyId"] = new SelectList(_unitOfWork.Supplies.GetAll(), "Id", "Id", supplyFlower.SupplyId); return(View(supplyFlower)); }
public async Task Remove(SupplyFlower value) { if (value != null) { dbcontext.Entry(value).State = EntityState.Deleted; await dbcontext.SaveChangesAsync(); } }
public ActionResult Create(SupplyFlower supplyFlower) { if (ModelState.IsValid) { var newSupplyFlower = supplyFlowersService.Create(supplyFlower); return(RedirectToAction("Details", new { id = newSupplyFlower.Id })); } return(View()); }
public async Task <ActionResult> Edit(SupplyFlower PlantationFlower) { if (ModelState.IsValid) { await dataManager.SupplyFlowers.Update(PlantationFlower); return(RedirectToAction(nameof(PlantationFlowersController.Index))); } return(View(PlantationFlower)); }
public ActionResult Edit(SupplyFlower supplyFlower) { if (ModelState.IsValid) { supplyFlowersService.Update(supplyFlower); return(RedirectToAction("Details", new { id = supplyFlower.Id })); } return(View(supplyFlower)); }
public async Task <IActionResult> Create([Bind("Id,FlowerId,SupplyId,Amount")] SupplyFlower supplyFlower) { if (ModelState.IsValid) { _unitOfWork.SupplyFlowers.Create(supplyFlower); await _unitOfWork.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", supplyFlower.FlowerId); ViewData["SupplyId"] = new SelectList(_unitOfWork.Supplies.GetAll(), "Id", "Id", supplyFlower.SupplyId); return(View(supplyFlower)); }
public IActionResult FlowerEdit(SupplyFlower supplyFlower) { if (!ModelState.IsValid) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); return(View(supplyFlower)); } _flowerServiceRepository.SupplyRepository.UpdateSupplyFlower(supplyFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = supplyFlower.SupplyId })); }
public IActionResult FlowerCreate(int?id) { if (id == null || _flowerServiceRepository.SupplyRepository.Get(id.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); SupplyFlower supplyFlower = new SupplyFlower { SupplyId = id.Value }; return(View(supplyFlower)); }
public IActionResult FlowerDelete(int?supplyId, int?flowerId) { if (supplyId != null || flowerId != null || _flowerServiceRepository.SupplyRepository.Get(supplyId.Value) != null) { Supply supply = _flowerServiceRepository.SupplyRepository.Get(supplyId.Value); SupplyFlower supplyFlower = supply.SupplyFlowers.FirstOrDefault(item => item.SupplyId == supplyId.Value && item.FlowerId == flowerId.Value); if (supplyFlower != null) { _flowerServiceRepository.SupplyRepository.DeleteSupplyFlower(supplyFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = supplyId })); } } return(RedirectToAction("Index")); }
public IActionResult FlowerDetails(int?supplyId, int?flowerId) { if (supplyId == null || flowerId == null || _flowerServiceRepository.SupplyRepository.Get(supplyId.Value) == null) { return(RedirectToAction("Index")); } SupplyFlower supplyFlower = _flowerServiceRepository.SupplyRepository.GetSupplyFlowers(supplyId.Value).SingleOrDefault(item => item.SupplyId == supplyId && item.FlowerId == flowerId.Value); if (supplyFlower == null) { return(RedirectToAction("Index")); } return(View(supplyFlower)); }
public void Update(SupplyFlower supply) { var updateSupply = unitOfWork.SupplyFlowers.GetByID(supply.Id); if (updateSupply == null) { throw new ArgumentException("Flower not found"); } updateSupply.FlowerAmount = supply.FlowerAmount; updateSupply.FlowerId = supply.FlowerId; updateSupply.SupplyId = supply.SupplyId; unitOfWork.SupplyFlowers.Update(updateSupply); unitOfWork.SaveChanges(); }
public IActionResult FlowerEdit(int?supplyId, int?flowerId) { if (supplyId == null || flowerId == null || _flowerServiceRepository.SupplyRepository.Get(supplyId.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); SupplyFlower supplyFlower = _flowerServiceRepository.SupplyRepository.GetSupplyFlowers(supplyId.Value).SingleOrDefault(item => item.SupplyId == supplyId && item.FlowerId == flowerId.Value); if (supplyFlower == null) { return(RedirectToAction("Index")); } return(View(supplyFlower)); }
public SupplyFlower Create(SupplyFlower supplyFlower) { if (supplyFlower == null) { throw new ArgumentNullException(nameof(supplyFlower)); } var newSupplyFlower = new SupplyFlower() { FlowerAmount = supplyFlower.FlowerAmount, FlowerId = supplyFlower.FlowerId, SupplyId = supplyFlower.SupplyId, }; unitOfWork.SupplyFlowers.Create(newSupplyFlower); unitOfWork.SaveChanges(); return(newSupplyFlower); }
public IActionResult FlowerCreate(SupplyFlower supplyFlower) { if (!ModelState.IsValid) { return(View(supplyFlower)); } Supply supply = _flowerServiceRepository.SupplyRepository.Get(supplyFlower.SupplyId); if (supply.SupplyFlowers.FirstOrDefault(flowers => flowers.SupplyId == supplyFlower.SupplyId && flowers.FlowerId == supplyFlower.FlowerId) != null) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); ModelState["FlowerId"].Errors.Add("Такой цветок уже есть в поставке"); return(View(supplyFlower)); } _flowerServiceRepository.SupplyRepository.CreateSupplyFlower(supplyFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = supplyFlower.SupplyId })); }
public async Task Update(SupplyFlower value) { dbcontext.Entry(value).State = EntityState.Modified; await dbcontext.SaveChangesAsync(); }
public async Task Create(SupplyFlower value) { dbcontext.SupplyFlowers.Add(value); await dbcontext.SaveChangesAsync(); }
public void Remove(SupplyFlower item) { _dataManager.SupplyFlowers.Remove(item); }
public void Update(SupplyFlower item) { _dataManager.SupplyFlowers.Update(item); }
public void Create(SupplyFlower item) { _dataManager.SupplyFlowers.Create(item); }
public static void Initialize(FlowerContext flowerContext) { flowerContext.Database.EnsureCreated(); if (flowerContext.TheFlowers.Any()) { return; // DB has been seeded } var flowers = new TheFlower[] { new TheFlower { Id = 1, Name = "Tulip" }, new TheFlower { Id = 2, Name = "Rose" }, new TheFlower { Id = 3, Name = "Phalenopsis" } }; foreach (TheFlower f in flowers) { flowerContext.TheFlowers.Add(f); } flowerContext.SaveChanges(); var plantations = new Plantation[] { new Plantation { Id = 1, Name = "First", Address = "Philadelphia, 1020" }, new Plantation { Id = 2, Name = "Second", Address = "Pensilvania, 1452" } }; foreach (Plantation p in plantations) { flowerContext.Plantations.Add(p); } flowerContext.SaveChanges(); var plantationFlowers = new PlantationFlower[] { new PlantationFlower { PlantationId = 1, FlowerId = 1, Amount = 50 }, new PlantationFlower { PlantationId = 2, FlowerId = 2, Amount = 100 } }; foreach (PlantationFlower pf in plantationFlowers) { flowerContext.PlantationFlowers.Add(pf); } flowerContext.SaveChanges(); var warehouses = new Warehouse[] { new Warehouse { Id = 1, Name = "First", Address = "Philadelphia, 1020" }, new Warehouse { Id = 2, Name = "Second", Address = "Pensilvania, 1452" } }; foreach (Warehouse w in warehouses) { flowerContext.Warehouses.Add(w); } flowerContext.SaveChanges(); var warehouseFlowers = new WarehouseFlower[] { new WarehouseFlower { WarehouseId = 1, FlowerId = 1, Amount = 50 }, new WarehouseFlower { WarehouseId = 2, FlowerId = 2, Amount = 100 } }; foreach (WarehouseFlower wf in warehouseFlowers) { flowerContext.WarehouseFlowers.Add(wf); } flowerContext.SaveChanges(); var supplies = new Supply[] { new Supply { Id = 1, PlantationId = 1, WarehouseId = 1, SheduledDate = DateTime.Parse("2020-04-10"), ClosedDate = DateTime.Parse("2020-04-05"), Status = Entities.Enum.Status.Closed }, new Supply { Id = 2, PlantationId = 2, WarehouseId = 2, SheduledDate = DateTime.Parse("2020-04-06"), ClosedDate = DateTime.Parse("2020-04-21"), Status = Entities.Enum.Status.Sheduled } }; foreach (Supply s in supplies) { flowerContext.Supplies.Add(s); } flowerContext.SaveChanges(); var supplyFlowers = new SupplyFlower[] { new SupplyFlower { SupplyId = 1, FlowerId = 1, Amount = 75 }, new SupplyFlower { SupplyId = 2, FlowerId = 2, Amount = 85 } }; foreach (SupplyFlower sf in supplyFlowers) { flowerContext.SupplyFlowers.Add(sf); } flowerContext.SaveChanges(); }
public void UpdateSupplyFlower(SupplyFlower supplyFlower) { Context.SupplyFlowers.Update(supplyFlower); }
public void CreateSupplyFlower(SupplyFlower supplyFlower) { Context.Supply.SingleOrDefault(supply => supply.Id == supplyFlower.SupplyId).SupplyFlowers.Add(supplyFlower); }
public void DeleteSupplyFlower(SupplyFlower supplyFlower) { Context.Supply.SingleOrDefault(supply => supply.Id == supplyFlower.SupplyId).SupplyFlowers.Remove(supplyFlower); }