Пример #1
0
 public ActionResult DoResetPassword(AccountResetPasswordModel viewModel)
 {
     // Ensure we have a valid viewModel to work with
     if (ModelState.IsValid)
     {
         var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == viewModel.Id);
         if (user == null)
         {
             return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
         }
         else if (user.ResetPasswordToken != viewModel.Token)
         {
             return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidToken") }));
         }
         else
         {
             user.ResetPasswordDate  = null;
             user.ResetPasswordToken = null;
             user.Password           = viewModel.Password.ToBCrypt();
             _sysUserService.Update(user);
             _unitOfWork.SaveChanges();
             return(new JsonResult(new
             {
                 success = true,
                 message = $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PasswordResetSuccessfully")} " +
                           $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ClickHereToLogIn")}"
             }));
         }
     }
     return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
 }
Пример #2
0
        public IActionResult DoSend(HomeMessageViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Message.ToString());

                    var messageEmailTemplateViewModel = Mapper.Map <MessageEmailTemplateViewModel>(viewModel);
                    messageEmailTemplateViewModel.NameText                = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Name");
                    messageEmailTemplateViewModel.CheersText              = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                    messageEmailTemplateViewModel.ContactInfoText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                    messageEmailTemplateViewModel.CPLTeamText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "CPLTeam");
                    messageEmailTemplateViewModel.MessageText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Message");
                    messageEmailTemplateViewModel.EmailText               = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                    messageEmailTemplateViewModel.HiText                  = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                    messageEmailTemplateViewModel.MessageFromCustomerText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "MessageFromCustomer");
                    messageEmailTemplateViewModel.PhoneNumberText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PhoneNumber");
                    messageEmailTemplateViewModel.WebsiteText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                    messageEmailTemplateViewModel.RootUrl                 = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                    template.Body = _viewRenderService.RenderToStringAsync("/Views/Home/_MessageEmailTemplate.cshtml", messageEmailTemplateViewModel).Result;
                    EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), CPLConstant.SMTP.Contact);
                    return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "MessageSentSuccessfully") }));
                }
                catch (Exception ex)
                {
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                }
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #3
0
        public IActionResult VerifyPIN(AccountLoginModel viewModel, MobileModel mobileModel)
        {
            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Email == viewModel.Email);
            var tfa  = new TwoFactorAuthenticator()
            {
                DefaultClockDriftTolerance = TimeSpan.FromSeconds(30)
            };
            bool isCorrectPIN = tfa.ValidateTwoFactorPIN($"{CPLConstant.TwoFactorAuthenticationSecretKey}{user.Id}", viewModel.PIN);

            if (isCorrectPIN)
            {
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.SUCCESS,
                    }));
                }
                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                return(RedirectToLocal($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("Index", "Home")}"));
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.WARNING,
                    error_message_key = CPLConstant.MobileAppConstant.LoginScreenInvalidPIN
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidPIN") }));
        }
Пример #4
0
        public IActionResult DoEditEmail(EditEmailViewModel viewModel, MobileModel mobileModel)
        {
            var isEmailExisting = _sysUserService.Queryable().Any(x => x.Email == viewModel.NewEmail && x.IsDeleted == false);

            if (isEmailExisting)
            {
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.WARNING,
                        name = "new-email",
                        error_message_key = CPLConstant.MobileAppConstant.EditEmailScreenExistingEmail
                    }));
                }

                return(new JsonResult(new { success = false, name = "new-email", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExistingEmail") }));
            }

            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            if (user != null)
            {
                user.Email = viewModel.NewEmail;
                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();

                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.SUCCESS,
                        success_message_key = CPLConstant.MobileAppConstant.EditEmailScreenEmailUpdatedSuccessfully
                    }));
                }
                return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "EmailUpdated") }));
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.WARNING,
                    error_message_key = CPLConstant.MobileAppConstant.EditEmailScreenNonExistingAccount
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
        }
Пример #5
0
        public IActionResult Index()
        {
            var user      = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);
            var viewModel = Mapper.Map <ProfileViewModel>(user);

            viewModel.NumberOfGameHistories = _lotteryHistoryService.Queryable().Count(x => x.SysUserId == viewModel.Id && x.Result != EnumGameResult.REFUND.ToString());
            viewModel.NumberOfTransactions  = _coinTransactionService.Queryable().Count(x => x.SysUserId == viewModel.Id);

            // Mapping KYC status
            if (!user.KYCVerified.HasValue)
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotVerifiedYet");
            }
            else if (user.KYCVerified == true)
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Verified");
            }
            else // viewModel.KYCVerified == false
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Pending");
            }

            // Mapping Affiliate status
            if (!user.AffiliateId.HasValue)
            {
                viewModel.AffiliateStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotJoinedYet");
            }
            else if (user.AffiliateId.Value != (int)EnumAffiliateApplicationStatus.PENDING)
            {
                viewModel.AffiliateStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Approved");
            }
            else // viewModel.AffiliateId.Value != (int)EnumAffiliateApplicationStatus.PENDING
            {
                viewModel.AffiliateStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Pending");
            }

            // Mapping TwoFactorAuthenticationEnable status
            if (user.TwoFactorAuthenticationEnable)
            {
                viewModel.TwoFactorAuthenticationEnableStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "IsEnabled");
            }
            else // viewModel.TwoFactorAuthenticationEnable == false
            {
                viewModel.TwoFactorAuthenticationEnableStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "IsNotEnabled");
            }

            return(View(viewModel));
        }
Пример #6
0
 public IActionResult DecodeQR(DecodeQrViewModel viewModel)
 {
     System.DrawingCore.Bitmap bitmap = new System.DrawingCore.Bitmap(viewModel.FormFile.OpenReadStream());
     try
     {
         BarcodeReader reader = new BarcodeReader {
             AutoRotate = true, TryInverted = true
         };
         string qrcode = reader.Decode(bitmap).Text;
         return(new JsonResult(new { success = true, address = qrcode, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "GeneratedQRCodeSuccessfully") }));
     }
     catch (Exception ex)
     {
         return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "GeneratedQRCodeError") }));
     }
 }
Пример #7
0
        public IActionResult DoEdit(ProfileViewModel viewModel, MobileModel mobileModel)
        {
            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            if (user != null)
            {
                user.FirstName     = viewModel.FirstName;
                user.LastName      = viewModel.LastName;
                user.Gender        = viewModel.Gender;
                user.DOB           = viewModel.DOB;
                user.Country       = viewModel.Country;
                user.City          = viewModel.City;
                user.StreetAddress = viewModel.StreetAddress;
                user.Mobile        = viewModel.Mobile;

                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();

                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.SUCCESS,
                        success_message_key = CPLConstant.MobileAppConstant.ProfileEditUserScreenUpdatedSuccessfully
                    }));
                }

                return(new JsonResult(new
                {
                    success = true,
                    message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PersonalInfoUpdated"),
                    gender = viewModel.Gender == true ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Male") : LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Female")
                }));
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.ERROR,
                    error_message_key = CPLConstant.MobileAppConstant.ProfileEditUserScreenNonExistingAccount
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
        }
