public async Task <IActionResult> PutEmployee(long id, Employee employee) { if (id != employee.Id) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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 <IActionResult> PutTrip(long id, Trips trip) { if (id != trip.Id) { return(BadRequest()); } _context.Entry(trip).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TripExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Client> > PutClient(int id, Client client) { if (id != client.Id) { return(BadRequest()); } _context.Entry(client).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(id)) { return(NotFound()); } else { throw; } } return(await _context.Client.FindAsync(client.Id)); }
public async Task <IActionResult> PutCustomer(long id, Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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 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 async Task <bool> HardDeleteUserById(Guid id) { var user = await _travelContext.Users .FirstOrDefaultAsync(x => x.Id == id); if (user != null) { _travelContext.Users.Remove(user); var result = await _travelContext.SaveChangesAsync(); return(result > 0); } return(false); }