public async Task <IActionResult> PutBuilding(int id, Building building) { if (id != building.Id) { return(BadRequest()); } _context.Entry(building).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BuildingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSession(int id, Session session) { if (id != session.Id) { return(BadRequest()); } _context.Entry(session).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SessionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <SubjectUser> > PostSubjectUser(SubjectUser subjectUser) { _context.SubjectUsers.Add(subjectUser); await _context.SaveChangesAsync(); return(RedirectToAction("GetSubjectUser", new { id = subjectUser.Id })); }
public async Task <IActionResult> PutUserData(int id, UserData userData) { if (id != userData.UserId) { return(BadRequest()); } _context.Entry(userData).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserDataExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDepartment(int id, Department department) { if (id != department.Id) { return(BadRequest()); } _context.Entry(department).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPermissionType(int id, PermissionType permissionType) { if (id != permissionType.Id) { return(BadRequest()); } _context.Entry(permissionType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PermissionTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Username,Email,SocialSecurityNumber,Password")] Account account) { if (ModelState.IsValid) { _context.Add(account); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(account)); }
public async Task <int> Delete(int id) { //_context.UserEntityDb.Remove(user); var user = await _context.UserEntityDb.FindAsync(id); if (user != null) { _context.UserEntityDb.Remove(user); } var ret = await _context.SaveChangesAsync(); return(ret); }
public override async Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) { if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } string identifier = resourceIdentifier.Identifier; if (int.TryParse(identifier, out int id) && _context.Users.Find(id) is MvcMovie.Models.User deleteUser) { _context.Users.Remove(deleteUser); await _context.SaveChangesAsync(); } }
public async Task <IActionResult> UpdateUser(UserProfileViewModel model) { string id = User.FindFirst("id").Value; User user = await UserManager.FindByIdAsync(id); if (user == null || !user.PhoneNumberConfirmed) { return(Unauthorized()); } if (user.FileNo != model.FileNo) { return(Unauthorized()); } user = Mapper.Map(model, user); user.Activities.Add(new AccountActivity() { ActivityType = Models.Entities.Activity.AccountUpdated }); UserDataContext.Update(user); await UserDataContext.SaveChangesAsync(); return(Ok()); }
public async Task <HandlerResponse <User> > Handle(CreateUserRequest request, CancellationToken cancellationToken) { HandlerResponse <User> response; var existingUser = await _dataContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.Username.Equals(request.Username, StringComparison.InvariantCultureIgnoreCase), cancellationToken); if (existingUser != null) { response = new HandlerResponse <User>($"Please supply an unique username"); } else { var userToCreate = new User { Username = request.Username }; try { await _dataContext.Users.AddAsync(userToCreate, cancellationToken); await _dataContext.SaveChangesAsync(cancellationToken); var user = await _dataContext.Users.AsNoTracking().SingleAsync(u => u.Id == userToCreate.Id, cancellationToken); response = new HandlerResponse <User>(user); } catch (DbException) { response = new HandlerResponse <User>($"Unable to create User"); } } return(response); }
public async Task <HandlerResponse <bool> > Handle(DeleteUserRequest request, CancellationToken cancellationToken) { HandlerResponse <bool> response; var user = await _dataContext.Users.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken); if (user is null) { response = new HandlerResponse <bool>(true, "User was not present"); } else { try { _dataContext.Users.Remove(user); await _dataContext.SaveChangesAsync(cancellationToken); response = new HandlerResponse <bool>(true); } catch (DbException) { response = new HandlerResponse <bool>($"Unable to delete User"); } } return(response); }
public async Task <ActionResult <User> > PostUser([FromBody] User user) { user.ProfilePictureName = await SaveImage(user.ImageFile); _context.Users.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction("GetUser", new { id = user.Id })); }
public async Task AddAsync(UserCommand user) { var userValid = new User { Age = user.Age, FirstName = user.FirstName, LastName = user.LastName, Street = user.Street, StreetNumber = user.StreetNumber, TelephoneNumber = user.TelephoneNumber, Username = user.Username, EmailAddress = user.EmailAddress }; await _context.UsersData.AddAsync(userValid); await _context.SaveChangesAsync(); }
async Task <IActionResult> UpdateApprovalStatus(string userId, ApprovalStatus status) { string id = User.FindFirst("id").Value; User coordinator = await UserManager.FindByIdAsync(id); if (coordinator == null) { return(Unauthorized()); } User user = await UserManager.FindByIdAsync(userId); if (user == null) { return(NotFound("The requested user was not found")); } if (user.ApprovalStatus == status) { return(Ok()); } user.ApprovalStatus = status; await UserDataContext.Entry(user).Collection(u => u.Activities).LoadAsync(); Activity activityType = status == ApprovalStatus.Approved ? Activity.AccountApproved : Activity.UpdateRequested; CoordinatorActivity activity = new CoordinatorActivity(activityType, coordinator); user.Activities.Add(activity); await UserManager.UpdateAsync(user); await UserDataContext.SaveChangesAsync(); return(Ok()); }
public async Task <HandlerResponse <bool> > Handle(UpdateUserRequest request, CancellationToken cancellationToken) { HandlerResponse <bool> response; var user = await _dataContext.Users.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken); if (user is null) { response = new HandlerResponse <bool>("Unable to find User"); } else { var existingUserName = await _dataContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.Username.Equals(request.Username, StringComparison.InvariantCultureIgnoreCase), cancellationToken); if (existingUserName != null) { response = new HandlerResponse <bool>($"Please supply an unique username"); } else { try { user.Username = request.Username; await _dataContext.SaveChangesAsync(cancellationToken); response = new HandlerResponse <bool>(true); } catch (DbException) { response = new HandlerResponse <bool>($"Unable to update User"); } } } return(response); }