Пример #8
0
        public IActionResult DoEditPassword(EditPasswordViewModel viewModel, MobileModel mobileModel)
        {
            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            if (user != null)
            {
                if (!BCrypt.Net.BCrypt.Verify(viewModel.CurrentPassword, user.Password))
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.WARNING,
                            error_message_key = CPLConstant.MobileAppConstant.EditPasswordScreenInvalidCurrentPassword
                        }));
                    }
                    return(new JsonResult(new { success = false, name = "current-password", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidCurrentPassword") }));
                }


                user.Password = viewModel.NewPassword.ToBCrypt();
                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();

                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.SUCCESS,
                        success_message_key = CPLConstant.MobileAppConstant.EditPasswordScreenPasswordUpdatedSuccessfully
                    }));
                }
                return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PasswordUpdated") }));
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.WARNING,
                    error_message_key = CPLConstant.MobileAppConstant.EditPasswordScreenNonExistingAccount
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
        }
Пример #9
0
        public ActionResult Resend(AccountResendModel viewModel)
        {
            // Ensure we have a valid viewModel to work with
            if (ModelState.IsValid)
            {
                var user = _sysUserService.Queryable().FirstOrDefault(x => x.Email == viewModel.Email);
                if (user == null)
                {
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
                }

                if (string.IsNullOrEmpty(user.ActivateToken))
                {
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PreviouslyActivated") }));
                }

                user.CreatedDate   = DateTime.Now;
                user.ActivateToken = Guid.NewGuid().ToString();
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();
                var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Activate.ToString());
                var activateEmailTemplateViewModel = Mapper.Map <ActivateEmailTemplateViewModel>(user);
                activateEmailTemplateViewModel.ActivateUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("Activate", "Authentication", new { token = activateEmailTemplateViewModel.ActivateToken, id = activateEmailTemplateViewModel.Id })}";
                activateEmailTemplateViewModel.RootUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                //Populate language
                activateEmailTemplateViewModel.RegistrationSuccessfulText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "RegistrationSuccessful");
                activateEmailTemplateViewModel.HiText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                activateEmailTemplateViewModel.RegisterActivateText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "RegisterActivate");
                activateEmailTemplateViewModel.NotWorkUrlText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotWorkUrl");
                activateEmailTemplateViewModel.CheersText           = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                activateEmailTemplateViewModel.ContactInfoText      = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                activateEmailTemplateViewModel.EmailText            = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                activateEmailTemplateViewModel.WebsiteText          = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                activateEmailTemplateViewModel.ExpiredEmail24hText  = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExpiredEmail24h");
                activateEmailTemplateViewModel.ActivateText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Activate");

                template.Body = _viewRenderService.RenderToStringAsync("/Views/Authentication/_ActivateEmailTemplate.cshtml", activateEmailTemplateViewModel).Result;
                EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), user.Email);

                return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NewActivateCodeSent") }));
            }

            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #10
0
        public IActionResult DoSubmitAffiliate(KYCViewModel viewModel)
        {
            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            if (user != null)
            {
                user.AffiliateId = (int)EnumAffiliateApplicationStatus.PENDING;
                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();

                return(new JsonResult(new
                {
                    success = true,
                    message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "AffiliateApplicationSubmitted")
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
        }
Пример #11
0
        public ActionResult DoForgotPassword(AccountForgotPasswordModel viewModel)
        {
            // Ensure we have a valid viewModel to work with
            if (ModelState.IsValid)
            {
                var user = _sysUserService.Queryable().FirstOrDefault(x => x.Email == viewModel.Email && x.IsDeleted == false);
                if (user == null)
                {
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
                }

                user.ResetPasswordDate  = DateTime.Now;
                user.ResetPasswordToken = Guid.NewGuid().ToString();
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();
                var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.ForgotPassword.ToString());

                var forgotPasswordEmailTemplateViewModel = Mapper.Map <ForgotPasswordEmailTemplateViewModel>(user);
                forgotPasswordEmailTemplateViewModel.ResetPasswordUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("ResetPassword", "Authentication", new { token = forgotPasswordEmailTemplateViewModel.ResetPasswordToken, id = forgotPasswordEmailTemplateViewModel.Id })}";
                forgotPasswordEmailTemplateViewModel.RootUrl          = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                // Populate language
                forgotPasswordEmailTemplateViewModel.ResetYourPasswordText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ResetYourPassword");
                forgotPasswordEmailTemplateViewModel.HiText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                forgotPasswordEmailTemplateViewModel.ResetPasswordRequestText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ResetPasswordRequest");
                forgotPasswordEmailTemplateViewModel.ButtonClickBelowText     = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ButtonClickBelow");
                forgotPasswordEmailTemplateViewModel.NotWorkUrlText           = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotWorkUrl");
                forgotPasswordEmailTemplateViewModel.NotYourRequestText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotYourRequest");
                forgotPasswordEmailTemplateViewModel.CheersText          = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                forgotPasswordEmailTemplateViewModel.ConnectWithUsText   = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ConnectWithUs");
                forgotPasswordEmailTemplateViewModel.ContactInfoText     = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                forgotPasswordEmailTemplateViewModel.EmailText           = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                forgotPasswordEmailTemplateViewModel.WebsiteText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                forgotPasswordEmailTemplateViewModel.ExpiredEmail24hText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExpiredEmail24h");

                template.Body = _viewRenderService.RenderToStringAsync("/Views/Authentication/_ForgotPasswordEmailTemplate.cshtml", forgotPasswordEmailTemplateViewModel).Result;
                EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), user.Email);
                return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ResetPasswordEmailSent") }));
            }

            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #12
0
        public IActionResult Index()
        {
            var user      = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id);
            var viewModel = Mapper.Map <DashboardViewModel>(user);

            // Mapping KYC status
            if (!user.KYCVerified.HasValue)
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotVerifiedYet");
            }
            else if (user.KYCVerified == true)
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Verified");
            }
            else // viewModel.KYCVerified == false
            {
                viewModel.KYCStatus = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Pending");
            }

            return(View(viewModel));
        }
