public async Task <ActionResult> Create(RegisterAdminViewModel model, FormCollection collection) { try { // TODO: Add insert logic here AlphaNumGen alp = new AlphaNumGen(); var pwd = alp.GetPassword(); string username = string.Concat(model.FirstName.Substring(0, 1), "_", model.LastName); var user = new ApplicationUser { UserName = username, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.Phone, RegDate = DateTime.UtcNow, NotifyStatus = 1, UserType = "AD", // EmailConfirmed = true }; //this method add Newly registering Subcriber to AspNetUsers Tb which house is primary info and login permission var result = await UserManager.CreateAsync(user, pwd); if (result.Succeeded) { var UserRole = UserManager.GetRoles(user.Id); if (!UserRole.Contains("Admin")) { var addToRole = UserManager.AddToRole(user.Id, "Admin"); } // await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); //TODO: newly created admin get an email notification containing is registrations status // eg. username and password string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "superadm", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", em.Notification_Email_Body_Creator(user.FullName, "This is to notify you that an account has been created " + "for you on iHealth Nigeria GSFM Portal using this email address " + user.Email + " and the following information: <br/><br/> Username: "******"" + "<br/> Password: "******" <br/><br/>Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>. <br/> Welcome on board. <br/><br/>" + "Best Regards, <br/><br/> iHealth Nigeria Management")); TempData["success"] = "Registration Succeeded"; return(RedirectToAction("create", "superadm")); } AddErrors(result); } catch { return(View()); } return(View()); }
public async Task <JsonResult> ApprovePayment(IEnumerable <string> markAsPaidbyId) { try { #region if (markAsPaidbyId != null) { if (markAsPaidbyId.Count() > 0) { foreach (var id in markAsPaidbyId) { var usrpaid = db.premium_user.Single(u => u.premiumUserId == id); //check if the premium client's email already exist in registered users table is an ING member var is_Premium_User_Registered_in_all_user_db = db.Users.Where(u => u.Email.Equals(usrpaid.Email, StringComparison.CurrentCultureIgnoreCase)); if (is_Premium_User_Registered_in_all_user_db.Count() <= 0) { Random rd = new Random(); int myReferralCode = rd.Next(10000000); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db)); PasswordHasher pdH = new PasswordHasher(); AlphaNumGen anGen = new AlphaNumGen(); string password = anGen.GetPassword(); string username = string.Concat(usrpaid.First_Name.Substring(0, 1), usrpaid.Last_Name); var RefUrl = this.Url.Action("Register", "Account", new { sp = username }, this.Request.Url.Scheme); ApplicationUser rgUser = new ApplicationUser(); rgUser.FirstName = usrpaid.First_Name; rgUser.LastName = usrpaid.Last_Name; rgUser.Email = usrpaid.Email; rgUser.PhoneNumber = usrpaid.Phone; rgUser.Address = usrpaid.Address; rgUser.City = usrpaid.City; rgUser.State = usrpaid.State; rgUser.Gender = usrpaid.Gender; rgUser.Health_Service_Provider = "No"; rgUser.isClientBooster = false; rgUser.UserType = "BusinessUser"; rgUser.NotifyStatus = 1; rgUser.Nationality = usrpaid.Nationality; rgUser.MyRefferalCode = myReferralCode; rgUser.subscriptionType = "Health_Insurance"; rgUser.UserName = username; rgUser.Refferal_Url = RefUrl; rgUser.PasswordHash = pdH.HashPassword(password); rgUser.SecurityStamp = Guid.NewGuid().ToString(); rgUser.RegDate = DateTime.UtcNow; rgUser.EmailConfirmed = true; db.Users.Add(rgUser); await db.SaveChangesAsync(); rgUser = userManager.FindByName(rgUser.UserName); if (rgUser != null) { var addtorole = userManager.AddToRole(rgUser.Id, "Users"); } IHealthUsersMLM iHmlm = new IHealthUsersMLM(); iHmlm.UserID = rgUser.Id; iHmlm.MyRefferalCode = myReferralCode; iHmlm.MySponsorRefCode = usrpaid.sponsorID.ToString(); iHmlm.MyDownlineCount = 0; db.IHealthUsersMLM.Add(iHmlm); await db.SaveChangesAsync(); #region //Confirm payment usrpaid.PaymentStatus = "Paid"; usrpaid.Transaction_date = DateTime.UtcNow; usrpaid.SignedBy = Session["Name"].ToString(); usrpaid.NotifyStatus = 1; // usrpaid.INISubcriberExtraDetails.MaxDT2MtTarget = DateTime.UtcNow.AddDays(30); await db.SaveChangesAsync(); //check if the new member has a sponsor so that we can give the sponsor bonus if (usrpaid.sponsorID != 0) { //retrieve the sponsor of this new registrant details from the all users table var sponsor = db.Users.Single(u => u.MyRefferalCode.ToString() == usrpaid.sponsorID.ToString()); //check if sponsor is an ihealth networking subscriber, so dt we can give him credit var sp_IN_mlm = db.INISubcriberExtraDetails.Single(sp => sp.User.Id == sponsor.Id); referral_BonusTb refbonus = new referral_BonusTb(); refbonus.user_ID = sponsor.Id; // refbonus.Downline_Id = usrpaid.INISubcriberExtraDetails.User.MyRefferalCode; refbonus.Downline_Name = usrpaid.First_Name + " " + usrpaid.Last_Name; refbonus.Bonus_Type = "Premium Referral Bonus"; refbonus.Subscription_Fee = usrpaid.Amount; refbonus.Bonus_created_date = DateTime.UtcNow; refbonus.Bonus = refbonus.Subscription_Fee * 0.05; // bonus is 5% of the subscription db.referral_bonus_tb.Add(refbonus); await db.SaveChangesAsync(); sp_IN_mlm.CurrentBonus = sp_IN_mlm.CurrentBonus + (refbonus.Subscription_Fee * 0.05); await db.SaveChangesAsync(); } string mailbody = "<p>We are glad to let you know that your payment for iHealth premium user package has been acknowledged.</p> " + "<p>Kindly note that we will batch and forward your details to the assigned HMO to activate your plan.</p>" + "<p>We will notify you via email, once your plan becomes active.</p>" + "<p>Kindly, note that a user account has also been created for you on our platform. Below are your login credentials;<br/>" + "<b> Username: "******" <br/> Password: "******"</b></p>" + "<p>Thank you. <br/><br/>Best Regards, <br/><br/>iHealthGSFM Team.</p>"; await em.premiumUserPaymentApprovalMail(usrpaid.Email, usrpaid.Last_Name, "Premium Plan Payment Approval", mailbody); TempData["success"] = "Operations Successfull"; #endregion } else { #region //confirm payment usrpaid.PaymentStatus = "Paid"; usrpaid.Transaction_date = DateTime.UtcNow; usrpaid.SignedBy = Session["Name"].ToString(); usrpaid.NotifyStatus = 1; // usrpaid.INISubcriberExtraDetails.MaxDT2MtTarget = DateTime.UtcNow.AddDays(30); await db.SaveChangesAsync(); //check if the new member has a sponsor so that we can give the sponsor bonus if (usrpaid.sponsorID != 0) { //retrieve the sponsor of this new registrant details from the all users table var sponsor = db.Users.Single(u => u.MyRefferalCode.ToString() == usrpaid.sponsorID.ToString()); //check if sponsor is an ihealth networking subscriber, so dt we can give him credit var sp_IN_mlm = db.INISubcriberExtraDetails.Single(sp => sp.User.Id == sponsor.Id); referral_BonusTb refbonus = new referral_BonusTb(); refbonus.user_ID = sponsor.Id; // refbonus.Downline_Id = usrpaid.INISubcriberExtraDetails.User.MyRefferalCode; refbonus.Downline_Name = usrpaid.First_Name + " " + usrpaid.Last_Name; refbonus.Bonus_Type = "Premium Referral Bonus"; refbonus.Subscription_Fee = usrpaid.Amount; refbonus.Bonus_created_date = DateTime.UtcNow; refbonus.Bonus = refbonus.Subscription_Fee * 0.05; // bonus is 5% of the subscription db.referral_bonus_tb.Add(refbonus); await db.SaveChangesAsync(); sp_IN_mlm.CurrentBonus = sp_IN_mlm.CurrentBonus + (refbonus.Subscription_Fee * 0.05); await db.SaveChangesAsync(); } string mailbody = "<p>We are glad to let you know that your payment for iHealth premium user package has been acknowledged.</p> " + "<p>Kindly note that we will batch and forward your details to the assigned HMO to activate your plan.</p>" + "<p>We will notify you via email, once your plan becomes active.</p>" + "<p>Thank you. <br/><br/>Best Regards, <br/><br/>iHealthGSFM Team.</p>"; await em.premiumUserPaymentApprovalMail(usrpaid.Email, usrpaid.Last_Name, "Premium Plan Payment Approval", mailbody); TempData["success"] = "Operations Successfull"; #endregion } } return(Json(true, JsonRequestBehavior.AllowGet)); } else { TempData["error"] = "Oops! No Item is selected from the list. "; return(Json(false, JsonRequestBehavior.AllowGet)); } } else { TempData["error"] = "Oops! No Item is selected from the list. "; return(Json(false, JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception) { throw; } }