public void Update(Contact oldModel) { var contactToUpdate = _ctx.Contacts.FirstOrDefault(x => x.SenderId == oldModel.SenderId); _ctx.Entry(contactToUpdate).CurrentValues.SetValues(oldModel); _ctx.SaveChanges(); }
public void Update(UserProfile oldModel) { var userToUpdate = _ctx.UserProfiles.FirstOrDefault(x => x.Id == oldModel.Id); _ctx.Entry(userToUpdate).CurrentValues.SetValues(oldModel); _ctx.SaveChanges(); }
public void Update(UserServices oldModel) { var serviceToUpdate = _ctx.Services.FirstOrDefault(x => x.ServiceId == oldModel.ServiceId); _ctx.Entry(serviceToUpdate).CurrentValues.SetValues(oldModel); _ctx.SaveChanges(); }
public void Update(Project oldModel) { var projectToUpdate = _ctx.Projects.FirstOrDefault(x => x.ProjectId == oldModel.ProjectId); _ctx.Entry(projectToUpdate).CurrentValues.SetValues(oldModel); _ctx.SaveChanges(); }
public void Update(Education oldModel) { var educationToUpdate = _ctx.Educations.FirstOrDefault(x => x.EducationId == oldModel.EducationId); _ctx.Entry(educationToUpdate).CurrentValues.SetValues(oldModel); _ctx.SaveChanges(); }
public async Task<IActionResult> Delete(int id) { using (var context = new UserProfileDbContext()) { var user = await context.ChiTietPhieuThus.FindAsync(id); if (user == null) return NotFound(); context.Entry(user).State = EntityState.Deleted; return Ok(await context.SaveChangesAsync()); } }
public async Task <IActionResult> Delete(int id) { using (var context = new UserProfileDbContext()) { var user = await context.TinhChatKhoanThus.FindAsync(id); if (user == null) { return(NotFound()); } context.Entry(user).State = EntityState.Deleted; return(Ok(await context.SaveChangesAsync())); } }
public async Task <bool> UserActivation(UserActivationDto activationDto) { using (var _activateTrans = _userProfileDbContext.Database.BeginTransaction()) { var activate = await _userProfileDbContext.UserActivationModel.FirstOrDefaultAsync(a => a.ActivationCode == activationDto.ActivationCode && a.UserModelId == activationDto.UserId); if (activate != null) { //check if code has expired var checkTime = activate.ExpiresAt >= (DateTime.UtcNow) ? true : false; if (checkTime) { //delete the code from the database _userProfileDbContext.Remove(activate); await _userProfileDbContext.SaveChangesAsync(); //update user table with statuses var user = await _userProfileDbContext.UserModel.FirstOrDefaultAsync(u => u.Id == activationDto.UserId); if (user != null) { user.IsActivated = true; user.IsActive = true; _userProfileDbContext.Entry(user).State = EntityState.Modified; await _userProfileDbContext.SaveChangesAsync(); } //commit to database _activateTrans.Commit(); return(true); } return(false); } } return(false); }