Пример #13
0
        public ActionResult ResetPassword(int id, string token)
        {
            var viewmodel = new AccountResetPasswordModel();
            var user      = _sysUserService.Queryable().FirstOrDefault(x => x.Id == id);

            if (user == null)
            {
                viewmodel.Status  = EnumAccountStatus.REQUEST_NOT_EXIST;
                viewmodel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount");
                return(View(viewmodel));
            }
            else if (user.ResetPasswordDate == null)
            {
                viewmodel.Status  = EnumAccountStatus.REQUEST_NOT_EXIST;
                viewmodel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "RequestNotExist");
                return(View(viewmodel));
            }
            else if (user.ResetPasswordDate.Value.AddDays(int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.ResetPasswordExpiredInDays).Value)) > DateTime.Now)
            {
                if (user.ResetPasswordToken == token)
                {
                    viewmodel.Id    = id;
                    viewmodel.Token = token;
                    return(View(viewmodel));
                }
                else
                {
                    viewmodel.Status  = EnumAccountStatus.INVALID_TOKEN;
                    viewmodel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidToken");
                    return(View(viewmodel));
                }
            }
            else
            {
                viewmodel.Status  = EnumAccountStatus.EXPIRED;
                viewmodel.Message = $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExpiredResetPasswordToken")} {LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ClickHereToAskResetPassword")} ";
                return(View(viewmodel));
            }
        }
Пример #14
0
        public IActionResult DoEditKYC(KYCViewModel viewModel)
        {
            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            if (user != null)
            {
                if (viewModel.FrontSideImage != null && viewModel.BackSideImage != null)
                {
                    user.KYCCreatedDate = DateTime.Now;
                    user.KYCVerified    = false;
                    var    kyc       = Path.Combine(_hostingEnvironment.WebRootPath, @"images\kyc");
                    string timestamp = DateTime.Now.ToString("yyyyMMddhhmmss");

                    // Front Size
                    var frontSide     = $"{viewModel.Id.ToString()}_FS_{timestamp}_{viewModel.FrontSideImage.FileName}";
                    var frontSidePath = Path.Combine(kyc, frontSide);
                    viewModel.FrontSideImage.CopyTo(new FileStream(frontSidePath, FileMode.Create));
                    user.FrontSide = frontSide;

                    // Back Size
                    var backSide     = $"{viewModel.Id.ToString()}_BS_{timestamp}_{viewModel.BackSideImage.FileName}";
                    var backSidePath = Path.Combine(kyc, backSide);
                    viewModel.BackSideImage.CopyTo(new FileStream(backSidePath, FileMode.Create));
                    user.BackSide = backSide;
                }

                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();

                return(new JsonResult(new
                {
                    success = true,
                    message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "KYCSubmitted")
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") }));
        }
Пример #15
0
        public IActionResult DoEditTwoFactorAuthentication(bool value, string pin)
        {
            if (value)
            {
                var userId = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id;
                var tfa    = new TwoFactorAuthenticator()
                {
                    DefaultClockDriftTolerance = TimeSpan.FromSeconds(30)
                };
                bool isCorrectPIN = tfa.ValidateTwoFactorPIN($"{CPLConstant.TwoFactorAuthenticationSecretKey}{userId}", pin);

                if (isCorrectPIN)
                {
                    var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == userId);
                    user.TwoFactorAuthenticationEnable = value;
                    HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                    _sysUserService.Update(user);
                    _unitOfWork.SaveChanges();
                    return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "TwoFactorAuthenticationUpdated") }));
                }
                else
                {
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidPIN") }));
                }
            }
            else
            {
                var userId = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id;
                var user   = _sysUserService.Queryable().FirstOrDefault(x => x.Id == userId);
                user.TwoFactorAuthenticationEnable = value;
                HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                _sysUserService.Update(user);
                _unitOfWork.SaveChanges();
                return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "TwoFactorAuthenticationUpdated") }));
            }
        }
