Esempio n. 1
0
        public IEnumerable <MaterialImpl> Get()
        {
            var dao = new MaterialDao();

            return(dao.GetAll().Select(item => new MaterialImpl()
            {
                Id = item.Id, Druh = item.Druh, Pn = item.Pn, Popis = item.Popis, SapCislo = item.SapCislo, SapPopis = item.PopisSap
            }).ToList());
        }
        public ActionResult Edit(int id)
        {
            var uvd  = new UkolVzorkovaniDao();
            var item = uvd.GetById(id);

            if (item == null)
            {
                return(RedirectToAction("Index"));
            }
            var matDao       = new MaterialDao();
            var materialList = matDao.GetAll();

            ViewBag.materialList = materialList;
            TempData["UkolVzorkovaniHistory"] = item;
            return(View(item));
        }
Esempio n. 3
0
        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));
        }
        public ActionResult Edit(int id, UkolVzorkovani collection, bool poslatMailResiteli, bool poslatMailZadavateli, string produktyInput)
        {
            var history = TempData["UkolVzorkovaniHistory"] as UkolVzorkovani;

            if (history == null)
            {
                return(RedirectToAction("Index"));
            }

            try
            {
                //POKUD VŠE SEDÍ
                if (ModelState.IsValid)
                {
                    if (produktyInput != history.MaterialyInput)
                    {
                        var ukolMaterialDao = new UkolVzorkovaniMaterialDao();
                        foreach (var item in history.MaterialyInput.Split(';').Where(item => !produktyInput.Contains(";" + item + ";")).Where(item => item != ""))
                        { // Odebrání přebytečných
                            ukolMaterialDao.Delete(history.Materialy.First(x => x.Produkt.Id == Convert.ToInt32(item)));
                        }
                        try
                        {//Přidání nových
                            foreach (var ukolProdukt in produktyInput.Split(';').Where(item => item != "").Select(item => new UkolVzorkovaniMaterial()
                            {
                                Ukol = new UkolVzorkovani()
                                {
                                    Id = collection.Id
                                },
                                Produkt = new MaterialDao().GetById(Convert.ToInt32(item)),
                                DateAdded = DateTime.Now
                            }).Where(lopProdukt => !history.MaterialyInput.Contains(lopProdukt.Produkt.Id.ToString())))
                            {
                                ukolMaterialDao.Create(ukolProdukt);
                            }
                        }
                        catch
                        {
                            TempData[MessagesHelper.Danger] = "Nepodařilo se připojení produktů k úkolu vzorkovaní";
                        }
                    }
                    //TEST SHODNOTI
                    if (collection.IsSame(history)) //vrací FALSE, pokud nastala změna
                    {
                        if (produktyInput != history.MaterialyInput)
                        {
                            TempData[MessagesHelper.Success] = "Provázané materiály byly aktualizovány";
                            return(RedirectToAction("Detail/" + collection.Id));
                        }
                        TempData[MessagesHelper.Info] = "Nebyly provedeny žádné změny";
                        return(RedirectToAction("Detail/" + collection.Id));
                    }

                    //SAVE HISTORY
                    var uvhd = new UkolVzorkovaniHistoryDao();
                    var copy = new UkolVzorkovaniHistory(history);
                    uvhd.Create(copy);


                    if (collection.DateFinish != null)
                    {
                        collection.Status = StatusUkolu.Closed; //byl zadán datum ukončení? nebo tohle přepíná zadavatel??
                    }

                    //SAVE OBJECT
                    collection.DateLastChanged = DateTime.Now;
                    var uvd = new UkolVzorkovaniDao();
                    uvd.Update(collection);

                    //NOTIFIKACE
                    string s = "Byl upraven úkol <a href='/UkolVzorkovani/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>";
                    if (poslatMailResiteli)
                    {
                        Notifikace.Create(collection.Resitel.Id, s);
                    }
                    if (poslatMailZadavateli)
                    {
                        Notifikace.Create(collection.Zadavatel.Id, s);
                    }


                    //DONE
                    TempData[MessagesHelper.Success] = "Změny byly úspěšně uloženy";
                    return(RedirectToAction("Detail/" + collection.Id));
                }
            }
            catch
            {
                TempData[MessagesHelper.Danger] = "Došlo k neočekávané chybě";
            }

            //NON VALID - RE EDIT IT
            TempData["UkolVzorkovaniHistory"] = history;
            TempData[MessagesHelper.Warning]  = "Zkontrolujte zadané údaje";

            var matDao       = new MaterialDao();
            var materialList = matDao.GetAll();

            ViewBag.materialList = materialList;
            collection.Materialy = history.Materialy;
            return(View(collection));
        }