public virtual TEntity Update(TEntity entity) { string currentUser = CurrentUserHolder.GetCurrentUserName(); entity.UpdatedBy = currentUser; entity.Updated = DateTime.UtcNow; var entityEntry = DbSet.Update(entity); DbContext.SaveChanges(); return(entityEntry.Entity); }
public UserInfo RegisterDonor(DonorRequestViewModel request) { var userInfo = new UserInfo() { Email = request.Email, FirstName = request.FirstName, SecondName = request.SecondName, AddressLine1 = request.AddressLine1, AddressLine2 = request.AddressLine2, City = request.City, Country = request.Country, ZipCode = request.ZipCode, PhoneNumber = request.PhoneNumber, BirthDate = request.BirthDate }; AppUser user = new AppUser() { Email = request.Email, UserName = request.Email, Created = DateTime.UtcNow, CreatedBy = CurrentUserHolder.GetCurrentUserName(), EmailConfirmed = true, PhoneNumber = request.PhoneNumber, PhoneNumberConfirmed = true, UserInfo = userInfo }; var result = _userManager.CreateAsync(user, request.Password).Result; if (result.Succeeded) { result = _userManager.AddToRoleAsync(user, RolesConstants.Donor).Result; } else { throw new ArgumentException(result.Errors.First().Description); } if (!result.Succeeded) { _userManager.DeleteAsync(user).Wait(); throw new InvalidOperationException(UserCreationFailedErrorMessage); } return(userInfo); }
private void UpdateMedicalExamResultsInner(MedicalExamResultViewModel model) { var donorRequest = _donorRequestsRepository.GetById(model.DonorRequestId); if (donorRequest == null) { //TODO: handle return; } donorRequest.Status = model.MedicalExamStatus == MedicalExamStatuses.Pass ? DonorRequestStatuses.AwaitingForPatientRequest : DonorRequestStatuses.FailedMedicalExamination; var exam = _medicalExamsService.GetLastMedicalExamByDonorRequestId(donorRequest.Id); exam.Results = model.MedicalExamResults; exam.Status = model.MedicalExamStatus; if (model.MedicalExamStatus == MedicalExamStatuses.Pass && !donorRequest.TransplantOrganId.HasValue) { donorRequest.TransplantOrgan = new TransplantOrgan() { UserInfoId = donorRequest.DonorInfoId, OrganInfoId = donorRequest.OrganInfoId, ClinicId = exam.ClinicId, Status = TransplantOrganStatuses.AwaitingSchedulingRetrieving, Created = DateTime.UtcNow, CreatedBy = CurrentUserHolder.GetCurrentUserName() }; } _medicalExamsService.UpdateMedicalExam(exam); _donorRequestsRepository.Update(donorRequest); }