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)); }
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); }