コード例 #1
0
        public ActionResult DenyLop(int id, string deniedMessage)
        {
            try
            {
                if (String.IsNullOrEmpty(deniedMessage.Trim()))
                {
                    deniedMessage = "Odmítnuto (bez udání důvodu)"; //natvrdo popisek
                }

                LopDao lopDao = new LopDao();
                Lop    lop    = lopDao.GetById(id);

                /*
                 * //uložení historie
                 * var histDao = new LopHistoryDao();
                 * var copy = new LopHistory(lop);
                 * histDao.Create(copy);
                 */

                lop.LastChangedDate = DateTime.Now; //něco se děje
                lop.DeniedMessage   = deniedMessage;

                //update objektu
                lopDao.Update(lop);

                LopWorkFlowEvent.Create(lop,
                                        LopWorkFlowEvent.Colors.Danger,
                                        LopWorkFlowEvent.Icons.User,
                                        "Odmítnutí odpovědnosti",
                                        "Řešitel odmítl řešit tento úkol. <q>" + deniedMessage + "</q>",
                                        User.Identity.Name
                                        );

                var s = lop.Resitel + " " + Resources.LopTexts.OdmitlResitUkol + " " +
                        "<a href='/Lop/Detail/" + lop.Id + "'>" + lop.Nazev +
                        "</a><br />" + lop.DeniedMessage;
                Notifikace.Create(lop.Zadavatel.Id, s);

                TempData[MessagesHelper.Success] = Resources.LopTexts.UkolBylOdmitnut;

                return(RedirectToAction("Index"));
            }
            catch
            {
                TempData[MessagesHelper.Warning] = Resources.LopTexts.NepodariloSeOdmitnoutUkol;
            }

            return(RedirectToAction("Detail/" + id));
        }
