public string PopoulateWelcomeEmailTemplate(string bodyHtml, School_AppIn_Model.User user, string username, string pw) { var wBodyHtml = bodyHtml.Replace("{{USER-NAME}}", user.NickName) .Replace("{{USER-ADDRESS}}", (user.Email ?? String.Empty)) .Replace("{{USERNAME}}", username) .Replace("{{PASSWORD}}", pw); return(wBodyHtml); }
public async Task <ActionResult> Create([Bind(Include = "Student_Id,Roll_No,First_Name,Middle_Name,Last_Name,Gender_Id,DOB,Enrollment_Date,Father_Name,Mother_Name,Blood_Group_Id,Address_Line1,Address_Line2,City_Id,State_Id,Country_Id,Phone_No1,Phone_No2,LandLine,Email_Id,Academic_Year,Created_By,Created_On,Updated_On,Updated_By,Is_Active,Is_Deleted,Pincode,Photo,Aadhar_No,Class_Id,Section_Id,Is_HostelStudent,Is_FeesDueRemaining,Fees_Due_Amount")] Student student, HttpPostedFileBase imageUpload, string command) { var userId = LoggedInUser.Id; if (string.IsNullOrEmpty(Request.Form["Country_Id"])) { goto Fail; } if (string.IsNullOrEmpty(Request.Form["State_Id"])) { goto Fail; } if (string.IsNullOrEmpty(Request.Form["City_Id"])) { goto Fail; } if (string.IsNullOrEmpty(Request.Form["Section_Id"])) { goto Fail; } if (ModelState.IsValid) { int cityId = int.Parse(Request.Form["City_Id"]); int countryId = int.Parse(Request.Form["Country_Id"]); int stateId = int.Parse(Request.Form["State_Id"]); int sectionId = int.Parse(Request.Form["Section_Id"]); string bodyHtml = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/EmailTemplates/WelcomeEmailTemplate.html"))) { bodyHtml = reader.ReadToEnd(); } var user = UserManager.FindByName(student.Email_Id); if (user == null) { user = new School_AppIn_Model.User { UserName = student.Email_Id, Email = student.Email_Id, EmailConfirmed = true }; var pwd = PasswordGenerator.GeneratePWD(); var result = await UserManager.CreateAsync(user, pwd); if (result.Succeeded) { UserManager.AddToRole(user.Id, School_AppIn_Model.Common.Constants.ROLE_STUDENT); } appDbContext.SaveChanges(); // var userMail = LoggedInUser; //var welcomeBodyHtml = PopoulateWelcomeEmailTemplate(bodyHtml, userMail, user.UserName, pwd.Trim()); //School_AppIn_Utils.Utility.ApiTypes.EmailSend emailSend = Utility.Send( // apiKey: "41750a2d-38ba-4f35-a616-f0f776cc107e", // subject: string.Format("Welcome to {0} School ERP Portal", userMail.UserName), // from: LoggedInUser.UserName, // fromName: userMail.Email, // to: new List<string> { user.Email }, // bodyText: "You can login to using the following credentials. Username :"******", Password :"******"Index"); switch (command) { //case "Save & Back To List": // return RedirectToAction("Index"); case "Save & Continue": TempData["Student_Id"] = student.Student_Id; return(RedirectToAction("CreateStudentOther")); default: return(RedirectToAction("Index")); } } Fail: ViewBag.Country_Id = new SelectList(db.Country, "Id", "Name"); ViewBag.Blood_Group_Id = new SelectList(db.Blood_Group, "Id", "Name", student.Blood_Group_Id); ViewBag.Class_Id = new SelectList(db.Classes, "Class_Id", "Class_Name", student.Class_Id); //ViewBag.Section_Id = new SelectList(db.Sections, "Section_Id", "Section_Name", student.Section_Id); ViewBag.Gender_Id = new SelectList(db.Genders, "Id", "Name", student.Gender_Id); return(View(student)); }