示例#1
0
        public async Task <IActionResult> RegistrationAsync([FromServices] ICaptchaGenratorBase captchaGenratorBase,
                                                            [FromServices] ISequenceMaster sequenceMaster,
                                                            [FromServices] IConsolidatorProfile consolidatorProfile,
                                                            [FromServices] RoleManager <IdentityRole> RoleManager,
                                                            [FromForm] mdlRegistration mdl)
        {
            if (mdl.CaptchaData == null)
            {
                ModelState.AddModelError(mdl.CaptchaData.CaptchaCode, "Invalid Captcha");
            }
            else if (!captchaGenratorBase.verifyCaptch(mdl.CaptchaData.SaltId, mdl.CaptchaData.CaptchaCode))
            {
                ModelState.AddModelError(mdl.CaptchaData.CaptchaCode, "Invalid Captcha");
            }
            if (ModelState.IsValid)
            {
                using var transaction = _context.Database.BeginTransaction();
                try
                {
                    mdl.GenrateRegistration(sequenceMaster, consolidatorProfile, _context);
                    ApplicationUser appuser = new ApplicationUser()
                    {
                        UserName    = mdl.TcId,
                        Email       = mdl.EmailAddress,
                        TcNid       = mdl.TcNId,
                        PhoneNumber = mdl.PhoneNo,
                        UserType    = enmUserType.Consolidator
                    };
                    var result = await _userManager.CreateAsync(appuser, mdl.Password);

                    if (result.Succeeded)
                    {
                        var role = await RoleManager.FindByNameAsync("TC");

                        if (role != null)
                        {
                            await _userManager.AddToRoleAsync(appuser, "TC");
                        }

                        await _signInManager.SignInAsync(appuser, isPersistent : false);

                        transaction.Commit();
                        return(RedirectToAction("Index", "Home"));
                    }

                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                    transaction.Rollback();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    ModelState.AddModelError("", ex.Message);
                }
            }
            mdl.CaptchaData.GenrateCaptcha(captchaGenratorBase);
            return(View(mdl));
        }
示例#2
0
        public async Task <IActionResult> IsSponsorValid(string SpTcId, [FromServices] IConsolidatorProfile consolidatorProfile)
        {
            if (SpTcId != null)
            {
                var validSp = consolidatorProfile.ValidateSponsorId(SpTcId, true);

                return(Json(validSp));
            }

            return(Json(true));
        }
示例#3
0
        public bool GenrateRegistration(ISequenceMaster sequenceMaster, IConsolidatorProfile consolidatorProfile, DBContext context)
        {
            DateTime CurrentDatetime = DateTime.Now;
            //Validate Sponsor
            int?       SpNid    = null;
            List <int> AllSpNid = new List <int>();

            if (this.SpTcId != null && this.SpTcId.Length > 0)
            {
                SpNid = consolidatorProfile.GetNId(this.SpTcId, true);
                if (SpNid == 0)
                {
                    throw new Exception("Invalid Sponsor Nid");
                }
                AllSpNid = consolidatorProfile.GetAllSpNid(SpNid.Value);
                AllSpNid.Add(SpNid.Value);
            }

            this.TcId = sequenceMaster.GenrateSequence(this.state_id);
            tblRegistration tr = new tblRegistration()
            {
                Id                  = TcId,
                FirstName           = first_name,
                MiddleName          = middle_name ?? "",
                LastName            = last_name,
                Husband_father_name = husband_father_name,
                Gender              = gender,
                Dob                 = this.Dob.Value,
                JoiningState        = state_id,
                SpNid               = SpNid,
                SpId                = SpTcId,
                Isblock             = false,
                IsTerminate         = false,
                is_active           = (enmApprovalType)8,
                IsKycUpdated        = enmIsKycUpdated.No,
                JoiningDt           = CurrentDatetime,
                SpLegNumber         = SpNid.HasValue?(consolidatorProfile.GetNidLegCount(SpNid.Value) + 1):1,
                TCRanks             = enmTCRanks.Level1
            };

            context.tblRegistration.Add(tr);
            context.SaveChanges();
            TcNId = tr.Nid;
            context.tblTree.AddRange(AllSpNid.Select(p => new tblTree {
                TcNid = TcNId, TcSpNid = p
            }).ToList());
            tblTcAddressDetail tblTcAddressDetail = new tblTcAddressDetail()
            {
                AddressType   = enmAddressType.Permanent,
                address_line1 = this.address_line1,
                address_line2 = this.address_line2,
                StateId       = this.state_id,
                CountryId     = this.country_id,
                TcNid         = TcNId,
                IsDeleted     = false,
                CityId        = null,
                CreatedBy     = 0,
                CreatedDt     = CurrentDatetime,
                ModifiedBy    = 0,
                ModifiedDt    = CurrentDatetime
            };

            context.tblTcAddressDetail.Add(tblTcAddressDetail);
            context.SaveChanges();

            tblTcRanksDetails tblTcRanksDetails = new tblTcRanksDetails()
            {
                TCRanks     = enmTCRanks.Level1,
                TcNid       = TcNId,
                QualifyDate = CurrentDatetime,
                PPRequired  = 0,
                PPDone      = 0,
                Isdeleted   = false
            };

            context.tblTcRanksDetails.Add(tblTcRanksDetails);

            context.SaveChanges();
            tblTcEmail tblTCEmail = new tblTcEmail()
            {
                EmailID          = this.EmailAddress,
                TcNid            = TcNId,
                Isdeleted        = false,
                CreatedBy        = 0,
                CreatedDt        = CurrentDatetime,
                lastModifiedBy   = 0,
                LastModifieddate = CurrentDatetime
            };

            context.TblTcEmail.Add(tblTCEmail);
            context.SaveChanges();

            tblTcContact tblTCContact = new tblTcContact()
            {
                MobileNo         = this.PhoneNo,
                TcNid            = TcNId,
                Isdeleted        = false,
                CreatedBy        = 0,
                CreatedDt        = CurrentDatetime,
                lastModifiedBy   = 0,
                LastModifieddate = CurrentDatetime
            };

            context.TblTcContact.Add(tblTCContact);
            context.SaveChanges();
            return(true);
        }
