public void DeletePlFl(int id) { PlantationFlower plantationFlower = DbContext.PlantationFlowers.Find(id); DbContext.Entry(plantationFlower).State = System.Data.Entity.EntityState.Deleted; DbContext.SaveChanges(); }
public async Task <IActionResult> Edit(int id, [Bind("Id,PlantationId,FlowerId,Amount")] PlantationFlower plantationFlower) { if (id != plantationFlower.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _unitOfWork.PlantationFlowers.Update(plantationFlower); await _unitOfWork.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlantationFlowerExists(plantationFlower.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", plantationFlower.FlowerId); ViewData["PlantationId"] = new SelectList(_unitOfWork.Plantations.GetAll(), "Id", "Id", plantationFlower.PlantationId); return(View(plantationFlower)); }
public ActionResult DeleteConfirmed(int id) { PlantationFlower plantationFlower = db.PlantationFlowers.Find(id); db.PlantationFlowers.Remove(plantationFlower); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(PlantationFlower plantationFlower) { if (ModelState.IsValid) { var newPlantationFlower = plantationFlowersService.Create(plantationFlower); return(RedirectToAction("Details", new { id = newPlantationFlower.Id })); } return(View()); }
public ActionResult AddFlowers([Bind(Include = "Id,PlantationId,FlowerId,Amount")] PlantationFlower plantationflower) { if (ModelState.IsValid) { plantationRepository.CreatePlFl(plantationflower); return(RedirectToAction("Index")); } return(View(plantationflower)); }
public ActionResult EditPlantationFlowers([Bind(Include = "Id,PlantationId,Amount,FlowerId")] PlantationFlower plantationFlower) { if (ModelState.IsValid) { plantationRepository.UpdatePlFl(plantationFlower); return(RedirectToAction("Index")); } ViewBag.FlowerId = new SelectList(flowerRepository.GetFlowers(), "Id", "Name", plantationFlower.FlowerId); ViewBag.PlantationId = new SelectList(plantationRepository.GetPlantations(), "Id", "Name", plantationFlower.PlantationId); return(View(plantationFlower)); }
public ActionResult Edit(PlantationFlower plantationFlower) { if (ModelState.IsValid) { plantationFlowersService.Update(plantationFlower); return(RedirectToAction("Details", new { id = plantationFlower.Id })); } return(View(plantationFlower)); }
public async Task <ActionResult> Edit(PlantationFlower PlantationFlower) { if (ModelState.IsValid) { await dataManager.PlantationFlowers.Update(PlantationFlower); return(RedirectToAction(nameof(PlantationFlowersController.Index))); } return(View(PlantationFlower)); }
public ActionResult DeletePlFl(int id) { PlantationFlower plantationFlower = plantationRepository.GetPlFl(id); if (plantationFlower == null) { return(HttpNotFound()); } plantationRepository.DeletePlFl(id); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,PlantationId,Amount,FlowerId")] PlantationFlower plantationFlower) { if (ModelState.IsValid) { db.Entry(plantationFlower).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FlowerId = new SelectList(db.Flowers, "Id", "Name", plantationFlower.FlowerId); ViewBag.PlantationId = new SelectList(db.Plantations, "Id", "Name", plantationFlower.PlantationId); return(View(plantationFlower)); }
public async Task <IActionResult> Create([Bind("Id,PlantationId,FlowerId,Amount")] PlantationFlower plantationFlower) { if (ModelState.IsValid) { _unitOfWork.PlantationFlowers.Create(plantationFlower); await _unitOfWork.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FlowerId"] = new SelectList(_unitOfWork.Flowers.GetAll(), "Id", "Name", plantationFlower.FlowerId); ViewData["PlantationId"] = new SelectList(_unitOfWork.Plantations.GetAll(), "Id", "Id", plantationFlower.PlantationId); return(View(plantationFlower)); }
public IActionResult FlowerEdit(PlantationFlower plantationFlower) { if (!ModelState.IsValid) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); return(View(plantationFlower)); } _flowerServiceRepository.PlantationRepository.UpdatePlantationFlower(plantationFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = plantationFlower.PlaceId })); }
// GET: Test/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantationFlower plantationFlower = db.PlantationFlowers.Find(id); if (plantationFlower == null) { return(HttpNotFound()); } return(View(plantationFlower)); }
public IActionResult FlowerCreate(int?id) { if (id == null || _flowerServiceRepository.PlantationRepository.Get(id.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); PlantationFlower plantationFlower = new PlantationFlower { PlaceId = id.Value }; return(View(plantationFlower)); }
// GET: Plantation/Edit/5 public ActionResult EditPlantationFlowers(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantationFlower plantationFlower = plantationRepository.GetPlFl(id.Value); if (plantationFlower == null) { return(HttpNotFound()); } ViewBag.FlowerId = new SelectList(flowerRepository.GetFlowers(), "Id", "Name", plantationFlower.FlowerId); ViewBag.PlantationId = new SelectList(plantationRepository.GetPlantations(), "Id", "Name", plantationFlower.PlantationId); return(View(plantationFlower)); }
public void Update(PlantationFlower plantationFlower) { var updatePlantationFlower = unitOfWork.PlantationFlowers.GetByID(plantationFlower.Id); if (updatePlantationFlower == null) { throw new ArgumentNullException(nameof(plantationFlower)); } updatePlantationFlower.FlowerAmount = plantationFlower.FlowerAmount; updatePlantationFlower.FlowerId = plantationFlower.FlowerId; updatePlantationFlower.PlantationId = plantationFlower.PlantationId; unitOfWork.PlantationFlowers.Update(updatePlantationFlower); unitOfWork.SaveChanges(); }
public IActionResult FlowerDetails(int?placeId, int?flowerId) { if (placeId == null || flowerId == null || _flowerServiceRepository.PlantationRepository.Get(placeId.Value) == null) { return(RedirectToAction("Index")); } PlantationFlower plantationFlower = _flowerServiceRepository.PlantationRepository.GetPlantationFlowers(placeId.Value).SingleOrDefault(pf => pf.PlaceId == placeId && pf.FlowerId == flowerId.Value); if (plantationFlower == null) { return(RedirectToAction("Index")); } return(View(plantationFlower)); }
// GET: Test/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantationFlower plantationFlower = db.PlantationFlowers.Find(id); if (plantationFlower == null) { return(HttpNotFound()); } ViewBag.FlowerId = new SelectList(db.Flowers, "Id", "Name", plantationFlower.FlowerId); ViewBag.PlantationId = new SelectList(db.Plantations, "Id", "Name", plantationFlower.PlantationId); return(View(plantationFlower)); }
public IActionResult FlowerEdit(int?placeId, int?flowerId) { if (placeId == null || flowerId == null || _flowerServiceRepository.PlantationRepository.Get(placeId.Value) == null) { return(RedirectToAction("Index")); } ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); PlantationFlower plantationFlower = _flowerServiceRepository.PlantationRepository.GetPlantationFlowers(placeId.Value).SingleOrDefault(pf => pf.PlaceId == placeId && pf.FlowerId == flowerId.Value); if (plantationFlower == null) { return(RedirectToAction("Index")); } return(View(plantationFlower)); }
public PlantationFlower Create(PlantationFlower plantationFlower) { if (plantationFlower == null) { throw new ArgumentNullException(nameof(plantationFlower)); } var newPlantationFlower = new PlantationFlower() { FlowerAmount = plantationFlower.FlowerAmount, FlowerId = plantationFlower.FlowerId, PlantationId = plantationFlower.PlantationId, }; unitOfWork.PlantationFlowers.Create(newPlantationFlower); unitOfWork.SaveChanges(); return(newPlantationFlower); }
public IActionResult FlowerCreate(PlantationFlower plantationFlower) { if (!ModelState.IsValid) { return(View(plantationFlower)); } Plantation plantation = _flowerServiceRepository.PlantationRepository.Get(plantationFlower.PlaceId); if (plantation.PlantationFlowers.FirstOrDefault(flowers => flowers.PlaceId == plantationFlower.PlaceId && flowers.FlowerId == plantationFlower.FlowerId) != null) { ViewBag.Flowers = new SelectList(_flowerServiceRepository.FlowerRepository.All(), "Id", "Name"); ModelState["FlowerId"].Errors.Add("Такой цветок уже есть на плантации"); return(View(plantationFlower)); } _flowerServiceRepository.PlantationRepository.CreatePlantationFlower(plantationFlower); _flowerServiceRepository.SaveChanges(); return(RedirectToAction("Edit", new { id = plantationFlower.PlaceId })); }
public void UpdatePlantationFlower(PlantationFlower plantationFlower) { Context.PlantationFlowers.Update(plantationFlower); }
public void DeletePlantationFlower(PlantationFlower plantationFlower) { Context.Plantations.SingleOrDefault(plantation => plantation.Id == plantationFlower.PlaceId).PlantationFlowers.Remove(plantationFlower); }
public void CreatePlantationFlower(PlantationFlower plantationFlower) { Context.Plantations.SingleOrDefault(plantation => plantation.Id == plantationFlower.PlaceId).PlantationFlowers.Add(plantationFlower); }
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 UpdatePlFl(PlantationFlower idplantationFlower) { DbContext.Entry(idplantationFlower).State = System.Data.Entity.EntityState.Modified; DbContext.SaveChanges(); }
public void CreatePlFl(PlantationFlower plantationFlower) { DbContext.PlantationFlowers.Add(plantationFlower); DbContext.SaveChanges(); }