Beispiel #1
0
        public async Task <(bool HasReferralCodeTransactionCountExceeded, bool IsDuplicateTransaction, bool IsReferralCodeSelfUsed)> CheckReferralCodeAsync(string ReferralCode, Guid BenificiaryUserId)
        {
            ReferralCode referralCodeDetails = await _referralCodeRepository.GetSingleBySpecAsync(x => x.RefCode.ToLower() == ReferralCode.ToLower());

            Guard.Against.NullItem <ReferralCode>(referralCodeDetails);

            int duplicateTransactionCount = referralCodeDetails.ReferralCodeTransactions.Count(x => x.BenificiaryId == BenificiaryUserId);

            (bool HasReferralCodeTransactionCountExceeded, bool IsDuplicateTransaction, bool IsReferralCodeSelfUsed)referralCodeStatusTuple = (false, false, false);

            if (referralCodeDetails.ReferralCodeTransactionCount >= 3)
            {
                referralCodeStatusTuple.HasReferralCodeTransactionCountExceeded = true;
            }

            if (duplicateTransactionCount > 0)
            {
                referralCodeStatusTuple.IsDuplicateTransaction = true;
            }

            if (referralCodeDetails.UserId == BenificiaryUserId)
            {
                referralCodeStatusTuple.IsReferralCodeSelfUsed = true;
            }

            return(referralCodeStatusTuple);
        }
Beispiel #2
0
        private RecordDeleteViewModel DeleteModel(string id, out ReferralCode record)
        {
            RecordDeleteViewModel deleteModel = new RecordDeleteViewModel();

            record = null;
            deleteModel.ActionName     = "Delete";
            deleteModel.ControllerName = "ReferralCode";
            deleteModel.Id             = id;
            deleteModel.Title          = "Delete Referral Code";
            if (id == null)
            {
                ModelState.AddModelError(string.Empty, "Invalid Action");
                return(deleteModel);
            }
            record = _context.ReferralCode.SingleOrDefault(m => m.Id == id);
            if (record == null)
            {
                ModelState.AddModelError(string.Empty, "Record not found.");
            }
            else
            {
                deleteModel.RecordDetail.Add(new RecordDetail {
                    Label = "PIN Code", Value = record.PINCode
                });
                deleteModel.RecordDetail.Add(new RecordDetail {
                    Label = "Secutiry Code", Value = record.SecutiryCode
                });
            }
            return(deleteModel);
        }
 public override string ToString()
 {
     return(string.Format("MegacoolShare(State={0}, ReferralCode={1}, Url=\"{2}\", Data={3}, " +
                          "CreatedAt={4}, UpdatedAt={5})",
                          State, ReferralCode.ToString(true), Url, Data == null ? null : Json.Serialize(Data),
                          CreatedAt.ToString("yyyy-MM-ddTHH:mm:ss"), UpdatedAt.ToString("yyyy-MM-ddTHH:mm:ss")));
 }
