public ActionResult DetailHistory(int id) { var lopHist = new LopHistoryDao().GetById(id); //natáhneme historii a pošleme i s jejím lopem return(View(new LopHistoryVsLop(lopHist, new LopDao().GetById(lopHist.Lop.Id)))); }
public ActionResult Edit(int id, Lop collection, bool poslatMailResiteli, bool poslatMailZadavateli, string produktyInput) { var history = TempData["LopHistory"] as Lop; if (history == null) { return(RedirectToAction("Index")); } try { collection.Zadavatel = new UzivatelDao().GetByWindowsId(User.Identity.Name); if (ModelState.IsValid) { if (produktyInput != history.MaterialyInput) { var lopMaterialDao = new LopMaterialDao(); foreach (var item in history.MaterialyInput.Split(';').Where(item => !produktyInput.Contains(";" + item + ";")).Where(item => item != "")) { // Odebrání přebytečných lopMaterialDao.Delete(history.Materialy.First(x => x.Produkt.Id == Convert.ToInt32(item))); } try {//Přidání nových foreach (var lopProdukt in produktyInput.Split(';').Where(item => item != "").Select(item => new LopMaterial() { Lop = new Lop() { Id = collection.Id }, Produkt = new MaterialDao().GetById(Convert.ToInt32(item)), DateAdded = DateTime.Now }).Where(lopProdukt => !history.MaterialyInput.Contains(lopProdukt.Produkt.Id.ToString()))) { lopMaterialDao.Create(lopProdukt); } } catch { TempData[MessagesHelper.Danger] = Resources.LopTexts.NepodariloSePripojeniProduktuKUkolu; } } //TEST SHODNOTI /* * if (collection.IsSame(history)) //vrací FALSE, pokud nastala změna * { * if (produktyInput != history.MaterialyInput) * { * TempData[MessagesHelper.Success] = Resources.LopTexts.ProvazaneMaterialyBylyAktualizovany; * return RedirectToAction("Detail/" + collection.Id); * } * TempData[MessagesHelper.Info] = Resources.LopTexts.NebylyProvedenyZadneZmeny; * return RedirectToAction("Detail/" + collection.Id); * } */ //KONTROLA JESTLI LZE ÚKOL UZAVŘÍT if (collection.Status == StatusUkolu.Closed) { int celkemUkolu = history.PocetSubUkoluCelkem(); int ukoluHotovych = history.PocetSubUkoluCompleted(); if (celkemUkolu != ukoluHotovych) { TempData[MessagesHelper.Info] = Resources.LopTexts.NelzeUkoncitUkol1 + " (" + (celkemUkolu - ukoluHotovych) + ") " + Resources.LopTexts.NelzeUkoncitUkol2; } } else { //ZMĚNA? - ULOŽÍME DO HISTORIE A PŘEPÍŠEME var lopDao = new LopDao(); var lopHistDao = new LopHistoryDao(); /* * //uložení historie * var copy = new LopHistory(history); * lopHistDao.Create(copy); */ //update objektu collection.LastChangedDate = DateTime.Now; lopDao.Update(collection); TempData[MessagesHelper.Success] = Resources.LopTexts.LopUspesneAktualizovan; if (poslatMailResiteli) { var s = Resources.LopTexts.BylUpravenLop + " <a href='/Lop/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>"; Notifikace.Create(collection.Resitel.Id, s); } if (poslatMailZadavateli) { var s = Resources.LopTexts.BylUpravenLop + " <a href='/Lop/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>"; Notifikace.Create(collection.Zadavatel.Id, s); } return(Redirect(Url.RouteUrl(new { controller = "Lop", action = "Detail", id = collection.Id, showHistory = true }))); } //return RedirectToAction("Detail", new {id = collection.Id, showHistory = true}); } TempData[MessagesHelper.Warning] = Resources.LopTexts.ZkontrolujteZadaneUdaje; } catch (Exception) { TempData[MessagesHelper.Danger] = Resources.LopTexts.DosloKNeocekavaneChybe; } TempData["LopHistory"] = history; var matDao = new MaterialDao(); var materialList = matDao.GetAll(); ViewBag.materialList = materialList; collection.SubUkoly = history.SubUkoly; collection.Materialy = history.Materialy; return(View(collection)); }