Beispiel #1
0
        public ActionResult vyprazdnit()
        {
            if (User.Identity.Name != "")
            {
                PolozkaKosikDao polozkaKosikDao = new PolozkaKosikDao();



                polozkaKosikDao.vyprazdnit(new UcetDao().GetByLogin(User.Identity.Name).Id);
            }
            else
            {
                if (Request.Cookies["kosik"] == null)
                {
                }

                else
                {
                    var myCookie = new HttpCookie("kosik");
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie);
                }
            }


            return(RedirectToAction("Kosik"));
        }
Beispiel #2
0
        public ActionResult dokonceniObjednavky(Objednavka model)
        {
            PolozkaObjednavkaDao PolozkaObjednavkaDao = new PolozkaObjednavkaDao();
            ObjednavkaDao        objednavkaDao        = new ObjednavkaDao();
            AdresaDao            adresaDao            = new AdresaDao();


            Kosik kosik = new Kosik();



            if (User.Identity.Name != "")
            {
                Ucet ucet = new UcetDao().GetByLogin(User.Identity.Name);
                IList <PolozkaKosik> polozky = new PolozkaKosikDao().GetByUzivatel(ucet.Id);
                kosik = new Kosik(polozky);
            }
            else
            {
                if (Request.Cookies["kosik"] != null)
                {
                    string               objCartListString      = Request.Cookies["kosik"].Value.ToString();
                    string[]             objCartListStringSplit = objCartListString.Split('|');
                    IList <PolozkaKosik> polozky = new List <PolozkaKosik>();


                    foreach (string s in objCartListStringSplit)
                    {
                        PolozkaKosik polozka = new PolozkaKosik();
                        string[]     ss      = s.Split(',');
                        polozka.Hra      = new GameDao().GetById(Convert.ToInt32(ss[0]));
                        polozka.Mnozstvi = Convert.ToInt32(ss[1]);

                        polozky.Add(polozka);
                    }
                    kosik = new Kosik(polozky);
                }
            }



            model.Polozky = new List <PolozkaObjednavka>();
            foreach (PolozkaKosik item in kosik.Polozky)
            {
                PolozkaObjednavka x = new PolozkaObjednavka();
                x.Hra          = item.Hra;
                x.Aktivovano   = true;
                x.Mnozstvi     = item.Mnozstvi;
                x.Stav         = new Stav();
                x.Stav.Id      = 8;
                x.TehdejsiCena = item.Hra.aktualniCenasDPH();
                model.Polozky.Add(x);
            }
            if (User.Identity.Name != "")
            {
                Ucet ucet = new UcetDao().GetByLogin(User.Identity.Name);
                model.IdUser = ucet.Id;
            }
            model.DatumObjednavky = DateTime.Now;
            model.Stav.Id         = 1;
            adresaDao.Create(model.Adresa);
            objednavkaDao.Create(model);
            foreach (PolozkaObjednavka item in model.Polozky)
            {
                item.ObjednavkaID = model.Id;
                PolozkaObjednavkaDao.Create(item);
            }


            if (User.Identity.Name != "")
            {
                PolozkaKosikDao polozkaKosikDao = new PolozkaKosikDao();



                polozkaKosikDao.vyprazdnit(new UcetDao().GetByLogin(User.Identity.Name).Id);
            }
            else
            {
                if (Request.Cookies["kosik"] == null)
                {
                }

                else
                {
                    var myCookie = new HttpCookie("kosik");
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie);
                }
            }

            model = objednavkaDao.GetById(model.Id);
            if (model.Cislo == null)
            {
                model.Cislo = DateTime.Now.Day + " " + DateTime.Now.Month + DateTime.Now.Year + "/" + model.Id;
            }

            TNPW.utility.Utilityzer.SendingMail();
            TempData["error"] = "Objednávka byla vytvořena č." + model.Cislo + ". Na Váš email byl poslán email";
            return(View("Zprava"));
        }