private void UpdateAssignedBoxesForKrzewLisciasty(string[] selectedBoxes, KrzewLisciasty lisciastyToUpdate) { if (selectedBoxes == null) { lisciastyToUpdate.Boxes = new List <Box>(); return; } var selectedBoxesHS = new HashSet <string>(selectedBoxes); var krzewLisciastyBoxes = new HashSet <int>(lisciastyToUpdate.Boxes.Select(b => b.BoxID)); foreach (var box in context.Boxes) { if (selectedBoxesHS.Contains(box.BoxID.ToString())) { if (!krzewLisciastyBoxes.Contains(box.BoxID)) { lisciastyToUpdate.Boxes.Add(box); } } else { if (krzewLisciastyBoxes.Contains(box.BoxID)) { lisciastyToUpdate.Boxes.Remove(box); } } } }
public ActionResult EditKrzewLisciasty(int productID) { KrzewLisciasty krzewLisciasty = krzewLisciasityRepository.KrzewyLisciaste.FirstOrDefault(d => d.ProductID == productID); //krzewLisciasty.Date = DateTime.Now; PopulateAssignedBoxesForKrzewLisciasty(krzewLisciasty); return(View(krzewLisciasty)); }
public ActionResult DeleteKrzewLisciasty(int productID) { KrzewLisciasty deletedKrzewLisciasty = krzewLisciasityRepository.DeleteKrzewLisciasty(productID); if (deletedKrzewLisciasty != null) { TempData["message"] = string.Format("Usunieto {0}", deletedKrzewLisciasty.Name); } return(RedirectToAction("KrzewLisciastyList")); }
public ActionResult CreateKrzewLisciasty() { var krzewLisciasty = new KrzewLisciasty(); krzewLisciasty.Boxes = new List <Box>(); krzewLisciasty.Date = DateTime.Now; krzewLisciasty.Available = true; PopulateAssignedBoxesForKrzewLisciasty(krzewLisciasty); return(View("EditKrzewLisciasty", krzewLisciasty)); }
public KrzewLisciasty DeleteKrzewLisciasty(int krzewLisciastyID) { KrzewLisciasty dbEntry = context.KrzewyLisciaste.Find(krzewLisciastyID); if (dbEntry != null) { context.KrzewyLisciaste.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public FileContentResult GetImage(int productID) { KrzewLisciasty krzewLisciasty = repository.KrzewyLisciaste.FirstOrDefault(p => p.ProductID == productID); if (krzewLisciasty != null) { return(File(krzewLisciasty.ImageData, krzewLisciasty.ImageMimeType)); } else { return(null); } }
public ActionResult Details(int?productID) { if (productID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } KrzewLisciasty krzewLisciasty = repository.KrzewyLisciaste.FirstOrDefault(k => k.ProductID == productID); if (krzewLisciasty == null) { return(HttpNotFound()); } return(View(krzewLisciasty)); }
public void SaveKrzewLisciasty(string[] selectedbox, KrzewLisciasty krzewLisciasty) { if (krzewLisciasty.ProductID == 0) { if (selectedbox != null) { krzewLisciasty.Boxes = new List <Box>(); foreach (var box in selectedbox) { var boxnumber = int.Parse(box); var boxToAdd = context.Boxes.Where(b => b.BoxID == boxnumber).FirstOrDefault(); krzewLisciasty.Boxes.Add(boxToAdd); } } context.KrzewyLisciaste.Add(krzewLisciasty); } else { KrzewLisciasty dbEntry = context.KrzewyLisciaste.Include(b => b.Boxes).Where(k => k.ProductID == krzewLisciasty.ProductID).FirstOrDefault(); if (dbEntry != null) { UpdateAssignedBoxesForKrzewLisciasty(selectedbox, dbEntry); //Product dbEntry.Name = krzewLisciasty.Name; dbEntry.Date = krzewLisciasty.Date; dbEntry.Description = krzewLisciasty.Description; dbEntry.Price = krzewLisciasty.Price; dbEntry.Discount = krzewLisciasty.Discount; dbEntry.Description = krzewLisciasty.Description; dbEntry.Available = krzewLisciasty.Available; if (dbEntry.Available == true) { dbEntry.Quantity = krzewLisciasty.Quantity; } else { dbEntry.Quantity = null; } dbEntry.HeightMin = krzewLisciasty.HeightMin; dbEntry.HeightMax = krzewLisciasty.HeightMax; dbEntry.ImageData = krzewLisciasty.ImageData; dbEntry.ImageMimeType = krzewLisciasty.ImageMimeType; //IglakiGrunt } } context.SaveChanges(); }
private void PopulateAssignedBoxesForKrzewLisciasty(KrzewLisciasty krzewLisciasty) { var allBoxes = boxesRepository.Boxes; var KrzewLisciastyBoxes = new HashSet <int>(krzewLisciasty.Boxes.Select(i => i.BoxID)); var viewModel = new List <AssignedBoxes>(); foreach (var box in allBoxes) { viewModel.Add(new AssignedBoxes { BoxID = box.BoxID, Title = box.Name, Assigned = KrzewLisciastyBoxes.Contains(box.BoxID) }); } ViewBag.Boxes = viewModel; }
public ActionResult EditKrzewLisciasty(string[] selectedBoxes, KrzewLisciasty krzewLisciasty, HttpPostedFileBase image = null) { if (ModelState.IsValid) { if (image != null) { krzewLisciasty.ImageMimeType = image.ContentType; krzewLisciasty.ImageData = new byte[image.ContentLength]; image.InputStream.Read(krzewLisciasty.ImageData, 0, image.ContentLength); } krzewLisciasityRepository.SaveKrzewLisciasty(selectedBoxes, krzewLisciasty); TempData["message"] = string.Format("Zapisano {0} ", krzewLisciasty.Name); return(RedirectToAction("KrzewLisciastyList")); } else { return(View(krzewLisciasty)); } }