public async Task <IActionResult> Create([Bind("ID,Email,Password")] Users users) { user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); bool AlreadyExist = _context.Users.Any(u => u.Email == users.Email); if (AlreadyExist) { ViewBag.AlreadyExist = true; return(View("~/Views/Users/Create.cshtml")); } if (user == null) { if (ModelState.IsValid) { users.Password = getHash(users.Password); _context.Add(users); await _context.SaveChangesAsync(); var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, users.Email)); identity.AddClaim(new Claim(ClaimTypes.Name, users.Email)); // Authenticate using the identity var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); } return(RedirectToAction("Index", "Tours")); } else { return(View("~/Views/Home/Index.cshtml")); } }
public async Task <bool> AddCounter(Counter counterDetails) { counterDetails.CreatedOn = DateTime.Now; _travelContext.Add(counterDetails); var result = await _travelContext.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Create([Bind("ID,ClientName")] Clients clients) { if (ModelState.IsValid) { _context.Add(clients); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(clients)); }
public async Task <IActionResult> Create([Bind("ID,ExcursionName")] Excursion_Sights excursion_Sights) { if (ModelState.IsValid) { _context.Add(excursion_Sights); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(excursion_Sights)); }
public int RegisterUser(RegisterUser registerUser) { var entity = new User { FirstName = registerUser.FirstName, Email = registerUser.Email, Password = registerUser.Password, Salt = registerUser.Salt, Role = registerUser.Role, LastName = registerUser.LastName, CreatedOn = DateTime.UtcNow }; _travelContext.Add(entity); var status = _travelContext.SaveChanges(); return(status); }
public async Task <IActionResult> Create([Bind("TourName,Date")] Tours tours) { try { if (ModelState.IsValid) { _context.Add(tours); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(tours)); }
public Trip Add(Trip trip) { return(_context.Add(trip).Entity); }