public async Task <IActionResult> Edit(int id, [Bind("Id,FlowerId,WarehouseId,Amount")] WarehouseFlower warehouseFlower) { if (id != warehouseFlower.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _unitOfWork.WarehouseFlowers.Update(warehouseFlower); await _unitOfWork.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WarehouseFlowerExists(warehouseFlower.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", warehouseFlower.FlowerId); ViewData["WarehouseId"] = new SelectList(_unitOfWork.Warehouses.GetAll(), "Id", "Id", warehouseFlower.WarehouseId); return(View(warehouseFlower)); }
public async Task Remove(WarehouseFlower value) { if (value != null) { dbcontext.Entry(value).State = EntityState.Deleted; await dbcontext.SaveChangesAsync(); } }
public ActionResult Create(WarehouseFlower warehouseFlower) { if (ModelState.IsValid) { var newWarehouseFlower = warehouseFlowersService.Create(warehouseFlower); return(RedirectToAction("Details", new { id = newWarehouseFlower.Id })); } return(View()); }
public async Task <ActionResult> Create(WarehouseFlower warehouseFlower) { if (ModelState.IsValid) { await dataManager.WarehouseFlowers.Create(warehouseFlower); return(RedirectToAction(nameof(WarehouseFlowersController.Index))); } return(View()); }
public async Task <ActionResult> Edit(WarehouseFlower PlantationFlower) { if (ModelState.IsValid) { await dataManager.WarehouseFlowers.Update(PlantationFlower); return(RedirectToAction(nameof(WarehouseFlowersController.Index))); } return(View(PlantationFlower)); }
public ActionResult Edit(WarehouseFlower warehouseFlower) { if (ModelState.IsValid) { warehouseFlowersService.Update(warehouseFlower); return(RedirectToAction("Details", new { id = warehouseFlower.Id })); } return(View(warehouseFlower)); }
public IActionResult FlowerEdit(WarehouseFlower warehouseFlower) { if (!ModelState.IsValid) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); return(View(warehouseFlower)); } _flowerServiceRepository.WarehouseRepository.UpdateWarehouseFlower(warehouseFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = warehouseFlower.PlaceId })); }
public async Task <IActionResult> Create([Bind("Id,FlowerId,WarehouseId,Amount")] WarehouseFlower warehouseFlower) { if (ModelState.IsValid) { _unitOfWork.WarehouseFlowers.Create(warehouseFlower); await _unitOfWork.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", warehouseFlower.FlowerId); ViewData["WarehouseId"] = new SelectList(_unitOfWork.Warehouses.GetAll(), "Id", "Id", warehouseFlower.WarehouseId); return(View(warehouseFlower)); }
public IActionResult FlowerCreate(int?id) { if (id == null || _flowerServiceRepository.WarehouseRepository.Get(id.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); WarehouseFlower warehouseFlower = new WarehouseFlower { PlaceId = id.Value }; return(View(warehouseFlower)); }
public IActionResult FlowerDelete(int?placeId, int?flowerId) { if (placeId != null || flowerId != null || _flowerServiceRepository.WarehouseRepository.Get(placeId.Value) != null) { Warehouse warehouse = _flowerServiceRepository.WarehouseRepository.Get(placeId.Value); WarehouseFlower warehouseFlower = warehouse.WarehouseFlowers.FirstOrDefault(item => item.PlaceId == placeId.Value && item.FlowerId == flowerId.Value); if (warehouseFlower != null) { _flowerServiceRepository.WarehouseRepository.DeleteWarehouseFlower(warehouseFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = placeId })); } } return(RedirectToAction("Index")); }
public void Update(WarehouseFlower warehouseFlower) { var updateWarehouseFlower = unitOfWork.WarehouseFlowers.GetByID(warehouseFlower.Id); if (updateWarehouseFlower == null) { throw new ArgumentNullException(nameof(warehouseFlower)); } updateWarehouseFlower.FlowerAmount = warehouseFlower.FlowerAmount; updateWarehouseFlower.FlowerId = warehouseFlower.FlowerId; updateWarehouseFlower.WarehouseId = warehouseFlower.WarehouseId; unitOfWork.WarehouseFlowers.Update(updateWarehouseFlower); unitOfWork.SaveChanges(); }
public IActionResult FlowerDetails(int?placeId, int?flowerId) { if (placeId == null || flowerId == null || _flowerServiceRepository.WarehouseRepository.Get(placeId.Value) == null) { return(RedirectToAction("Index")); } WarehouseFlower warehouseFlower = _flowerServiceRepository.WarehouseRepository.GetWarehouseFlowers(placeId.Value).SingleOrDefault(pf => pf.PlaceId == placeId && pf.FlowerId == flowerId.Value); if (warehouseFlower == null) { return(RedirectToAction("Index")); } return(View(warehouseFlower)); }
public IActionResult FlowerEdit(int?placeId, int?flowerId) { if (placeId == null || flowerId == null || _flowerServiceRepository.WarehouseRepository.Get(placeId.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); WarehouseFlower warehouseFlower = _flowerServiceRepository.WarehouseRepository.GetWarehouseFlowers(placeId.Value).SingleOrDefault(pf => pf.PlaceId == placeId && pf.FlowerId == flowerId.Value); if (warehouseFlower == null) { return(RedirectToAction("Index")); } return(View(warehouseFlower)); }
public WarehouseFlower Create(WarehouseFlower warehouseFlower) { if (warehouseFlower == null) { throw new ArgumentNullException(nameof(warehouseFlower)); } var newWarehouseFlower = new WarehouseFlower() { FlowerAmount = warehouseFlower.FlowerAmount, FlowerId = warehouseFlower.FlowerId, WarehouseId = warehouseFlower.WarehouseId, }; unitOfWork.WarehouseFlowers.Create(newWarehouseFlower); unitOfWork.SaveChanges(); return(newWarehouseFlower); }
public IActionResult FlowerCreate(WarehouseFlower warehouseFlower) { if (!ModelState.IsValid) { return(View(warehouseFlower)); } Warehouse warehouse = _flowerServiceRepository.WarehouseRepository.Get(warehouseFlower.PlaceId); if (warehouse.WarehouseFlowers.FirstOrDefault(flowers => flowers.PlaceId == warehouseFlower.PlaceId && flowers.FlowerId == warehouseFlower.FlowerId) != null) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); ModelState["FlowerId"].Errors.Add("Такой цветок уже есть на плантации"); return(View(warehouseFlower)); } _flowerServiceRepository.WarehouseRepository.CreateWarehouseFlower(warehouseFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = warehouseFlower.PlaceId })); }
public async Task Update(WarehouseFlower value) { dbcontext.Entry(value).State = EntityState.Modified; await dbcontext.SaveChangesAsync(); }
public void DeleteWarehouseFlower(WarehouseFlower warehouseFlower) { Context.Warehouses.SingleOrDefault(warehouse => warehouse.Id == warehouseFlower.PlaceId).WarehouseFlowers.Remove(warehouseFlower); }
public async Task Create(WarehouseFlower value) { dbcontext.WarehouseFlowers.Add(value); await dbcontext.SaveChangesAsync(); }
public void UpdateWarehouseFlower(WarehouseFlower warehouseFlower) { Context.WarehouseFlowers.Update(warehouseFlower); }
public void Update(WarehouseFlower item) { _dataManager.WarehouseFlowers.Update(item); }
public void CreateWarehouseFlower(WarehouseFlower warehouseFlower) { Context.Warehouses.SingleOrDefault(warehouse => warehouse.Id == warehouseFlower.PlaceId).WarehouseFlowers.Add(warehouseFlower); }
public void Remove(WarehouseFlower item) { _dataManager.WarehouseFlowers.Remove(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(); }