示例#4
0
        public async Task <IActionResult> AddWalletAsync([FromServices] ICurrentUsers currentUsers, mdlWallet mdl, [FromServices] IConsolidatorProfile consolidator)
        {
            if (ModelState.IsValid)
            {
                int TcNiD = 0;
                if (mdl.SpTcId != null && mdl.SpTcId.Length > 0)
                {
                    TcNiD = consolidator.GetNId(mdl.SpTcId, true);
                    if (TcNiD == 0)
                    {
                        ModelState.AddModelError("", "Invalid TC ID !!!");
                    }
                }

                decimal  credit_amt = mdl.TransactionType == (enmWalletTransactiontype)1 ? mdl.WalletAmt : 0;
                decimal  debit_amt  = mdl.TransactionType == (enmWalletTransactiontype)2 ? mdl.WalletAmt : 0;
                DateTime todaydate  = Convert.ToDateTime(DateTime.Now.ToString("dd-MMM-yyyy"));
                var      data       = _context.tblTCwalletlog.Where(p => p.TcNid == TcNiD && p.credit == credit_amt && p.debit == debit_amt && p.createddatetime >= todaydate && p.createddatetime <= todaydate.AddDays(1)).FirstOrDefault();
                if (data != null)
                {
                    ModelState.AddModelError("", "Same Date with same Amount entry already exists !!!");
                    return(View(mdl));
                }



                var ExistingData = _context.tblTCwallet.FirstOrDefault(p => p.TcNid == TcNiD);
                if (ExistingData != null)
                {
                    ExistingData.TcNid     = TcNiD;
                    ExistingData.walletamt = ExistingData.walletamt + mdl.WalletAmt;
                    _context.tblTCwallet.Update(ExistingData);
                }
                else
                {
                    _context.tblTCwallet.Add(new tblTCWallet
                    {
                        TcNid     = TcNiD,
                        walletamt = mdl.WalletAmt,
                    });
                }
                _context.tblTCwalletlog.Add(new tblTCWalletLog()
                {
                    TcNid           = TcNiD,
                    credit          = credit_amt,
                    debit           = debit_amt,
                    createdby       = currentUsers.EmpId,
                    createddatetime = DateTime.Now,
                    remarks         = mdl.Remarks,
                    reqno           = 0,
                    groupid         = 0,
                });

                await _context.SaveChangesAsync();

                return(RedirectToAction("AddWallet",
                                        new { _enmSaveStatus = enmSaveStatus.success, _enmMessage = enmMessage.SaveSucessfully }));
            }



            return(View(mdl));
        }