/// <summary> /// Updates user contact details over user contract details contract client. /// </summary> /// <param name="dto">User contact details dto which has to be updated.</param> public void UpdateUsersContactDetails(UserContactDetailsDto dto) { _ucdc.UpdateUsersContactDetails(dto); }
/// <summary> /// Inserts users contact details over user contact details contract client. /// </summary> /// <param name="dto">User contact details dto which has to be inserted.</param> public void InsertUsersContactDetails(UserContactDetailsDto dto) { _ucdc.InsertUsersContactDetails(dto); }
/// <summary> /// Deletes user contact details over user contact details contract client. /// </summary> /// <param name="dto">User contact details dto which has to be deleted.</param> public void DeleteUsersContactDetails(UserContactDetailsDto dto) { _ucdc.DeleteUsersContactDetails(dto); }
public bool UpdateContactDetails( UserContactDetailsDto userContactDetailsDto, int modifiedByUserId, ref IList<string> errorMessages) { var user = _userRepository.GetById(userContactDetailsDto.UserId); #region Validation if (!userContactDetailsDto.IsValid) { errorMessages = userContactDetailsDto.ErrorMessages.ToList(); } if (user.UserStatusId != (int)UserStatus.Statuses.Active) { errorMessages.Add("You can't edit a user whose account is disabled or deleted."); } if ((userContactDetailsDto.UserId != modifiedByUserId) && (_roleRepository.GetByUserId(modifiedByUserId).All(r => r.RoleId != (int)Role.Roles.Administrator))) { errorMessages.Add("Wait, you're attempting to update another user's contact details. You can only edit your details, unless you're an administrator."); } if (errorMessages.Count > 0) { return false; } #endregion user.FirstName = userContactDetailsDto.FirstName; user.Surname = userContactDetailsDto.Surname; user.EmailAddress = userContactDetailsDto.EmailAddress; user.ModifiedByUserId = modifiedByUserId; user.ModifiedDateTime = DateTime.Now.ToGmtDateTime(); _userRepository.Update(user); var newUserRole = new UserRole { UserId = user.UserId, RoleId = userContactDetailsDto.RoleId }; _userRoleRepository.DeleteByUserId(user.UserId); _userRoleRepository.Insert(newUserRole); var userLog = new UserLog { UserId = modifiedByUserId, UserLogTypeId = (int)UserLogType.Types.EditedUserContactDetails, ActionAgainstUserId = userContactDetailsDto.UserId, AddedDateTime = DateTime.Now.ToGmtDateTime() }; _userLogRepository.Insert(userLog); UnitOfWork.Commit(); return true; }
public bool Insert( UserContactDetailsDto userContactDetailsDto, int addedByUserId, ref IList<string> errorMessages) { #region Validation if (!userContactDetailsDto.IsValid) { errorMessages = userContactDetailsDto.ErrorMessages.ToList(); return false; } if (_roleRepository.GetByUserId(addedByUserId).All(r => r.RoleId != (int)Role.Roles.Administrator)) { errorMessages.Add("Stop! You can't add a new user unless you're an administrator."); } if (errorMessages.Count > 0) { return false; } #endregion // Prepare the user entity. var addedDateTime = DateTime.Now.ToGmtDateTime(); var user = new User { UserStatusId = (int)UserStatus.Statuses.Active, FirstName = userContactDetailsDto.FirstName, Surname = userContactDetailsDto.Surname, EmailAddress = userContactDetailsDto.EmailAddress, HashedPassword = null, UnsuccessfulLoginAttempts = 0, AddedByUserId = addedByUserId, AddedDateTime = addedDateTime, ModifiedByUserId = addedByUserId, ModifiedDateTime = addedDateTime }; _userRepository.Insert(user); var userRole = new UserRole { UserId = user.UserId, RoleId = userContactDetailsDto.RoleId }; _userRoleRepository.Insert(userRole); var userLog = new UserLog { UserId = addedByUserId, UserLogTypeId = (int)UserLogType.Types.AddedUser, ActionAgainstUserId = userContactDetailsDto.UserId, AddedDateTime = DateTime.Now.ToGmtDateTime() }; _userLogRepository.Insert(userLog); // Dispatch email. IEmail email = new Email { ToEmailAddress = userContactDetailsDto.EmailAddress, ToRecipientName = string.Format("{0} {1}", userContactDetailsDto.FirstName, userContactDetailsDto.Surname), Subject = "Verify Email Address - Fallen Nova", EmailBody = "Email body goes here" }; if (!email.Dispatch()) { errorMessages.Add(string.Format("The user's account was created however the verification email wasn't sent succesfully. Contact the web admin.")); return false; } userContactDetailsDto.UserId = user.UserId; UnitOfWork.Commit(); return true; }
/// <summary> /// Fills all fields in form with data from passed dto object. /// </summary> /// <param name="dto">UserDto which represents current user (logged or selected)</param> private void PopulateFields(UserDto currentUserDto, UserPersonalDetailsDto currentUserPersonalDetailsDto, UserSystemInformationDto currentUserSystemInformationDto, UserContactDetailsDto currentUserContactDetailsDto, AddressDto currentAddressDto) { //Populate all text boxes tbUserId.Text = currentUserDto.UserId.ToString(); tbUserName.Text = currentUserDto.UserName; tbFirstName.Text = currentUserPersonalDetailsDto.FirstName; tbLastName.Text = currentUserPersonalDetailsDto.LastName; tbUserPassword.Text = currentUserDto.UserPassword; tbSocialSecurityNumber.Text = currentUserPersonalDetailsDto.SocSecNumber; tbLastSuccessfullLogIn.Text = currentUserSystemInformationDto.LastSuccessfullLogIn; tbUserLoggedIn.Text = currentUserSystemInformationDto.IsLoggedIn; tbAddress1.Text = currentAddressDto.AddressLine1; tbAddress2.Text = currentAddressDto.AddressLine2; tbAddress3.Text = currentAddressDto.AddressLine3; tbCity.Text = currentAddressDto.City; tbZip.Text = currentAddressDto.Zip; tbTelephone.Text = currentUserContactDetailsDto.Telephone; tbMobilePhone.Text = currentUserContactDetailsDto.Mobile; //Populate all combo boxes cbUserType.DataSource = UserTypeDtoList; cbUserType.DisplayMember = "UserTypeName"; cbUserType.ValueMember = "id"; cbUserType.DropDownStyle = ComboBoxStyle.DropDownList; cbUserType.SelectedIndex = currentUserSystemInformationDto.UserTypeId - 1; cbCountry.DataSource = CountryDtoList; cbCountry.DisplayMember = "Name"; cbCountry.ValueMember = "id"; cbCountry.DropDownStyle = ComboBoxStyle.DropDownList; cbCountry.SelectedIndex = currentAddressDto.CountryId - 1; cbState.DataSource = StateDtoList; cbState.DisplayMember = "Name"; cbState.ValueMember = "id"; cbState.DropDownStyle = ComboBoxStyle.DropDownList; cbState.SelectedIndex = currentAddressDto.StateId - 1; }