public async Task <IActionResult> Edit(int id, [Bind("IdKorisnik,ZahtijevaEko")] Narucitelj narucitelj) { if (id != narucitelj.IdKorisnik) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(narucitelj); await _context.SaveChangesAsync(); TempData[Constants.Message] = "Ažuriranje uspješno obavljeno"; TempData[Constants.ErrorOccurred] = false; } catch (DbUpdateConcurrencyException) { if (!NaruciteljExists(narucitelj.IdKorisnik)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdKorisnik"] = new SelectList(_context.Korisnik, "Id", "Prezime", narucitelj.IdKorisnik); return(View(narucitelj)); }
public async Task <IActionResult> Create([Bind("Id,Oib,Ime,Prezime,Lozinka,TelBroj,Email")] Korisnik korisnik) { if (ModelState.IsValid) { _context.Korisnik.Add(korisnik); Narucitelj narucitelj = new Narucitelj { IdKorisnik = korisnik.Id, IdKorisnikNavigation = korisnik }; _context.Narucitelj.Add(narucitelj); Prijevoznik prijevoznik = new Prijevoznik { IdKorisnik = korisnik.Id, IdKorisnikNavigation = korisnik }; _context.Prijevoznik.Add(prijevoznik); await _context.SaveChangesAsync(); TempData[Constants.Message] = $"Korisnik dodan."; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Index))); } return(View(korisnik)); }
public async Task <IActionResult> Create([Bind("IdKorisnik,ZahtijevaEko")] Narucitelj narucitelj) { if (ModelState.IsValid) { _context.Add(narucitelj); await _context.SaveChangesAsync(); TempData[Constants.Message] = $"Naručitelj {narucitelj.IdKorisnikNavigation} dodan."; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Index))); } ViewData["IdKorisnik"] = new SelectList(_context.Korisnik, "Id", "Prezime", narucitelj.IdKorisnik); return(View(narucitelj)); }
public async Task <IActionResult> Register(string PrimaEmail, ExtendedRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { Korisnik korisnik = new Korisnik { Ime = model.Ime, Prezime = model.Prezime, Email = model.Email, Lozinka = model.Password, TelBroj = model.TelBroj, Oib = model.Oib }; if (PrimaEmail == "on") { korisnik.PrimaEmail = true; } else { korisnik.PrimaEmail = false; } _context.Korisnik.Add(korisnik); _context.SaveChanges(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, IdKorisnik = korisnik.Id }; var result = await _userManager.CreateAsync(user, model.Password); if (model.Uloga == "N") { Narucitelj narucitelj = new Narucitelj { IdKorisnik = korisnik.Id }; _context.Narucitelj.Add(narucitelj); await _userManager.AddToRoleAsync(user, "narucitelj"); } else if (model.Uloga == "P") { Prijevoznik prijevoznik = new Prijevoznik { IdKorisnik = korisnik.Id }; _context.Prijevoznik.Add(prijevoznik); await _userManager.AddToRoleAsync(user, "prijevoznik"); } else if (model.Uloga == "A") { await _userManager.AddToRoleAsync(user, "administrator"); } _context.SaveChanges(); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); if (PrimaEmail == "on") { var smtpClient = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, Credentials = new NetworkCredential("*****@*****.**", "carryon1") }; using (var message = new MailMessage("*****@*****.**", user.Email) { Subject = "Uspješna registracija", Body = "Uspješno ste se registrirali." }) { await smtpClient.SendMailAsync(message); } } return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }