/// <summary> /// add the admin or agent user /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> AddAdminAgentUsersAsync(AdminAgentUserViewModel user) { if (string.IsNullOrEmpty(user.UserName) || user.Password == null || user.Name == null || user.MobileNo == null) { return((int)StatusCode.ExpectationFailed); } var existingTemplate = await _userRepository.SelectAsync(u => u.UserName == user.UserName || u.MobileNo == user.MobileNo); if (existingTemplate.Any()) { return((int)StatusCode.ConflictStatusCode); } var userTypes = new List <UserTypes>(); if (user.IsAdmin == false && user.IsAgent == true && user.IsOperator == false) { userTypes = (await _userTypesRepository.SelectAsync(u => u.UserType == UserTypesConstants.Agent)).ToList(); } else if (user.IsAdmin == true && user.IsAgent == false && user.IsOperator == false) { userTypes = (await _userTypesRepository.SelectAsync(u => u.UserType == UserTypesConstants.Admin)).ToList(); } else if (user.IsAdmin == false && user.IsAgent == false && user.IsOperator == true) { userTypes = (await _userTypesRepository.SelectAsync(u => u.UserType == UserTypesConstants.Operator)).ToList(); } var newuser = new Users(); newuser.UserId = Guid.NewGuid(); newuser.UserName = user.UserName; newuser.Password = Convert.ToString(EncryptionandDecryption.Encrypt(user.Password)); newuser.Name = user.Name; newuser.MobileNo = user.MobileNo; newuser.Address = user.Address; newuser.Email = user.Email; newuser.CreatedAt = DateTime.UtcNow; newuser.UserTypeId = userTypes[0].UserTypeId; newuser.DateOfBirth = user.DateOfBirth; newuser.AadharNo = user.AadharNo; newuser.DrivingLicenceNo = user.DrivingLicenceNo; await _userRepository.AddAsync(newuser); await _userRepository.Uow.SaveChangesAsync(); return((int)StatusCode.SuccessfulStatusCode); }
/// <summary> /// Add new user /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> AddUserAsync(Users user) { if (string.IsNullOrEmpty(user.UserName) || user.Password == null || user.Name == null || user.MobileNo == null) { return((int)StatusCode.ExpectationFailed); } var existingTemplate = await _userRepository.SelectAsync(u => u.UserName == user.UserName || u.MobileNo == user.MobileNo); var userTypes = await _userTypesRepository.SelectAsync(u => u.UserType == UserTypesConstants.Customer); if (string.IsNullOrWhiteSpace(user.PromoCode)) { if (existingTemplate.Any()) { return((int)StatusCode.ConflictStatusCode); } user.Password = Convert.ToString(EncryptionandDecryption.Encrypt(user.Password)); user.CreatedAt = DateTime.UtcNow; user.UserId = Guid.NewGuid(); user.UserTypeId = userTypes[0].UserTypeId; user.PromoCode = null; user.PromoCodePoints = null; } else { var promocodes = (await _promoCodesRepository.SelectAsync(x => x.PromoCode == user.PromoCode)).ToList(); if (existingTemplate.Any()) { return((int)StatusCode.ConflictStatusCode); } user.Password = Convert.ToString(EncryptionandDecryption.Encrypt(user.Password)); user.CreatedAt = DateTime.UtcNow; user.UserId = Guid.NewGuid(); user.UserTypeId = userTypes[0].UserTypeId; user.PromoCode = Convert.ToString(promocodes[0].PromoCode); user.PromoCodePoints = Convert.ToString(promocodes[0].PromoCodePoints); await _promoCodesRepository.DeleteAsync(promocodes[0]); } await _userRepository.AddAsync(user); await _userRepository.Uow.SaveChangesAsync(); return((int)StatusCode.SuccessfulStatusCode); }
/// <summary> /// Update the user password /// </summary> /// <param name="newPass"></param> /// <param name="conPass"></param> /// <param name="mob"></param> /// <returns></returns> public async Task <int> UpdateUserPasswordAsync(string newPass, string conPass, string mob) { if (string.IsNullOrEmpty(newPass) || string.IsNullOrEmpty(conPass) || string.IsNullOrEmpty(mob)) { return((int)StatusCode.ExpectationFailed); } var existingUser = await _userRepository.SelectAsync(u => u.MobileNo == mob); if (existingUser.Any() && newPass == conPass) { existingUser[0].Password = Convert.ToString(EncryptionandDecryption.Encrypt(newPass)); await _userRepository.UpdateAsync(existingUser[0]); await _userRepository.Uow.SaveChangesAsync(); return((int)StatusCode.SuccessfulStatusCode); } else { return((int)StatusCode.NoContent); } }
/// <summary> /// Update the customer profile /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> UpdateCustomerProfileAsync(CustomerProfileViewModel user) { if (string.IsNullOrEmpty(user.UserName) || user.Password == null || user.Name == null || user.MobileNo == null) { return((int)StatusCode.ExpectationFailed); } var existingTemplate = await _userRepository.SelectAsync(u => u.UserId == Guid.Parse(user.UserId)); if (existingTemplate.Any()) { var existingMobile = await _userRepository.SelectAsync(u => u.MobileNo == user.MobileNo && u.UserId != Guid.Parse(user.UserId)); if (existingMobile.Any()) { return((int)StatusCode.ConflictStatusCode); } existingTemplate[0].Password = Convert.ToString(EncryptionandDecryption.Encrypt(user.Password)); existingTemplate[0].Name = user.Name; existingTemplate[0].Address = user.Address; existingTemplate[0].MobileNo = user.MobileNo; existingTemplate[0].Email = user.EmailId; existingTemplate[0].SecurityAnswerOne = user.SecurityAnsOne; existingTemplate[0].SecurityAnswerTwo = user.SecurityAnsTwo; existingTemplate[0].CreatedAt = DateTime.UtcNow; await _userRepository.UpdateAsync(existingTemplate[0]); await _userRepository.Uow.SaveChangesAsync(); return((int)StatusCode.SuccessfulStatusCode); } else { return((int)StatusCode.NoContent); } }