Пример #16
0
        public IViewComponentResult Invoke(PricePredictionViewComponentViewModel viewModel)
        {
            var tokenAmount    = viewModel.TokenAmount;
            var predictedTrend = viewModel.PredictedTrend;
            var isDisabled     = viewModel.IsDisabled;
            var coinBase       = viewModel.Coinbase;

            viewModel = _pricePredictionService.Queryable().Where(x => x.Id == viewModel.Id)
                        .Select(x => Mapper.Map <PricePredictionViewComponentViewModel>(x)).FirstOrDefault();
            viewModel.TokenAmount    = tokenAmount;
            viewModel.PredictedTrend = predictedTrend;
            viewModel.IsDisabled     = isDisabled;
            viewModel.BTCPricePredictionChartTitle = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionChartTitle") : ""; // TODO: Add more chart title if there are more coinbases
            viewModel.BTCPricePredictionSeriesName = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionSeriesName") : ""; // TODO: Add more chart title if there are more coinbases

            //Calculate percentage
            decimal highPrediction = _pricePredictionHistoryService
                                     .Queryable()
                                     .Where(x => x.PricePredictionId == viewModel.Id && x.Prediction == EnumPricePredictionStatus.HIGH.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                     .Count();

            decimal lowPrediction = _pricePredictionHistoryService
                                    .Queryable()
                                    .Where(x => x.PricePredictionId == viewModel.Id && x.Prediction == EnumPricePredictionStatus.LOW.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                    .Count();


            if (highPrediction + lowPrediction == 0)
            {
                viewModel.HighPercentage = viewModel.LowPercentage = 50;
            }
            else
            {
                viewModel.HighPercentage = Math.Round((highPrediction / (highPrediction + lowPrediction) * 100), 2);
                viewModel.LowPercentage  = 100 - viewModel.HighPercentage;
            }
            //////////////////////////

            var btcCurrentPriceResult = ServiceClient.BTCCurrentPriceClient.GetBTCCurrentPriceAsync();

            btcCurrentPriceResult.Wait();
            if (btcCurrentPriceResult.Result.Status.Code == 0)
            {
                viewModel.CurrentBTCRate         = btcCurrentPriceResult.Result.Price;
                viewModel.CurrentBTCRateInString = btcCurrentPriceResult.Result.Price.ToString("#,##0.00");
            }

            // Get btc previous rates 12h before until now
            var btcPriceInUTC = _btcPriceService.Queryable()
                                .Where(x => x.Time >= viewModel.OpenBettingTime.AddHours(-CPLConstant.HourBeforeInChart).ToUTCUnixTimeInSeconds())
                                .ToList();
            var lowestRate = btcPriceInUTC.Min(x => x.Price) - CPLConstant.LowestRateBTCInterval;

            if (lowestRate < 0)
            {
                lowestRate = 0;
            }
            viewModel.PreviousBtcRate = JsonConvert.SerializeObject(btcPriceInUTC);
            viewModel.LowestBtcRate   = lowestRate;
            return(View(viewModel));
        }
Пример #17
0
        public ActionResult Register(int?id, string token)
        {
            ClearSession();

            var viewModel   = new AccountRegistrationModel();
            var gcaptchaKey = _settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.GCaptchaKey)?.Value;

            viewModel.GCaptchaKey = gcaptchaKey;

            var affiliateCookieExpirations = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.CookieExpirations).Value);
            var affiliateCookie            = Request.Cookies["AffiliateCookie"];
            var agencyTokenCookie          = Request.Cookies["AgencyTokenCookie"];

            if (!string.IsNullOrEmpty(token))
            {
                var agencyToken = _agencyTokenService.Queryable().FirstOrDefault(x => x.Token == token && x.ExpiredDate >= DateTime.Now && !x.SysUserId.HasValue);
                if (agencyToken != null)
                {
                    if (MobileHelper.IsMobile(HttpContext))
                    {
                        return(Redirect("cryptoodds://SetAgencyToken/" + token + "/" + (affiliateCookieExpirations * 60 * 24)));
                    }
                    viewModel.AgencyToken = token;
                    CookieHelper.SetCookies(Response, "AgencyTokenCookie", token, affiliateCookieExpirations * 60 * 24);
                    viewModel.IsRedirected = true;
                }
                else
                {
                    viewModel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidOrExpiredAgencyToken");
                }
            }
            else if (!string.IsNullOrEmpty(agencyTokenCookie))
            {
                viewModel.AgencyToken = agencyTokenCookie;
            }

            // Update id using cookie
            if (id.HasValue)
            {
                if (MobileHelper.IsMobile(HttpContext))
                {
                    return(Redirect("cryptoodds://SetIntroductionId/" + id.Value.ToString() + "/" + (affiliateCookieExpirations * 60 * 24)));
                }
                CookieHelper.SetCookies(Response, "AffiliateCookie", id.Value.ToString(), affiliateCookieExpirations * 60 * 24);
                viewModel.IsRedirected = true;
            }
            else if (!string.IsNullOrEmpty(affiliateCookie))
            {
                id = int.Parse(affiliateCookie);
            }

            // Verify id again
            if (id.HasValue)
            {
                var introducedByUser           = _sysUserService.Queryable().FirstOrDefault(x => x.Id == id.Value);
                var isKYCVerificationActivated = bool.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.IsKYCVerificationActivated).Value);
                if (introducedByUser != null &&
                    !introducedByUser.IsAdmin &&
                    (!isKYCVerificationActivated || (introducedByUser.KYCVerified.HasValue && introducedByUser.KYCVerified.Value)))
                {
                    viewModel.IsIntroducedById = id.Value;
                }
            }

            if (viewModel.IsRedirected)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(viewModel));
            }
        }