Beispiel #4
0
        public async Task AddNewBookingAsync(Booking NewBooking, string ReferralCode, string BookingTimeZoneId)
        {
            await _bookingRepository.AddAsync(NewBooking);

            string subject = "Booking Confirmation";

            if (!string.IsNullOrEmpty(ReferralCode))
            {
                ReferralCode referralCodeDetails = await _referralCodeRepository.GetSingleBySpecAsync(x => x.RefCode.ToLower() == ReferralCode.ToLower());

                ReferralCodeTransaction newTransaction = new ReferralCodeTransaction
                {
                    ReferralTransactionId = Guid.NewGuid(),
                    ReferralCodeId        = referralCodeDetails.ReferralCodeId,
                    IssuerId      = referralCodeDetails.UserId,
                    BenificiaryId = NewBooking.UserID,
                    BookingId     = NewBooking.BookingID
                };

                await _referralCodeTransactionRepository.AddAsync(newTransaction);

                referralCodeDetails.ReferralCodeTransactionCount = referralCodeDetails.ReferralCodeTransactionCount + 1;
                await _referralCodeRepository.UpdateAsync(referralCodeDetails);
            }

            Booking currentBooking = await _bookingRepository.GetByIdAsync(NewBooking.BookingID);

            string path         = Path.Combine(_hostingEnvironment.WebRootPath, "EmailMarkup.html");
            string customerName = $"{currentBooking.ApplicationUser.FirstName} {currentBooking.ApplicationUser.LastName}";
            string bookingID    = currentBooking.BookingID.ToString();
            string bookedFrom   = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currentBooking.BookingFromDate, BookingTimeZoneId).ToString();
            string bookedTo     = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currentBooking.BookingToDate, BookingTimeZoneId).ToString();
            string venueName    = currentBooking.VenueDetail.VenueName;
            string venueCity    = currentBooking.VenueDetail.VenueCity;
            string venueState   = currentBooking.VenueDetail.VenueState;
            string price        = currentBooking.Price.ToString();


            string emailMarkupBody = await File.ReadAllTextAsync(path);

            emailMarkupBody = emailMarkupBody.Replace("{CustomerName}", customerName);
            emailMarkupBody = emailMarkupBody.Replace("{BookingID}", bookingID);
            emailMarkupBody = emailMarkupBody.Replace("{BookedFrom}", bookedFrom);
            emailMarkupBody = emailMarkupBody.Replace("{BookedTo}", bookedTo);
            emailMarkupBody = emailMarkupBody.Replace("{VenueName}", venueName);
            emailMarkupBody = emailMarkupBody.Replace("{VenueCity}", venueCity);
            emailMarkupBody = emailMarkupBody.Replace("{VenueState}", venueState);
            emailMarkupBody = emailMarkupBody.Replace("{Price}", price);

            EmailModel emailModel = new EmailModel
            {
                EmailTo = currentBooking.ApplicationUser.Email,
                Body    = emailMarkupBody,
            };

            await _emailService.SendEmailAsync(emailModel);
        }
        public ReferralCode GenerateReferralCode(string UserName, Guid UserId)
        {
            string       userIdString        = UserId.ToString();
            string       referralCode        = $"{UserName.Substring(0,4)}_{CreateCryptoRandomString()}";
            ReferralCode referralCodeDetails = new ReferralCode
            {
                ReferralCodeId = Guid.NewGuid(),
                UserId         = UserId,
                ReferralCodeTransactionCount = 0,
                RefCode = referralCode
            };

            return(referralCodeDetails);
        }