コード例 #2
0
        public ActionResult Delete(int id)
        {
            var lopDao = new LopDao();
            var lop    = lopDao.GetById(id);

            try
            {
                lop.Deleted = true;
                lopDao.Update(lop);
            }
            catch (Exception)
            {
                TempData[MessagesHelper.Danger] = Resources.LopTexts.DosloKNeocekavaneChybe;
                return(RedirectToAction("Detail", new { id = lop.Id }));
            }
            TempData[MessagesHelper.Success] = Resources.LopTexts.UkolSmazan;
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public ActionResult Edit(Lop lop)
        {
            if (ModelState.IsValid)
            {
                var dao = new LopDao();

                var result = dao.Update(lop);

                if (result)
                {
                    SetAlert("Chỉnh sửa lớp thành công", "success");
                    return(RedirectToAction("Index", "Lop"));
                }
                else
                {
                    ModelState.AddModelError("", "cập nhật không thành công");
                }
                SetViewBag(lop.DonViID);
            }
            return(View("Index"));
        }
コード例 #4
0
        public ActionResult FinishUkol(int id, bool finished, string komentar)
        {
            try
            {
                LopDao lopD = new LopDao();
                Lop    lop  = lopD.GetById(id);

                lop.LastChangedDate = DateTime.Now; //něco se děje

                if (finished)
                {
                    //KONTROLA JESTLI LZE UKONČIT ÚKOL, DOKUD NEJSOU UKONČENY PODÚKOLY
                    //teoreticky můžeme přesměrovat na hlášku, jestli chce zadavatel označit všechny podúkoly
                    //jako vyřešené?
                    //btw .. tlačítko na tuhle akci ukážu jen pokud jsou všechny done ;)
                    int celkemUkolu   = lop.PocetSubUkoluCelkem();
                    int ukoluHotovych = lop.PocetSubUkoluCompleted();

                    if (celkemUkolu != ukoluHotovych)
                    {
                        TempData[MessagesHelper.Info] = Resources.LopTexts.NelzeUkoncitUkol1 + " (" + (celkemUkolu - ukoluHotovych) + ") " + Resources.LopTexts.NelzeUkoncitUkol2;
                        return(RedirectToAction("Index"));
                    }
                    Uzivatel u           = new UzivatelDao().GetByWindowsId(User.Identity.Name.ToUpper());
                    bool     isZadavatel = u.Id == lop.Zadavatel.Id;
                    bool     isZadavatelATeprveUzavira = false;
                    if (isZadavatel && lop.Status == StatusUkolu.Open) //v případě že je uživatel zároveň Zadavatel a Řešitel
                    {
                        isZadavatelATeprveUzavira = true;
                    }

                    if (isZadavatel && lop.Status == StatusUkolu.Closed)
                    {
                        lop.CheckDate  = DateTime.Now; //proběhla kontrola (ať už jakákoliv)
                        lop.FinishDate = DateTime.Now; //v pořádku

                        #region workflow-event
                        LopWorkFlowEvent.Create(lop,
                                                LopWorkFlowEvent.Colors.Success,
                                                LopWorkFlowEvent.Icons.Ok,
                                                "Úkol uzavřen",
                                                "Zadavatel přijal řešení úkolu a úkol uzavřel jako splněný. <q>" + komentar + "</q>",
                                                User.Identity.Name
                                                );
                        #endregion
                    }
                    else
                    {
                        #region workflow-event
                        LopWorkFlowEvent.Create(lop,
                                                LopWorkFlowEvent.Colors.Info,
                                                LopWorkFlowEvent.Icons.User,
                                                "Úkol dokončen",
                                                "Řešitel označil úkol jako splněný - čeká na schválení zadavatelem. <q>" + komentar + "</q>",
                                                User.Identity.Name
                                                );
                        #endregion
                        lop.CloseDate = DateTime.Now;
                    }

                    lop.Status = StatusUkolu.Closed; //řešitel pouze uzavírá na close
                    if (!string.IsNullOrEmpty(komentar))
                    {
                        var koment = komentar + "<br />";
                        koment      += $"<span class=\"glyphicon glyphicon-time\"></span><i>{DateTime.Now} - by {new Uzivatel(User.Identity.Name)}</i>";
                        lop.Komentar = (!string.IsNullOrEmpty(lop.Komentar) ? lop.Komentar + "<hr />" + koment : koment);
                    }
                    //update objektu
                    lopD.Update(lop);
                    if (isZadavatel && !isZadavatelATeprveUzavira) //tuto hlášku nechceme generovat, pokud je to sice zadavatel ale zároveň řešitel a teprve uzavírá úkol poprvé ;)
                    {
                        string s = Resources.LopTexts.ByloPrijatoReseniLopu +
                                   " <a href='/Lop/Detail/" + lop.Id + "?showHistory=true#historyBtn'>" + lop.Nazev +
                                   "</a>";
                        Notifikace.Create(lop.Resitel.Id, s);
                    }
                    else
                    {
                        string s = Resources.LopTexts.UkolBylOznacenJakoVyreseny +
                                   " <a href='/Lop/Detail/" + lop.Id + "'>" + lop.Nazev + "</a>";
                        Notifikace.Create(lop.Zadavatel.Id, s);
                    }
                    TempData[MessagesHelper.Success] = Resources.LopTexts.UkolBylVyresen;
                }
                else
                {
                    //pokud chceme označit jako nevyřešený
                    lop.CheckDate  = DateTime.Now;     //proběhla kontrola (ať už jakákoliv)
                    lop.CloseDate  = null;
                    lop.FinishDate = null;             //nepřijato
                    lop.Status     = StatusUkolu.Open; //úkol musí být dále zpracováván
                    if (!string.IsNullOrEmpty(komentar))
                    {
                        var koment = komentar + "<br />";
                        koment      += $"<span class=\"glyphicon glyphicon-time\"></span><i>{DateTime.Now} - by {new Uzivatel(User.Identity.Name)}</i>";
                        lop.Komentar = (!string.IsNullOrEmpty(lop.Komentar) ? lop.Komentar + "<hr />" + koment : koment);
                    }
                    lopD.Update(lop);
                    #region workflow-event
                    LopWorkFlowEvent.Create(lop,
                                            LopWorkFlowEvent.Colors.Danger,
                                            LopWorkFlowEvent.Icons.Remove,
                                            "Řešení zamítnuto",
                                            "Zadavatel odmítl odevzdané řešení úkolu. <q>" + komentar + "</q>",
                                            User.Identity.Name
                                            );
                    #endregion
                    string s = Resources.LopTexts.ByloOdmitnutoReseniUkolu +
                               " <a href='/Lop/Detail/" + lop.Id + "?showHistory=true#historyBtn'>" + lop.Nazev + "</a>";
                    Notifikace.Create(lop.Resitel.Id, s);
                    TempData[MessagesHelper.Warning] = Resources.LopTexts.UkolJeZnovuVReseni;
                }
            }
            catch (Exception e)
            {
                TempData[MessagesHelper.Warning] = Resources.LopTexts.NepodariloSeUpravitZaznam;
            }

            return(RedirectToAction("Detail/" + id));
        }
コード例 #5
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));
        }