Пример #18
0
        public IActionResult DoRegister(AccountRegistrationModel viewModel, MobileModel mobileModel)
        {
            // Ensure we have a valid viewModel to work with
            if (ModelState.IsValid)
            {
                if (_sysUserService.Queryable().Any(x => x.Email == viewModel.Email && x.IsDeleted == false))
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.WARNING,
                            error_message_key = CPLConstant.MobileAppConstant.RegisterScreenInputEmailExist
                        }));
                    }
                    return(new JsonResult(new { success = false, name = "email", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExistingEmail") }));
                }

                var    agencyToken = _agencyTokenService.Queryable().FirstOrDefault(x => x.Token == viewModel.AgencyToken && x.ExpiredDate >= DateTime.Now && !x.SysUserId.HasValue);
                Agency agency      = null;
                if (agencyToken != null)
                {
                    agency = new Agency
                    {
                        Tier1DirectRate      = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier1DirectRate).Value),
                        Tier2DirectRate      = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier2DirectRate).Value),
                        Tier3DirectRate      = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier3DirectRate).Value),
                        Tier2SaleToTier1Rate = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier2SaleToTier1Rate).Value),
                        Tier3SaleToTier1Rate = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier3SaleToTier1Rate).Value),
                        Tier3SaleToTier2Rate = int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.AgencyAffiliate.Tier3SaleToTier2Rate).Value)
                    };

                    _agencyService.Insert(agency);
                    _unitOfWork.SaveChanges();
                }


                var isAccountActivationEnable = bool.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.IsAccountActivationEnable).Value);
                var latestAddressIndex        = _sysUserService.Queryable().LastOrDefault()?.ETHHDWalletAddressIndex ?? 0;
                // Try to create a user with the given identity
                SysUser user = null;
                if (viewModel.IsIntroducedById.HasValue)
                {
                    var fatherUser           = _sysUserService.Queryable().FirstOrDefault(x => x.Id == viewModel.IsIntroducedById);
                    var grandFatherUser      = _sysUserService.Queryable().FirstOrDefault(x => fatherUser != null && x.Id == fatherUser.IsIntroducedById);
                    var grandGrandFatherUser = _sysUserService.Queryable().FirstOrDefault(x => grandFatherUser != null && x.Id == grandFatherUser.IsIntroducedById);

                    if (grandGrandFatherUser == null && fatherUser.AgencyId.HasValue)
                    {
                        user = new SysUser
                        {
                            Email            = viewModel.Email,
                            Password         = viewModel.Password.ToBCrypt(),
                            CreatedDate      = DateTime.Now,
                            IsAdmin          = false,
                            ActivateToken    = isAccountActivationEnable ? Guid.NewGuid().ToString() : null,
                            IsIntroducedById = viewModel.IsIntroducedById,
                            AgencyId         = fatherUser.AgencyId,
                            BTCAmount        = 0,
                            ETHAmount        = 0,
                            TokenAmount      = 0,
                            IsLocked         = false
                        };
                    }
                    else
                    {
                        user = new SysUser
                        {
                            Email            = viewModel.Email,
                            Password         = viewModel.Password.ToBCrypt(),
                            CreatedDate      = DateTime.Now,
                            IsAdmin          = false,
                            ActivateToken    = isAccountActivationEnable ? Guid.NewGuid().ToString() : null,
                            IsIntroducedById = viewModel.IsIntroducedById,
                            AgencyId         = null,
                            BTCAmount        = 0,
                            ETHAmount        = 0,
                            TokenAmount      = 0,
                            IsLocked         = false
                        };
                    }
                }
                else
                {
                    user = new SysUser
                    {
                        Email            = viewModel.Email,
                        Password         = viewModel.Password.ToBCrypt(),
                        CreatedDate      = DateTime.Now,
                        IsAdmin          = false,
                        ActivateToken    = isAccountActivationEnable ? Guid.NewGuid().ToString() : null,
                        IsIntroducedById = viewModel.IsIntroducedById,
                        AgencyId         = agency == null ? null : (int?)agency.Id,
                        BTCAmount        = 0,
                        ETHAmount        = 0,
                        TokenAmount      = 0,
                        IsLocked         = false
                    };
                }

                try
                {
                    var requestCount = 0;
                    var isETHHDWalletAddressGenerated = false;
                    var isBTCHDWalletAddressGenerated = false;
                    while (requestCount < CPLConstant.RequestCountLimit)
                    {
                        // Populate ETH HD Wallet Address
                        if (!isETHHDWalletAddressGenerated)
                        {
                            var eWallet = new EWalletService.EWalletClient().GetAccountAsync(Authentication.Token, CPLConstant.ETHMnemonic, latestAddressIndex + 1);
                            eWallet.Wait();

                            if (eWallet.Result.Status.Code == 0) //OK
                            {
                                user.ETHHDWalletAddress       = eWallet.Result.Address;
                                user.ETHHDWalletAddressIndex  = latestAddressIndex + 1;
                                isETHHDWalletAddressGenerated = true;
                            }
                        }

                        // Populate BTC HD Wallet Address
                        if (!isBTCHDWalletAddressGenerated)
                        {
                            var bWallet = new BWalletService.BWalletClient().GetAccountAsync(Authentication.Token, CPLConstant.BTCMnemonic, latestAddressIndex + 1);
                            bWallet.Wait();

                            if (bWallet.Result.Status.Code == 0) //OK
                            {
                                user.BTCHDWalletAddress       = bWallet.Result.Address;
                                user.BTCHDWalletAddressIndex  = latestAddressIndex + 1;
                                isBTCHDWalletAddressGenerated = true;
                            }
                        }

                        if (isETHHDWalletAddressGenerated && isBTCHDWalletAddressGenerated)
                        {
                            break;
                        }
                        else
                        {
                            requestCount++;
                            Thread.Sleep(CPLConstant.RequestCountIntervalInMiliseconds);
                        }
                    }

                    if (requestCount == CPLConstant.RequestCountLimit)
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                            }));
                        }
                        return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                    }
                }
                catch (Exception ex)
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.ERROR,
                            error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs,
                            error_message = ex.Message
                        }));
                    }
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                }

                _sysUserService.Insert(user);
                _unitOfWork.SaveChanges();


                if (agencyToken != null && !user.IsIntroducedById.HasValue)
                {
                    agencyToken.SysUserId = user.Id;
                    _agencyTokenService.Update(agencyToken);
                    _unitOfWork.SaveChanges();
                }

                if (isAccountActivationEnable)
                {
                    var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Activate.ToString());
                    var activateEmailTemplateViewModel = Mapper.Map <ActivateEmailTemplateViewModel>(user);
                    activateEmailTemplateViewModel.ActivateUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("Activate", "Authentication", new { token = activateEmailTemplateViewModel.ActivateToken, id = activateEmailTemplateViewModel.Id })}";
                    activateEmailTemplateViewModel.RootUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                    //Populate language
                    activateEmailTemplateViewModel.RegistrationSuccessfulText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "RegistrationSuccessful");
                    activateEmailTemplateViewModel.HiText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                    activateEmailTemplateViewModel.RegisterActivateText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "RegisterActivate");
                    activateEmailTemplateViewModel.NotWorkUrlText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotWorkUrl");
                    activateEmailTemplateViewModel.CheersText           = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                    activateEmailTemplateViewModel.ContactInfoText      = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                    activateEmailTemplateViewModel.EmailText            = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                    activateEmailTemplateViewModel.WebsiteText          = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                    activateEmailTemplateViewModel.ExpiredEmail24hText  = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExpiredEmail24h");
                    activateEmailTemplateViewModel.ActivateText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Activate");

                    template.Body = _viewRenderService.RenderToStringAsync("/Views/Authentication/_ActivateEmailTemplate.cshtml", activateEmailTemplateViewModel).Result;
                    EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), user.Email);

                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.SUCCESS,
                            activation = 1
                        }));
                    }

                    CookieHelper.RemoveCookies(Response, "AffiliateCookie");
                    CookieHelper.RemoveCookies(Response, "AgencyTokenCookie");

                    return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ActivateEmailSent") }));
                }
                else
                {
                    var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Member.ToString());
                    var memberEmailTemplateViewModel = Mapper.Map <MemberEmailTemplateViewModel>(user);
                    memberEmailTemplateViewModel.RootUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                    // Populate language
                    memberEmailTemplateViewModel.ActivationSuccessfulText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ActivationSuccessful");
                    memberEmailTemplateViewModel.HiText            = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                    memberEmailTemplateViewModel.TeamMemberNowText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "TeamMemberNow");
                    memberEmailTemplateViewModel.PlayGameNowText   = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PlayGameNow");
                    memberEmailTemplateViewModel.CheersText        = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                    memberEmailTemplateViewModel.ContactInfoText   = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                    memberEmailTemplateViewModel.EmailText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                    memberEmailTemplateViewModel.WebsiteText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                    memberEmailTemplateViewModel.CPLTeamText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "CPLTeam");

                    template.Body = _viewRenderService.RenderToStringAsync("/Views/Authentication/_MemberEmailTemplate.cshtml", memberEmailTemplateViewModel).Result;
                    EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), user.Email);

                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.SUCCESS,
                            activation = 0
                        }));
                    }

                    CookieHelper.RemoveCookies(Response, "AffiliateCookie");
                    CookieHelper.RemoveCookies(Response, "AgencyTokenCookie");

                    // Log in
                    HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                    return(new JsonResult(new { success = true, activated = true, url = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("Index", "Home")}" }));
                }
            }
            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.ERROR,
                    error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #19
