/// <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> /// check the promo code is present or not /// </summary> /// <param name="promoCode"></param> /// <returns></returns> public async Task <bool> IsPromoCodeValidAsync(string promoCode) { if (string.IsNullOrWhiteSpace(promoCode)) { return(false); } var promoCodes = (await _promoCodesRepository.SelectAsync(x => x.PromoCode == promoCode)).ToList(); if (promoCodes.Any()) { return(true); } else { return(false); } }