public async Task <IResult <GenericResponse> > UpdateCustomerProfile(IOption <long> id, UpdateCustomerProfileDto updateProfileData, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } var user = await _userService.GetUser(id.Always()); if (!user.IsNone) { var alwaysAUser = user.Always(); _mapper.Map(updateProfileData, alwaysAUser); // (from, to) alwaysAUser.ModifiedOn = DateTime.UtcNow; if (_userService.UpdateUser(alwaysAUser, alwaysAUser.Id)) { return(await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully updated profile." ))); } return(await Response <GenericResponse> .GetErrorResponseMessage("Problem updating profile.")); } return(await Response <GenericResponse> .GetErrorResponseMessage("Could not find the account.")); }
public async Task <IResult <IEnumerable <UserAddress> > > GetAddress(IOption <long> id, long addressId, byte addressType, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <IEnumerable <UserAddress> > .GetErrorResponseMessage("You are not authorized.")); } return((await _userService.GetAddress(id.Always(), addressId, addressType)) .Map(addresses => Response <IEnumerable <UserAddress> > .SuccessResponese(addresses)) .Or(Response <IEnumerable <UserAddress> > .ErrorResponse("User address is not found"))); }
public async Task <IResult <GenericResponse> > AddOrUpdateAddress(IOption <long> id, AddressDto addressData, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } if (addressData.IsAddOperation) { var addressToCreate = _mapper.Map <UserAddress>(addressData); addressToCreate.CreatedBy = id.Always(); addressToCreate.CreatedOn = DateTime.UtcNow; addressToCreate.UserId = id.Always(); var ret = await _userService.AddOrUpdateAddress(addressToCreate, addressData.IsAddOperation); int.TryParse(ret?.ReturnCode?.ToString(), out int code); return(code == 0 ? await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully added the address." )) : await Response <GenericResponse> .GetErrorResponseMessage(ret?.ReturnMsg?.ToString())); } else { var addressToUpdate = _mapper.Map <UserAddress>(addressData); addressToUpdate.ModifiedBy = id.Always(); addressToUpdate.ModifiedOn = DateTime.UtcNow; if (addressToUpdate.UserId == 0) { addressToUpdate.UserId = id.Always(); } var ret = await _userService.AddOrUpdateAddress(addressToUpdate, addressData.IsAddOperation); int.TryParse(ret?.ReturnCode?.ToString(), out int code); return(code == 0 ? await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully updated the address." )) : await Response <GenericResponse> .GetErrorResponseMessage(ret?.ReturnMsg?.ToString())); } }
public async Task <IResult <GenericResponse> > UpdateUserTheme(IOption <long> id, long userId, string theme, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } var userProfiles = await _userService.GetUserProfile(userId); if (!userProfiles.IsNone) { var alwaysUserProfileToUpdate = userProfiles.Always(); var userProfileToUpdate = alwaysUserProfileToUpdate.ToList()[0]; userProfileToUpdate.Theme = theme; userProfileToUpdate.ModifiedBy = requestUserId; userProfileToUpdate.ModifiedOn = DateTime.UtcNow; var ret = await _userService.UpdateUserProfile(userId, userProfileToUpdate); int.TryParse(ret?.ReturnCode?.ToString(), out int code); return(code == 0 ? await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully updated theme." )) : await Response <GenericResponse> .GetErrorResponseMessage(ret?.ReturnMsg?.ToString())); } return(await Response <GenericResponse> .GetErrorResponseMessage("Error updating theme.")); }
public async Task <IResult <GenericResponse> > UpdatePassword(IOption <long> id, UpdatePasswordDto updatePasswordData) { if (id.IsNone) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } var user = await _userService.GetUser(id.Always()); if (!user.IsNone) { var alwaysAUser = user.Always(); if (!VerifyPassword(updatePasswordData.OldPassword, alwaysAUser.Password)) { return(await Response <GenericResponse> .GetErrorResponseMessage("Please Enter your correct current password.")); } alwaysAUser.Password = new HashingManager().HashToString(updatePasswordData.NewPassword); alwaysAUser.ModifiedOn = DateTime.UtcNow; if (_userService.UpdateUser(alwaysAUser, alwaysAUser.Id)) { return(await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Password updated successfully." ))); } return(await Response <GenericResponse> .GetErrorResponseMessage("Problem updating password.")); } return(await Response <GenericResponse> .GetErrorResponseMessage("Could not find the account.")); }
public async Task <IResult <IEnumerable <UserProfile> > > GetUserProfile(IOption <long> id, long userId, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <IEnumerable <UserProfile> > .GetErrorResponseMessage("You are not authorized.")); } return((await _userService.GetUserProfile(userId)) .Map(userProfile => Response <IEnumerable <UserProfile> > .SuccessResponese(userProfile)) .Or(Response <IEnumerable <UserProfile> > .ErrorResponse("User is not found"))); }
public Task <IResult <GenericResponse> > MakeKeyExpire(IOption <Claim> claimOption) { return(claimOption.IsSome ? _userService.InsertExpiredKey(claimOption.Always().Value) ? Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully logged out." )) : Response <GenericResponse> .GetErrorResponseMessage("Problem login out.") : Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); }
public Task <IResult <GenericResponse> > Register(IOption <long> id, UserProfileDto userProfileDto, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } string password = new Random().Next(100000, 999999).ToString(); var addressData = new UserAddress(userProfileDto.FirstName, userProfileDto.LastName, userProfileDto.CompanyName, userProfileDto.Country, userProfileDto.Address, userProfileDto.City, userProfileDto.State, userProfileDto.PostCode ?? 0, userProfileDto.Email, userProfileDto.Phone, 1, 0, requestUserId, DateTime.UtcNow ); return(Register(userProfileDto.FirstName, userProfileDto.LastName, userProfileDto.Email, userProfileDto.Phone, password, userProfileDto.Role, id.Always(), DateTime.UtcNow, addressData)); }
public async Task <IResult <GenericResponse> > DeleteUser(IOption <long> id, long userId, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } var ret = await _userService.DeleteUser(userId); int.TryParse(ret?.ReturnCode?.ToString(), out int code); return(code == 0 ? await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully deleted the user." )) : await Response <GenericResponse> .GetErrorResponseMessage(ret?.ReturnMsg?.ToString())); }
public async Task <IResult <GenericResponse> > UpdateUserProfile(IOption <long> id, long userId, UserProfileDto profileData, long requestUserId) { if (id.IsNone || id.Always() != requestUserId) { return(await Response <GenericResponse> .GetErrorResponseMessage("You are not authorized.")); } var userProfiles = await _userService.GetUserProfile(userId); if (!userProfiles.IsNone) { var alwaysUserProfileToUpdate = userProfiles.Always(); var userProfileToUpdate = alwaysUserProfileToUpdate.ToList()[0]; // only admin can change the role if (userProfileToUpdate.Role != Roles.Admin) { var prevRole = userProfileToUpdate.Role; _mapper.Map(profileData, userProfileToUpdate); // (from, to) userProfileToUpdate.Role = prevRole; } else { _mapper.Map(profileData, userProfileToUpdate); // (from, to) } userProfileToUpdate.ModifiedBy = requestUserId; userProfileToUpdate.ModifiedOn = DateTime.UtcNow; var ret = await _userService.UpdateUserProfile(userId, userProfileToUpdate); int.TryParse(ret?.ReturnCode?.ToString(), out int code); return(code == 0 ? await Task <IResult <GenericResponse> > .Factory.StartNew( () => Response <GenericResponse> .SuccessResponese( "Successfully updated profile." )) : await Response <GenericResponse> .GetErrorResponseMessage(ret?.ReturnMsg?.ToString())); } return(await Response <GenericResponse> .GetErrorResponseMessage("Error updating profile.")); }