Beispiel #6
0
        public IActionResult GenerateCode(int quantity)
        {
            ReferralCodeList         codeList = new ReferralCodeList();
            List <ReferralCodeModel> records  = new List <ReferralCodeModel>();

            for (int i = 0; i < quantity; i++)
            {
                var code = new ReferralCode
                {
                    PINCode            = _codeGenerator.GeneratePINCode(),
                    SecutiryCode       = _codeGenerator.GenerateSecurityCode(),
                    ReferralCodeStatus = Enums.ReferralCodeStatus.Open
                };
                code.ReferralCode_Id = $"{code.PINCode}-{code.SecutiryCode}";
                _context.ReferralCode.Add(code);
                var affected = _context.SaveChanges();
                if (affected != 0)
                {
                    records.Add(_mapper.Map <ReferralCodeModel>(code));
                }
            }
            codeList.Records = records;
            return(PartialView("_GenerateCode", codeList));
        }
 public async Task AddReferralCode(ReferralCode ReferralCodeDetails)
 {
     await _referralRepository.AddAsync(ReferralCodeDetails);
 }
        public async Task <IActionResult> RegisterAsync([FromBody] RegisterUserModelDTO RegisterUserModelDTO)
        {
            Guard.Against.NullItem(RegisterUserModelDTO);

            //Check for duplicate user-names and e-mail
            ApplicationUser foundUser = await _userManager.Users.Where(x => x.Email == RegisterUserModelDTO.UserEmail || x.UserName == RegisterUserModelDTO.UserName).FirstOrDefaultAsync();

            //Throw HTTP 409 Conflict then
            if (foundUser != null)
            {
                return(StatusCode(409, new { message = $"The username / email is already taken and is conflicting with other records, please give an unique username / email." }));
            }

            ApplicationUser applicationUser = new ApplicationUser
            {
                UserName       = RegisterUserModelDTO.UserName,
                Email          = RegisterUserModelDTO.UserEmail,
                FirstName      = RegisterUserModelDTO.FirstName,
                LastName       = RegisterUserModelDTO.LastName,
                PhoneNumber    = RegisterUserModelDTO.PhoneNumber,
                EmailConfirmed = false
            };

            IdentityResult createResult = await _userManager.CreateAsync(applicationUser, RegisterUserModelDTO.Password);

            //User creation failed because of some constraints
            if (!createResult.Succeeded)
            {
                return(BadRequest(new { message = createResult.GetIdentityResultErrorMessage() }));
            }

            await _signInManager.SignInAsync(applicationUser, false);

            await _userManager.AddToRoleAsync(applicationUser, UserType.User.ToString());

            //Generate JWT now
            string jwtToken = await _tokenManager.GenerateJWTAsync(applicationUser);

            //Send verify email now
            EmailModel emailModel = new EmailModel
            {
                EmailTo = RegisterUserModelDTO.UserEmail,
                Body    = $"<html><body><a href='{_configSettings.URL.VerifyEmailURL}/{jwtToken}'>Click here to verify Email</a><br></body></html>",
                Subject = "Verify your Email"
            };
            await _emailManager.SendEmailAsync(emailModel);

            ReferralCode referralCode = GenerateReferralCode(applicationUser.UserName, applicationUser.Id);
            await _referralCodeService.AddReferralCode(referralCode);

            //Send Referral code mail now
            emailModel.Body    = $"<html><body><fieldset><legend> Referral code for User - {applicationUser.UserName} </legend> {referralCode.RefCode} </fieldset></body></html>";
            emailModel.Subject = $"Visneto Referral Code for new user - {applicationUser.UserName}";
            await _emailManager.SendEmailAsync(emailModel);

            //Return HTTP 201 Created for new user
            return(StatusCode(201, new
            {
                role = UserType.User.ToString(),
                access_token = jwtToken,
                expires = 3600,
                email = string.Empty,
                user_name = RegisterUserModelDTO.UserName
            }));
        }
        public async Task <IActionResult> ExternalLoginAsync([FromBody] OAuthDTO AuthDTO)
        {
            Guard.Against.NullItem <OAuthDTO>(AuthDTO);

            JObject responseBody = new JObject();

            ApplicationUser applicationUserRegistered = await _userManager.FindByEmailAsync(AuthDTO.Email);

            ApplicationUser applicationExternalUser = await _userManager.FindByLoginAsync("Google", AuthDTO.ProviderKey);

            //user registered with same email id of Visneto registration
            if (applicationUserRegistered != null && applicationExternalUser == null)
            {
                return(StatusCode(401, new { message = "Already registered with Visneto. Cannot use Google SignIn credentials to login. Please use Visneto credentials to login." }));
            }


            //User is already registered with Visneto and Google
            if (applicationUserRegistered != null && applicationExternalUser != null)
            {
                string access_token = await _tokenManager.GenerateJWTAsync(applicationUserRegistered);

                IList <string> externalLoginUserRolesList = await _userManager.GetRolesAsync(applicationUserRegistered);

                if (externalLoginUserRolesList.Count > 0)
                {
                    responseBody.Add("role", JToken.FromObject(externalLoginUserRolesList[0]));
                }

                else
                {
                    return(StatusCode(401, new { message = $"Unauthorized, no roles for the user specified." }));
                }

                responseBody.Add("access_token", JToken.FromObject(access_token));
                responseBody.Add("expires", JToken.FromObject(3600));
                responseBody.Add("user_name", JToken.FromObject(applicationExternalUser.FirstName));
                responseBody.Add("provider", JToken.FromObject("Google"));
                return(Ok(responseBody));
            }

            //User is not registered with Visneto but Google
            ApplicationUser user = new ApplicationUser
            {
                UserName       = AuthDTO.Email,
                Email          = AuthDTO.Email,
                FirstName      = AuthDTO.DisplayName,
                EmailConfirmed = true
            };

            IdentityResult createUser = await _userManager.CreateAsync(user);

            if (!createUser.Succeeded)
            {
                return(BadRequest(new { message = createUser.GetIdentityResultErrorMessage() }));
            }

            user.ProfileImage = new ProfileImage
            {
                ProfileImageID  = Guid.NewGuid(),
                ProfileImageUrl = AuthDTO.ImageUrl,
                ContainerName   = String.Empty,
                ResourceName    = String.Empty
            };

            await _userManager.AddToRoleAsync(user, UserType.User.ToString());

            await _userManager.AddLoginAsync(user, new UserLoginInfo("Google", AuthDTO.ProviderKey, AuthDTO.DisplayName));

            string token = await _tokenManager.GenerateJWTAsync(user);

            //Generation of referral code
            ReferralCode referralCode = GenerateReferralCode(user.UserName, user.Id);
            await _referralCodeService.AddReferralCode(referralCode);

            //Send Referral code mail now
            EmailModel emailModel = new EmailModel
            {
                EmailTo = user.Email,
                Body    = $"<html><body><fieldset><legend> Referral code for User - {user.UserName} </legend> {referralCode.RefCode} </fieldset></body></html>",
                Subject = $"Visneto Referral Code for new user - {user.UserName}"
            };

            await _emailManager.SendEmailAsync(emailModel);

            responseBody.Add("access_token", JToken.FromObject(token));
            responseBody.Add("expires", JToken.FromObject(3600));
            responseBody.Add("user_name", JToken.FromObject(user.Email));
            responseBody.Add("provider", JToken.FromObject("Google"));
            responseBody.Add("role", JToken.FromObject(UserType.User.ToString()));
            return(StatusCode(201, responseBody));
        }