0
        public ActionResult Activate(int id, string token)
        {
            var viewmodel = new AccountActivateModel();
            var user      = _sysUserService.Queryable().FirstOrDefault(x => x.Id == id && x.IsDeleted == false);

            if (user == null)
            {
                viewmodel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount");
            }
            else if (string.IsNullOrEmpty(user.ActivateToken))
            {
                viewmodel.Message = $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PreviouslyActivated")} {LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ClickHereToReturnToTopPage")}";
            }
            else if (user.CreatedDate.AddDays(int.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.ActivateExpiredInDays).Value)) > DateTime.Now)
            {
                if (user.ActivateToken == token)
                {
                    user.ActivateToken = null;
                    _sysUserService.Update(user);
                    _unitOfWork.SaveChanges();

                    var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Member.ToString());
                    var memberEmailTemplateViewModel = Mapper.Map <MemberEmailTemplateViewModel>(user);
                    memberEmailTemplateViewModel.RootUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                    // Populate language
                    memberEmailTemplateViewModel.ActivationSuccessfulText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ActivationSuccessful");
                    memberEmailTemplateViewModel.HiText            = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                    memberEmailTemplateViewModel.TeamMemberNowText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "TeamMemberNow");
                    memberEmailTemplateViewModel.PlayGameNowText   = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PlayGameNow");
                    memberEmailTemplateViewModel.CheersText        = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                    memberEmailTemplateViewModel.ContactInfoText   = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                    memberEmailTemplateViewModel.EmailText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                    memberEmailTemplateViewModel.WebsiteText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                    memberEmailTemplateViewModel.CPLTeamText       = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "CPLTeam");

                    template.Body = _viewRenderService.RenderToStringAsync("/Views/Authentication/_MemberEmailTemplate.cshtml", memberEmailTemplateViewModel).Result;
                    EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), user.Email);

                    if (MobileHelper.IsMobile(HttpContext))
                    {
                        return(Redirect("cryptoodds://Activated"));
                    }

                    // Log in
                    user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == id);

                    HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                    viewmodel.Message = $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "AccountIsActivated")} {LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ClickHereToReturnToTopPage")}";
                }
                else
                {
                    viewmodel.Message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidToken");
                }
            }
            else
            {
                viewmodel.Message = $"{LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExpiredActivateToken")} {LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ClickHereToRequestNewActivateToken")}";
            }
            return(View(viewmodel));
        }
Пример #20
0
        public IActionResult Login(AccountLoginModel viewModel, MobileModel mobileModel)
        {
            if (ModelState.IsValid)
            {
                var user = _sysUserService.Queryable().FirstOrDefault(x => x.Email == viewModel.Email && x.IsDeleted == false);

                if (user != null && BCrypt.Net.BCrypt.Verify(viewModel.Password, user.Password))
                {
                    if (!string.IsNullOrEmpty(user.ActivateToken))
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                error_message_key = CPLConstant.MobileAppConstant.LoginScreenInactivatingAccount
                            }));
                        }
                        return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "EmailInactivatingAccount") }));
                    }
                    else
                    {
                        if (user.TwoFactorAuthenticationEnable)
                        {
                            if (mobileModel.IsMobile)
                            {
                                return(new JsonResult(new
                                {
                                    code = EnumResponseStatus.SUCCESS,
                                    two_factor = 1,
                                    data = Mapper.Map <SysUserViewModel>(user)
                                }));
                            }
                            return(new JsonResult(new { success = true, twofactor = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "WaitingPIN") }));
                        }
                        else
                        {
                            if (mobileModel.IsMobile)
                            {
                                return(new JsonResult(new
                                {
                                    code = EnumResponseStatus.SUCCESS,
                                    two_factor = 0,
                                    data = Mapper.Map <SysUserViewModel>(user)
                                }));
                            }
                            HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user));
                            return(viewModel.ReturnUrl == null?RedirectToLocal($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("Index", "Home")}") : RedirectToLocal($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{viewModel.ReturnUrl}"));
                        }
                    }
                }
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.WARNING,
                        error_message_key = CPLConstant.MobileAppConstant.LoginScreenInvalidEmailPassword
                    }));
                }
                return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidEmailPassword") }));
            }
            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.ERROR,
                    error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #21
0
        public IActionResult ConfirmPurchaseTicket(LotteryTicketPurchaseViewModel viewModel, MobileModel mobileModel)
        {
            var user = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser");

            if (user == null && !mobileModel.IsMobile)
            {
                var loginViewModel = new AccountLoginModel();

                var gcaptchaKey = _settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.GCaptchaKey)?.Value;
                loginViewModel.GCaptchaKey = gcaptchaKey;
                return(PartialView("_Login", loginViewModel));
            }
            else
            {
                try
                {
                    int userId;
                    if (mobileModel.IsMobile)
                    {
                        if (mobileModel.MobileUserId.HasValue)
                        {
                            userId = mobileModel.MobileUserId.Value;
                        }
                        else
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.ERROR,
                                error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                            }));
                        }
                    }
                    else
                    {
                        userId = user.Id;
                    }

                    var userEntity = _sysUserService.Queryable().FirstOrDefault(x => x.Id == userId);

                    var lotteryId = viewModel.LotteryId;

                    var lotteryRecordList = _lotteryHistoryService.Queryable().Where(x => x.LotteryId == lotteryId.Value && x.Result != EnumGameResult.REFUND.ToString()).ToList();
                    var lastTicketIndex   = 0;

                    if (lotteryRecordList.Count > 0)
                    {
                        lastTicketIndex = _lotteryHistoryService.Queryable().Where(x => x.LotteryId == lotteryId.Value && x.Result != EnumGameResult.REFUND.ToString()).Max(x => x.TicketIndex);
                    }

                    var unitPrice = _lotteryService.Queryable().FirstOrDefault(x => !x.IsDeleted && x.Id == lotteryId.Value).UnitPrice;

                    var totalPriceOfTickets = viewModel.TotalTickets * unitPrice;

                    var currentLottery = _lotteryService.Queryable().FirstOrDefault(x => !x.IsDeleted && x.Id == lotteryId);

                    if (viewModel.TotalTickets <= currentLottery.Volume - lotteryRecordList.Count())
                    {
                        if (totalPriceOfTickets <= userEntity.TokenAmount)
                        {
                            /// Example paramsInJson: {"1":{"uint32":"4"},"2":{"address":"0xB43eA1802458754A122d02418Fe71326030C6412"}, "3": {"uint32[]":"[1, 2, 3]"}}
                            var userAddress     = userEntity.ETHHDWalletAddress;
                            var ticketIndexList = new List <int> [viewModel.TotalTickets / 10 + 1];
                            var lotteryPhase    = _lotteryService.Queryable().FirstOrDefault(x => !x.IsDeleted && x.Id == lotteryId).Phase;

                            var listIndex = 0;
                            ticketIndexList[listIndex] = new List <int>();

                            for (int i = 0; i < viewModel.TotalTickets; i++)
                            {
                                if (i % 10 == 0 && i != 0)
                                {
                                    listIndex++;
                                    ticketIndexList[listIndex] = new List <int>();
                                }
                                lastTicketIndex += 1;
                                ticketIndexList[listIndex].Add(lastTicketIndex);
                            }

                            var totalOfTicketSuccessful = 0;

                            var buyTime = DateTime.Now;
                            foreach (var ticket in ticketIndexList)
                            {
                                if (ticket == null)
                                {
                                    continue;
                                }

                                var paramJson = string.Format(CPLConstant.RandomParamInJson, lotteryPhase, userAddress, string.Join(",", ticket.ToArray()));

                                var ticketGenResult = ServiceClient.ETokenClient.CallTransactionAsync(Authentication.Token, CPLConstant.OwnerAddress, CPLConstant.OwnerPassword, "random", CPLConstant.GasPriceMultiplicator, CPLConstant.DurationInSecond, paramJson);
                                ticketGenResult.Wait();

                                if (ticketGenResult.Result.Status.Code == 0)
                                {
                                    for (int i = 0; i < ticket.Count; i++)
                                    {
                                        var lotteryRecord = new LotteryHistory
                                        {
                                            CreatedDate = buyTime,
                                            LotteryId   = lotteryId.Value,
                                            SysUserId   = userEntity.Id,
                                            TicketIndex = ticket[i],
                                            TxHashId    = ticketGenResult.Result.TxId
                                        };

                                        _lotteryHistoryService.Insert(lotteryRecord);
                                        totalOfTicketSuccessful++;
                                    }
                                }
                            }
                            userEntity.TokenAmount -= totalOfTicketSuccessful * unitPrice;
                            _sysUserService.Update(userEntity);

                            _unitOfWork.SaveChanges();

                            if (mobileModel.IsMobile)
                            {
                                return(new JsonResult(new
                                {
                                    code = EnumResponseStatus.SUCCESS
                                }));
                            }

                            return(new JsonResult(new { success = true,
                                                        token = userEntity.TokenAmount.ToString("N0"),
                                                        hintThankyou = string.Format(LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "HintThankYouLottery1"), totalOfTicketSuccessful),
                                                        message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "PurchaseSuccessfully") }));
                        }
                        else
                        {
                            if (mobileModel.IsMobile)
                            {
                                return(new JsonResult(new
                                {
                                    code = EnumResponseStatus.WARNING,
                                    error_message_key = CPLConstant.MobileAppConstant.LotteryDetailNotEnoughCPL
                                }));
                            }

                            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NotEnoughCPL") }));
                        }
                    }
                    else
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                error_message_key = CPLConstant.MobileAppConstant.LotteryDetailNoTicketsLeft
                            }));
                        }

                        return(new JsonResult(new { success = false, message = string.Format(LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NoTicketsLeft"), currentLottery.Volume - lotteryRecordList.Count()) }));
                    }
                }
                catch (Exception ex)
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.ERROR,
                            error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs,
                            error_message = ex.Message
                        }));
                    }
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                }
            }
        }
