コード例 #1
0
        public async Task <IActionResult> Index()
        {
            Narucivanje narucivanje = nServis.CitajSpisak();

            if (narucivanje.Kartas.Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ApplicationUser user = await um.GetUserAsync(User);

            string     id = user.Id;
            Porudzbina p1 = new Porudzbina
            {
                KorisnikId       = id,
                DatumPorucivanja = DateTime.Now
            };

            try
            {
                db.Porudzbina.Add(p1);
                db.SaveChanges();
                int pId = p1.PorudzbinaId;

                foreach (NarucenaKarta kr in narucivanje.Kartas)
                {
                    Karta kr1 = new Karta
                    {
                        PorudzbinaId = pId,
                        PredstavaId  = kr.Predstava.PredstavaId,
                        Kolicina     = kr.Kolicina
                    };

                    db.Karta.Add(kr1);
                    db.SaveChanges();
                }


                nServis.ObrisiSpisak();

                return(View());
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Ime = model.Ime, Prezime = model.Prezime, Drzava = model.Drzava, Grad = model.Grad, Adresa = model.Adresa
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    Korisnik k = new Korisnik {
                        KorisnikId = user.Id,
                        Ime        = user.Ime,
                        Prezime    = user.Prezime,
                        Drzava     = user.Drzava,
                        Grad       = user.Grad,
                        Adresa     = user.Adresa
                    };

                    db.Korisnik.Add(k);
                    db.SaveChanges();


                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }