コード例 #1
0
        public IActionResult Index(NaruzbaViewModel model)
        {
            NaruzbaViewModel returnModel = new NaruzbaViewModel();

            PopulateModel(ref returnModel);

            if (!ModelState.IsValid)
            {
                return(View(returnModel));
            }


            Narudzba narudzba = new Narudzba
            {
                Datum          = DateTime.UtcNow,
                Kanton         = model.Kanton,
                Ulica          = model.Ulica,
                KontaktTelefon = model.KontaktTelefon,
                PostanskiBroj  = model.PostanskiBroj,
                UkupnaCijena   = returnModel.Detalji.TotalPrice,
                Stanje         = 1,
                KupacId        = kupacService.GetKupacByAspUserId(_userManager.GetUserId(HttpContext.User)),
                Opcina         = model.Opcina
            };

            List <StavkaNarudzbe> listaStavki = new List <StavkaNarudzbe>();

            foreach (var item in returnModel.Detalji.Items)
            {
                var stavka = new StavkaNarudzbe
                {
                    MobitelId = item.Product.Id,
                    Kolicina  = item.Quantity,
                    Cijena    = item.Product.mobitel.Cijena
                };
                listaStavki.Add(stavka);
            }


            narudzbaService.InsertNarudzba(narudzba, listaStavki);

            // posalji sms zahvale kupcu
            string poruka = "Hvala vam na naruzbi sa webshopmobitela, " + model.Ime + ".Vasa naruzba ce ubrzo biti dostavljena u ulicu " + model.Ulica + ".";

            smsService.SendSms(new SmsModel {
                To = model.FullPhone, Text = poruka
            });


            // nakon uspjesne narudzbe ukloni sve iz kosarice.
            List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, CartName);

            cart.RemoveAll(x => x.Quantity > 0);
            SessionHelper.SetObjectAsJson(HttpContext.Session, CartName, cart);


            return(RedirectToAction("Narudzbe"));
        }
コード例 #2
0
        public IActionResult Index(NarudzbaViewModel model)
        {
            NarudzbaViewModel returnModel = new NarudzbaViewModel();

            PopulateModel(ref returnModel);

            if (!ModelState.IsValid)
            {
                return(View(returnModel));
            }


            Narudzba narudzba = new Narudzba
            {
                DatumNarudzbe = DateTime.UtcNow,
                Kontakt       = model.KontaktTelefon,
                UkupnaCijena  = returnModel.Detalji.TotalPrice,
                Status        = 1,
                KupacId       = KupacService.GetKupacByAspUserId(UserManager.GetUserId(HttpContext.User))
            };

            List <StavkaNarudzbe> listaStavki = new List <StavkaNarudzbe>();

            foreach (var item in returnModel.Detalji.Items)
            {
                var stavka = new StavkaNarudzbe
                {
                    ArtikalId = item.Product.Id,
                    Kolicina  = item.Quantity,
                    Cijena    = item.Product.artikal.Cijena
                };
                listaStavki.Add(stavka);
            }


            NarudzbaService.InsertNarudzba(narudzba, listaStavki);
            var VONAGE_API_KEY    = Configuration["VONAGE_API_KEY"];
            var VONAGE_API_SECRET = Configuration["VONAGE_API_SECRET"];
            var credentials       = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
            var client            = new SmsClient(credentials);
            var request           = new SendSmsRequest {
                To = model.KontaktTelefon, From = model.KontaktTelefon, Text = "Uspjesno ste narucili artikal!"
            };
            var response = client.SendAnSms(request);

            ViewBag.MessageId = response.Messages[0].MessageId;

            // Delete sve iz kosarice nakon uspjesne narudzbe
            List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, CartName);

            cart.RemoveAll(x => x.Quantity > 0);
            SessionHelper.SetObjectAsJson(HttpContext.Session, CartName, cart);



            return(View("NarudzbaConfirmation"));
        }