Пример #22
0
        public IActionResult DoSend(ContactIndexViewModel viewModel, MobileModel mobileModel)
        {
            // Ensure we have a valid viewModel to work with
            if (ModelState.IsValid)
            {
                try
                {
                    var contact = Mapper.Map <Contact>(viewModel);
                    contact.CreatedDate = DateTime.Now;
                    _contactService.Insert(contact);
                    _unitOfWork.SaveChanges();
                    var template = _templateService.Queryable().FirstOrDefault(x => x.Name == EnumTemplate.Contact.ToString());

                    var contactEmailTemplateViewModel = Mapper.Map <ContactEmailTemplateViewModel>(viewModel);
                    contactEmailTemplateViewModel.CategoryName            = ((EnumContactCategory)viewModel.Category).ToString();
                    contactEmailTemplateViewModel.CategoryText            = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Category");
                    contactEmailTemplateViewModel.CheersText              = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Cheers");
                    contactEmailTemplateViewModel.ContactInfoText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ContactInfo");
                    contactEmailTemplateViewModel.CPLTeamText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "CPLTeam");
                    contactEmailTemplateViewModel.DescriptionText         = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Description");
                    contactEmailTemplateViewModel.EmailText               = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Email");
                    contactEmailTemplateViewModel.HiText                  = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Hi");
                    contactEmailTemplateViewModel.MessageFromCustomerText = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "MessageFromCustomer");
                    contactEmailTemplateViewModel.SubjectText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Subject");
                    contactEmailTemplateViewModel.WebsiteText             = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "Website");
                    contactEmailTemplateViewModel.RootUrl                 = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

                    template.Body    = _viewRenderService.RenderToStringAsync("/Views/Contact/_ContactEmailTemplate.cshtml", contactEmailTemplateViewModel).Result;
                    template.Subject = string.Format(template.Subject, contact.Id);
                    EmailHelper.Send(Mapper.Map <TemplateViewModel>(template), CPLConstant.SMTP.Contact);

                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.SUCCESS,
                            success_message_key = CPLConstant.MobileAppConstant.ContactScreenEmailSentSuccessfully
                        }));
                    }
                    return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "MessageSentSuccessfully") }));
                }
                catch (Exception ex)
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.ERROR,
                            error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs,
                            error_message = ex.Message
                        }));
                    }
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                }
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.ERROR,
                    error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                }));
            }
            return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
        }
