// GET: Sopstveniks/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sopstvenik sopstvenik = db.Sopstvenici.Find(id);

            if (sopstvenik == null)
            {
                return(HttpNotFound());
            }
            return(View(sopstvenik));
        }
Пример #2
0
        public ActionResult PrikaziVozilaSopstvenik(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Sopstvenik sopstvenik = db.Sopstvenici.Include(k => k.Vozila).Where(k => k.SopstvenikId == id).First();

            if (sopstvenik == null)
            {
                return(HttpNotFound());
            }

            return(View(sopstvenik));
        }
Пример #3
0
        public async Task <IActionResult> CreateSopstvenik(SopstvenikVM model)
        {
            if (ModelState.IsValid)
            {
                string     uniqueFileName = UploadedFile(model);
                Sopstvenik sopstvenik     = new Sopstvenik
                {
                    ImePrezime     = model.ImePrezime,
                    ImeMilenik     = model.ImeMilenik,
                    Email          = model.Email,
                    Grad           = model.Grad,
                    ProfilePicture = uniqueFileName,
                };
                _context.Add(sopstvenik);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(IndexSopstvenik)));
            }
            return(View(model));
        }
Пример #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    if (model.type == "Сопственик")
                    {
                        var sopstvenik = new Sopstvenik();
                        sopstvenik.Name     = model.Name;
                        sopstvenik.LastName = model.LastName;
                        sopstvenik.Address  = model.Address;
                        sopstvenik.Age      = model.Age;
                        sopstvenik.email    = model.Email;
                        sopstvenik.Telefon  = model.Telefon;
                        db.Sopstvenici.Add(sopstvenik);

                        try
                        {
                            var userr = UserManager.FindByEmail(model.Email);
                            UserManager.AddToRole(userr.Id, "Owner");
                        }

                        catch (Exception ex)
                        {
                            return(HttpNotFound());
                        }
                    }
                    else
                    {
                        var korisnik = new Korisnik();
                        korisnik.Name     = model.Name;
                        korisnik.LastName = model.LastName;
                        korisnik.Address  = model.Address;
                        korisnik.Age      = model.Age;
                        korisnik.email    = model.Email;
                        db.Korisnici.Add(korisnik);

                        try
                        {
                            var userr = UserManager.FindByEmail(model.Email);
                            UserManager.AddToRole(userr.Id, "User");
                        }

                        catch (Exception ex)
                        {
                            return(HttpNotFound());
                        }
                    }
                    db.SaveChanges();

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Voziloes"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #5
0
 public void Print()
 {
     Sopstvenik.Print();
     Datum.Print();
     Console.WriteLine($"Price: {Price}");
 }