예제 #1
0
        public ActionResult Create(Lop collection, bool poslatMail, string produktyInput)
        {
            ViewBag.FirstCreate = false;
            try
            {
                if (ModelState.IsValid)
                {
                    LopDao lopDao = new LopDao();

                    collection.StartDate       = DateTime.Now;
                    collection.LastChangedDate = DateTime.Now;
                    collection.Status          = StatusUkolu.Open; //když vytváříme - úkol je standartně otevřený
                    var latest = lopDao.GetLatestLopThisYear();
                    collection.Action = latest?.Action + 1 ?? 1;
                    collection.Id     = (int)lopDao.Create(collection);
                    TempData[MessagesHelper.Success] = Resources.LopTexts.UkolPridany;

                    if (produktyInput != "")
                    {
                        try
                        {
                            var ukolMaterialDao = new LopMaterialDao();
                            foreach (var ukolProdukt in produktyInput.Split(';').Where(item => item != "").Select(item => new LopMaterial()
                            {
                                Lop = collection,
                                Produkt = new MaterialDao().GetById(Convert.ToInt32(item)),
                                DateAdded = DateTime.Now
                            }))
                            {
                                ukolMaterialDao.Create(ukolProdukt);
                            }
                        }
                        catch
                        {
                            TempData[MessagesHelper.Danger] = Resources.LopTexts.NepodariloSePripojeniProduktuKUkolu;
                        }
                    }
                    new LopMaterialDao().ClearWrongHistoryAfterCreate(); //po vytvoření je nadbytečná historie lopu

                    //posíláme vždy
                    //if (!poslatMail) return RedirectToAction("Detail", new {id = collection.Id});
                    var s = Resources.LopTexts.BylVamPridelenNovyUkol +
                            " <a href='/Lop/Detail/" + collection.Id + "'>" + collection.Nazev + "</a>";
                    Notifikace.Create(collection.Resitel.Id, s);

                    return(RedirectToAction("Detail", new { id = collection.Id }));
                }
                TempData[MessagesHelper.Warning] = Resources.LopTexts.ZkontrolujteZadaneUdaje;
            }
            catch
            {
                TempData[MessagesHelper.Danger] = Resources.LopTexts.DosloKNeocekavaneChybe;
            }
            return(View(collection));
        }
예제 #2
0
        public ActionResult Test()
        {
            var lopDao = new LopDao();
            var rnd    = new Random();

            for (int i = lopDao.GetLatestLopThisYear().Action; i < 10000; i++)
            {
                lopDao.Create(new Lop()
                {
                    Action           = i,
                    Nazev            = "Lop " + i,
                    Zadavatel        = new UzivatelDao().GetById(rnd.Next(1, 8)),
                    Resitel          = new UzivatelDao().GetById(rnd.Next(1, 8)),
                    Status           = StatusUkolu.Open,
                    StartDate        = DateTime.Now,
                    LastChangedDate  = DateTime.Now,
                    PlannedCloseDate = DateTime.Now.AddDays(40),
                    Popis            = "blsadklasmdaskldmalsdm"
                });
            }
            TempData[MessagesHelper.Success] = "Záznamy lopu vygenerovány";

            return(RedirectToAction("Index"));
        }