Пример #23
0
        public IActionResult ConfirmPrediction(int pricePredictionId, decimal betAmount, bool predictedTrend)
        {
            var user            = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser");
            var pricePrediction = _pricePredictionService.Queryable().FirstOrDefault(x => x.Id == pricePredictionId);

            if (DateTime.Now > pricePrediction.CloseBettingTime)
            {
                return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "OverBettingTime") }));
            }
            else
            {
                if (user != null)
                {
                    var currentUser = _sysUserService.Queryable().FirstOrDefault(x => x.Id == user.Id);
                    if (betAmount < currentUser.TokenAmount)
                    {
                        var predictionRecord = new PricePredictionHistory()
                        {
                            PricePredictionId = pricePredictionId, Amount = betAmount, CreatedDate = DateTime.Now, Prediction = predictedTrend, SysUserId = user.Id
                        };
                        _pricePredictionHistoryService.Insert(predictionRecord);

                        currentUser.TokenAmount -= betAmount;
                        _sysUserService.Update(currentUser);

                        _unitOfWork.SaveChanges();

                        decimal highPercentage;
                        decimal lowPercentage;
                        //Calculate percentage
                        decimal highPrediction = _pricePredictionHistoryService
                                                 .Queryable()
                                                 .Where(x => x.PricePredictionId == pricePredictionId && x.Prediction == EnumPricePredictionStatus.HIGH.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                                 .Count();

                        decimal lowPrediction = _pricePredictionHistoryService
                                                .Queryable()
                                                .Where(x => x.PricePredictionId == pricePredictionId && x.Prediction == EnumPricePredictionStatus.LOW.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                                .Count();


                        if (highPrediction + lowPrediction == 0)
                        {
                            highPercentage = lowPercentage = 50;
                        }
                        else
                        {
                            highPercentage = Math.Round((highPrediction / (highPrediction + lowPrediction) * 100), 2);
                            lowPercentage  = 100 - highPercentage;
                        }
                        //////////////////////////


                        _progressHubContext.Clients.All.SendAsync("predictedUserProgress", highPercentage, lowPercentage, pricePredictionId);


                        return(new JsonResult(new { success = true, token = currentUser.TokenAmount.ToString("N0"), message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BettingSuccessfully") }));
                    }
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InsufficientFunds") }));
                }
                return(new JsonResult(new
                {
                    success = true,
                    url = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("LogIn", "Authentication")}?returnUrl={Url.Action("Index", "PricePrediction")}"
                }));
            }
        }
Пример #24
0
        public IActionResult DoWithdraw(WithdrawViewModel viewModel, MobileModel mobileModel)
        {
            if (viewModel.Amount <= 0)
            {
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.WARNING,
                        name = "amount",
                        error_message_key = CPLConstant.MobileAppConstant.DepositAndWithdrawScreenInvalidWithdrawAmount
                    }));
                }
                return(new JsonResult(new { success = false, name = "amount", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidWithdrawAmount") }));
            }

            var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false);

            var txHashId = "";

            if (string.IsNullOrEmpty(user.FirstName) || string.IsNullOrEmpty(user.LastName) ||
                !user.DOB.HasValue || string.IsNullOrEmpty(user.Country) || string.IsNullOrEmpty(user.City) || string.IsNullOrEmpty(user.StreetAddress) ||
                string.IsNullOrEmpty(user.Mobile))

            {
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.WARNING,
                        require_profile = true
                    }));
                }

                return(new JsonResult(new
                {
                    success = false,
                    requireProfile = false
                }));
            }


            if (user.KYCVerified == null || !user.KYCVerified.Value)
            {
                if (mobileModel.IsMobile)
                {
                    return(new JsonResult(new
                    {
                        code = EnumResponseStatus.WARNING,
                        require_kyc = true
                    }));
                }

                return(new JsonResult(new
                {
                    success = false,
                    requireKyc = false
                }));
            }

            if (viewModel.Currency == EnumCurrency.BTC.ToString())
            {
                try
                {
                    // Validate max BTC Amount
                    var btcToTokenRate     = decimal.Parse(_settingService.Queryable().FirstOrDefault(x => x.Name == CPLConstant.BTCToTokenRate).Value);
                    var availableBTCAmount = user.TokenAmount / btcToTokenRate;

                    if (viewModel.Amount > availableBTCAmount)
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                name = "amount",
                                error_message_key = CPLConstant.MobileAppConstant.DepositAndWithdrawScreenInsufficientFunds
                            }));
                        }
                        return(new JsonResult(new { success = false, name = "amount", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InsufficientFunds") }));
                    }

                    //Validate BTC wallet address
                    if (string.IsNullOrEmpty(viewModel.Address) || (!string.IsNullOrEmpty(viewModel.Address) && !ValidateAddressHelper.IsValidBTCAddress(viewModel.Address)))
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                name = "wallet",
                                error_message_key = CPLConstant.MobileAppConstant.DepositAndWithdrawScreenInvalidBTCAddress
                            }));
                        }
                        return(new JsonResult(new { success = false, name = "wallet", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "InvalidBTCAddress") }));
                    }

                    // Transfer
                    var txHashIdTask = ServiceClient.BAccountClient.TransferAsync(Authentication.Token, CPLConstant.BTCWithdrawPrivateKey, viewModel.Address, viewModel.Amount);
                    txHashIdTask.Wait();
                    txHashId = txHashIdTask.Result.TxId;

                    // Save to DB
                    if (txHashId != null)
                    {
                        _coinTransactionService.Insert(new CoinTransaction()
                        {
                            SysUserId         = user.Id,
                            FromWalletAddress = CPLConstant.BTCWithdrawAddress,
                            ToWalletAddress   = viewModel.Address,
                            CoinAmount        = viewModel.Amount,
                            CreatedDate       = DateTime.Now,
                            CurrencyId        = (int)EnumCurrency.BTC,
                            Status            = EnumCoinTransactionStatus.PENDING.ToBoolean(),
                            TxHashId          = txHashId,
                            Type = (int)EnumCoinTransactionType.WITHDRAW_BTC
                        });

                        user.TokenAmount -= viewModel.Amount * btcToTokenRate;
                        _sysUserService.Update(user);
                        _unitOfWork.SaveChanges();
                    }
                    else
                    {
                        if (mobileModel.IsMobile)
                        {
                            return(new JsonResult(new
                            {
                                code = EnumResponseStatus.WARNING,
                                error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                            }));
                        }

                        return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                    }
                }
                catch (Exception ex)
                {
                    if (mobileModel.IsMobile)
                    {
                        return(new JsonResult(new
                        {
                            code = EnumResponseStatus.WARNING,
                            error_message_key = CPLConstant.MobileAppConstant.CommonErrorOccurs
                        }));
                    }
                    return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ErrorOccurs") }));
                }
            }

            if (mobileModel.IsMobile)
            {
                return(new JsonResult(new
                {
                    code = EnumResponseStatus.SUCCESS,
                    success_message_key = CPLConstant.MobileAppConstant.DepositAndWithdrawScreenWithdrawedSuccessfully,
                    token = user.TokenAmount,
                    profile_kyc = true,
                    txhashid = txHashId
                }));
            }
            return(new JsonResult(new { success = true, token = user.TokenAmount.ToString("N0"), profileKyc = true, txhashid = txHashId, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "WithdrawedSuccessfully") }));
        }
Пример #25
0
        public IActionResult GetPricePredictionViewComponent(int id, bool isDisabled, string coinBase)
        {
            var viewModel = new PricePredictionViewComponentViewModel();

            viewModel.Id         = id;
            viewModel.IsDisabled = isDisabled;
            viewModel.SysUserId  = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser")?.Id;
            viewModel.Coinbase   = coinBase;
            viewModel.BTCPricePredictionChartTitle = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionChartTitle") : ""; // TODO: Add more chart title if there are more coinbases
            viewModel.BTCPricePredictionSeriesName = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionSeriesName") : ""; // TODO: Add more chart title if there are more coinbases
            if (viewModel.SysUserId.HasValue)
            {
                viewModel.TokenAmount = _sysUserService.Queryable().FirstOrDefault(x => x.Id == viewModel.SysUserId).TokenAmount;
            }
            return(ViewComponent("PricePrediction", viewModel));
        }