private async void InitDBAsync() { Task.Run(() => { using (var ctx = new Models.DBContext()) { } }); }
public ActionResult SetAdminRole(string sType, string sUser) { ApplicationUser user = UserManager.FindByName <ApplicationUser, string>(sUser); Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.CompanyName == user.CompanyName select new { d.CompanyName, d.Logo }).FirstOrDefault(); if (sType == "Y") { cmp.CompanyName = user.CompanyName; cmp.EmailID = user.Email; cmp.UserName = user.UserName; cmp.Logo = FindCompany.Logo; dbContext.Company.Add(cmp); dbContext.SaveChanges(); } else { var userdata = dbContext.Company.Where(D => D.UserName == sUser).FirstOrDefault(); dbContext.Company.Remove(userdata); dbContext.SaveChanges(); } return(View()); }
// GET: /Account/LogOff public ActionResult LogOff() { HttpContext.Session["LoginUserInf"] = null; Models.DBContext db = new Models.DBContext(); string wcCompanyName = ConfigurationManager.AppSettings["wcCompanyName"].ToString(); var INI = (from ini in db.InitializeTables where ini.Authentication.ToUpper() == "WINDOWS" && ini.CompanyName == wcCompanyName select ini).FirstOrDefault(); if (INI != null) { string[] LogonUser = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.ToString().Split('\\'); ViewBag.UserName = LogonUser[1]; ViewBag.URL = "/"; } else { ApplicationUser UserData = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); ViewBag.UserName = UserData.UserName; ViewBag.URL = "Login"; } ViewBag.Title = "Log Off"; AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(View()); }
private void AddHackerNewsJobs(Models.DBContext context) { var anyJobLastMonth = context.JobPosts.FirstOrDefault(j => j.SourceReference.Contains("news.ycombinator") && DbFunctions.TruncateTime(j.SourcePostedDate).Value.Month == DbFunctions.TruncateTime(DateTime.UtcNow).Value.Month - 1 && DbFunctions.TruncateTime(j.SourcePostedDate).Value.Year == DbFunctions.TruncateTime(DateTime.UtcNow).Value.Year); if (anyJobLastMonth == null) { var lastMonthJobs = Import.LoadHackerNewsFeed(DateTime.UtcNow.AddMonths(-1)); if (lastMonthJobs.Any()) { context.JobPosts.AddRange(lastMonthJobs); } } var anyJobThisMonth = context.JobPosts.FirstOrDefault(j => j.SourceReference.Contains("news.ycombinator") && DbFunctions.TruncateTime(j.SourcePostedDate).Value.Month == DbFunctions.TruncateTime(DateTime.UtcNow).Value.Month && DbFunctions.TruncateTime(j.SourcePostedDate).Value.Year == DbFunctions.TruncateTime(DateTime.UtcNow).Value.Year); if (anyJobThisMonth == null) { var thisMonthJobs = Import.LoadHackerNewsFeed(); if (thisMonthJobs.Any()) { context.JobPosts.AddRange(thisMonthJobs); } } }
public async Task <IActionResult> Index() { TipoCambioSoapClient client = new TipoCambioSoapClient(EndpointConfiguration.TipoCambioSoap); //var result = await client.AddAsync(5, 8); var result = await client.TipoCambioDiaAsync(); var ResultOfTipoCambioBank = result.Body.TipoCambioDiaResult.CambioDolar[0]; ViewBag.ResultOfBank = ResultOfTipoCambioBank; var contextOptions = new DbContextOptionsBuilder <Models.DBContext>() .UseSqlServer("Server=localhost;Database=DemoAzureInsight;User Id=elvis;Password=*Disdel100;") .Options; using var context = new Models.DBContext(contextOptions); Models.TipoCambio NewValueTipoCambios = new TipoCambio(); NewValueTipoCambios.Fecha = Convert.ToDateTime(ResultOfTipoCambioBank.fecha); NewValueTipoCambios.Referencia = Convert.ToDecimal(ResultOfTipoCambioBank.referencia); context.Add <Models.TipoCambio>(NewValueTipoCambios); context.SaveChanges(); List <Models.TipoCambio> AllData = context.TipoCambios.ToList(); ViewBag.AllData = AllData; return(View()); }
public ActionResult UserRegister() { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.UserName == User.Identity.Name select new { d.CompanyName }).ToList(); string CompanyName = FindCompany[0].CompanyName; ViewBag.CompanyName = CompanyName; ViewBag.ErrorMessage = ""; ViewBag.InitialValues = JsonConvert.SerializeObject((from iv in db.InitializeTables where iv.CompanyName == CompanyName select iv).FirstOrDefault()); RegisterModel model = new RegisterModel(); model.UserName = ""; model.CompanyName = ViewBag.CompanyName; model.Email = ""; model.Upload = ""; model.Password = ""; model.ConfirmPassword = ""; model.ConfirmPassword = ""; model.ConfirmPasswordName = ""; model.RequestType = "Individual"; return(View(model)); }
public ActionResult UserRegister() { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.UserName == User.Identity.Name select new { d.CompanyName }).ToList(); ViewBag.CompanyName = FindCompany[0].CompanyName; return(View()); }
/// <summary> /// /// </summary> /// <returns></returns> public virtual ActionResult StiReport() { using (var db = new Models.DBContext()) { var obj = db.Provinces.Select(z => new { ProvinceName = z.Name, Citys = z.Citys }).ToList(); var mainReport = new StiReport(); mainReport.Load(Server.MapPath("~/Files/Report.mrt")); mainReport.Compile(); mainReport["DateTimeNow"] = DateTime.UtcNow; mainReport.RegBusinessObject("ProvincesWithCitys", obj); return(Stimulsoft.Report.Mvc.StiMvcViewer.GetReportSnapshotResult(HttpContext, mainReport)); } }
/// <summary> /// /// </summary> /// <returns></returns> public virtual ActionResult StiReport() { using (var db = new Models.DBContext()) { var obj = db.Provinces.Select(z => new {ProvinceName = z.Name, Citys= z.Citys}).ToList(); var mainReport = new StiReport(); mainReport.Load(Server.MapPath("~/Files/Report.mrt")); mainReport.Compile(); mainReport["DateTimeNow"] = DateTime.UtcNow; mainReport.RegBusinessObject("ProvincesWithCitys", obj); return Stimulsoft.Report.Mvc.StiMvcViewer.GetReportSnapshotResult(HttpContext, mainReport); } }
public ActionResult Store(Complaint c) { DBContext db = new Models.DBContext(); if (ModelState.IsValid) { c.IsAdminShow = false; db.Complaints.Add(c); db.SaveChanges(); ViewBag.Message = "پیام شما با موفقیت دریافت شد و بزودی توسط مدیران سایت بررسی خواهد شد"; } return(View("Create")); }
public ActionResult View(int id) { var db = new Models.DBContext(); var bil = db.Get(id); var model = new ViewModels.BilViewViewModel { Color = bil.Color, Manufacturer = bil.Manufacturer, Model = bil.Model, Price = bil.Price, Year = bil.Year }; return(View(model)); }
// GET: Bil public ActionResult Index() { var model = new ViewModels.BilIndexViewModel(); var db = new Models.DBContext(); model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel { Manufacturer = r.Manufacturer, Model = r.Model, Year = r.Year, Id = r.Id })); return(View(model)); }
public ActionResult Edit(ViewModels.BilEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var db = new Models.DBContext(); var bil = db.Get(model.Id); bil.Manufacturer = model.Manufacturer; bil.Model = model.Modell; //bil.Price = model.Price; bil.Year = model.Year; bil.Color = model.Color; return(RedirectToAction("Index")); }
public ActionResult Search(string SearchManufacturer, string SearchYear) { var db = new Models.DBContext(); var model = new ViewModels.BilIndexViewModel { SearchManufacturer = SearchManufacturer, SearchYear = SearchYear }; model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel { Manufacturer = r.Manufacturer, Model = r.Model, Year = r.Year, Id = r.Id }).Where(c => Matches(c, SearchManufacturer, SearchYear) )); return(View("Index", model)); }
public ActionResult Create(ViewModels.BilCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var db = new Models.DBContext(); var newId = db.GetAll().Max(r => r.Id) + 1; var bil = new Models.Bil { Id = newId, Color = model.Color, Manufacturer = model.Manufacturer, Model = model.Modell, Year = model.Year }; db.AddBil(bil); return(RedirectToAction("Index")); }
// POST: /Account/UploadLogo public ActionResult UploadLogo(HttpPostedFileBase file) { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = dbContext.Company.Where(C => C.UserName == User.Identity.Name).FirstOrDefault(); if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Content/assets/CompanyLogo/"), pic); // file is uploaded file.SaveAs(path); if (FindCompany != null) { FindCompany.Logo = pic; dbContext.SaveChanges(); } ViewBag.UploadSuccess = "Logo Uploaded Successfully, Please click on the link to dashboard list"; } return(View()); }
public GenericRepository(Models.DBContext Context) { this.Context = Context; }
public async Task <ActionResult> Register(RegisterModel model, string cbxDataPrivacy) { if (cbxDataPrivacy == "on") { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.CompanyName == model.CompanyName select new { d.CompanyName }).ToList(); if (ModelState.IsValid) { // Attempt to register the user if (FindCompany.Count == 0) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { cmp.CompanyName = user.CompanyName; cmp.EmailID = user.Email; cmp.UserName = user.UserName; cmp.Logo = null; dbContext.Company.Add(cmp); dbContext.SaveChanges(); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = EMail, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "/Home/ApprovalList/?CustRegId=" + user.Id + "'>" + "Approval link" + "</a>"; //HTML Template for Send email string subject = "Request for Approval of subscription"; string body = "<b>Dear Admin, </b><br/><br/>"; body = body + "<b>Kindly Approve The Customer: " + user.CompanyName + " Request for enrollement.</b><br/>" + "<b>Please find the Customers list </b> : " + lnkHref; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>Mcbitss Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); return(Redirect("/")); } ViewBag.ErrorMessage = result.Errors.First(); } else { ViewBag.ErrorMessage = "Company details are already added"; } } } else { ViewBag.ErrorMessage = "Please accept data privacy policy && Terms"; } // If we got this far, something failed, redisplay form return(View(model)); }
public HttpResponseMessage DownloadOrgChartPDF(DownloadPDFInfo Info) { string ErrorString = "ERROR_NONE", ErrorMessage = "", PDF_FileName = ""; try { LevelInfo LI = new LevelInfo(); string AuthHeader = HttpContext.Current.Request.Headers["Authorization"]; if (AuthHeader != null && AuthHeader.StartsWith("Basic")) { //Extract credentials string EncodedUsernamePassword = AuthHeader.Substring("Basic ".Length).Trim(); //The coding should be iso or you could use ASCII and UTF-8 decoder Encoding Encoding = Encoding.GetEncoding("iso-8859-1"); string UsernamePassword = Encoding.GetString(Convert.FromBase64String(EncodedUsernamePassword)); int SeperatorIndex = UsernamePassword.IndexOf(':'); string UserName = UsernamePassword.Substring(0, SeperatorIndex); string Password = UsernamePassword.Substring(SeperatorIndex + 1); using (Models.DBContext db = new Models.DBContext()) { LoginUsers UserData = LI.GetLoginUserWebAPI("", UserName); var UCA = (from uca in db.UserLastActions where uca.UserId == UserData.UserName select uca).FirstOrDefault(); if (UCA != null) { var FolderName = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Data/Versions/DownLoadVersion")); string FN = UserData.UserName + "_" + UserData.CompanyName + "_" + DateTime.Now.ToString("yyyyMMddhhmmss"); string FileNameWithPath = FolderName + "\\" + FN + ".PDF"; int FinalyzerVersion = Convert.ToInt32(LI.ChooseFinalyzerVersionWebAPI(UCA.Version, UserName)); VersionDetails VD = (from vd in db.VersionDetails where vd.UserRole == "Finalyzer" && vd.CompanyName == UserData.CompanyName && vd.ActiveVersion == "Y" && vd.VersionNo == FinalyzerVersion select vd).FirstOrDefault(); if (VD != null) { var UFH = (from ufh in db.UploadFilesHeaders where ufh.CompanyName == UserData.CompanyName && ufh.Role == "Finalyzer" && ufh.VersionNo == FinalyzerVersion select ufh).FirstOrDefault(); if (UFH != null) { string ShowLevelPDF = UCA.ShowLevel; if (Info.LevelUp == "Yes") { ShowLevelPDF = UCA.ParentLevel == "999999" ? UCA.ShowLevel : UCA.ParentLevel; } string CurrentLevelPDF = "All"; if (Info.CurrentLevel == "Yes") { CurrentLevelPDF = UCA.Levels; if (Info.LevelUp == "Yes") { if (UCA.ParentLevel != "999999") { if (CurrentLevelPDF == "One") { CurrentLevelPDF = "Two"; } else if (CurrentLevelPDF == "Two") { CurrentLevelPDF = "Three"; } else if (CurrentLevelPDF == "Three") { CurrentLevelPDF = "Four"; } else if (CurrentLevelPDF == "Four") { CurrentLevelPDF = "Five"; } else if (CurrentLevelPDF == "Five") { CurrentLevelPDF = "Five"; } else if (CurrentLevelPDF == "All") { CurrentLevelPDF = "All"; } } else { Info.LevelUp = "No"; } } } if (UCA.ParentLevel == "999999") { Info.LevelUp = "No"; } AllLevelPDF AllPDF = new AllLevelPDF(ShowLevelPDF, "999999", UCA.Oper.Trim().ToUpper(), UCA.Country, CurrentLevelPDF, "23/10/2018", 6, "EN", "", "PDF", "POSITION_CALCULATED_COST", UFH.PositionCostField, UserData.CompanyName, UFH.FirstPosition, FinalyzerVersion); DataSet OrgDataSet = LI.GetOrgChartDataTable(UCA.Role, UCA.Country, ShowLevelPDF, "999999", CurrentLevelPDF, UCA.Oper, UCA.Version, UCA.ShowLevel, Info.LevelUp, UCA.SelectedFunctionalManagerType); AllPDF.CreateAllLevelPDFIntermediateResults(OrgDataSet, UCA.Oper.ToUpper(), VD.VersionNo.ToString(), "", "PDF"); OrgDataSet = LI.GetOrgChartDataTable(UCA.Role, UCA.Country, ShowLevelPDF, "999999", CurrentLevelPDF, UCA.Oper, UCA.Version, UCA.ShowLevel, Info.LevelUp, UCA.SelectedFunctionalManagerType); PDF_FileName = AllPDF.CreateAllLevelPDF(OrgDataSet, "PDF", UCA.Company, UCA.UserId, UCA.Oper, UCA.SelectedFMLine, Info.ViewFlag, FileNameWithPath, Info.LevelUp, UCA.ShowLevel); } } } } } else { //Handle what happens if that isn't the case ErrorString = "ERROR_AUTH"; } } catch (Exception ex) { // Log exception code goes here ErrorString = "ERROR_IN"; ErrorMessage = ex.Message; } if (ErrorString == "ERROR_IN") { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error occured while executing DownloadOrgChartPDF(" + ErrorMessage + ").")); } else if (ErrorString == "ERROR_AUTH") { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "The authorization header is either empty or isn't Basic.")); } return(Request.CreateResponse(HttpStatusCode.OK, PDF_FileName)); }
public async Task <ActionResult> Register(RegisterModel model, string cbxDataPrivacy) { if (cbxDataPrivacy == "on") { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.CompanyName == model.CompanyName select new { d.CompanyName }).ToList(); string wcCompanyName = ConfigurationManager.AppSettings["wcCompanyName"].ToString(); var INI = (from ini in dbContext.InitializeTables where ini.Authentication.ToUpper() == "WINDOWS" && ini.CompanyName == wcCompanyName select ini).FirstOrDefault(); if (INI != null) { string[] WindowsUser = Request.LogonUserIdentity.User.ToString().Split('\\'); string WindowUserName = WindowsUser[0]; if (WindowsUser.Length >= 2) { WindowUserName = WindowsUser[1]; } model.UserName = WindowUserName; } if (ModelState.IsValid) { // Attempt to register the user if (FindCompany.Count == 0) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { cmp.CompanyName = user.CompanyName; cmp.EmailID = user.Email; cmp.UserName = user.UserName; cmp.Logo = null; dbContext.Company.Add(cmp); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles; usr.CompanyName = user.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 0; cmd.CommandText = "PROC_CONFIGURE_COMPANY"; cmd.Parameters.Add("@CURRENT_COMPANY", SqlDbType.VarChar, 500).Value = ConfigureCompany; cmd.Parameters.Add("@CONFIGURE_COMPANY", SqlDbType.VarChar, 500).Value = user.CompanyName; Common csobj = new Common(); csobj.SPReturnDataTable(cmd); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "/Home/ApprovalList/?CustRegId=" + user.Id + "'>" + "Approval link" + "</a>"; //HTML Template for Send email string subject = "Request for Approval of subscription"; string body = "<b>Dear Admin, </b><br/><br/>"; body = body + "<b>Kindly Approve The Customer: " + user.CompanyName + " Request for enrollement.</b><br/>" + "<b>Please find the Customers list </b> : " + lnkHref; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>Mcbitss Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); return(Redirect("~/")); } ViewBag.ErrorMessage = result.Errors.First(); } else { ViewBag.ErrorMessage = "Company details are already added"; } } } else { ViewBag.ErrorMessage = "Please accept data privacy policy && Terms"; } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> UserRegister(RegisterModel model, HttpPostedFileBase Upload, string cbxRequestType) { DataTable dtUsers = new DataTable(); ViewBag.CompanyName = model.CompanyName; string UploadFileName = ""; model.RequestType = cbxRequestType; if (cbxRequestType == "Individual") { model.Upload = "No File"; model.PasswordName = model.Password; model.ConfirmPasswordName = model.ConfirmPassword; if (ModelState.IsValid) { // Attempt to register the user var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Models.DBContext dbContext = new Models.DBContext(); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles.Replace("Planner", "Player"); usr.CompanyName = model.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); try { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "'> " + "link" + "</a>"; //HTML Template for Send email string subject = "Login Created"; string body = "<b>Dear " + model.UserName + ", </b><br/><br/>"; body = body + "<b>Your login credentials created, Kindly change the pasword at the earliest" + lnkHref + "</b><br/>"; body = body + "<b>User Name : " + model.UserName + "</b><br/>";; body = body + "<b>Password : "******"</b><br/>";; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>" + model.CompanyName + "Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } catch (Exception ex) { UploadFileName += model.UserName + " email not sent to this user(" + ex.Message + ")\n"; } } else { UploadFileName += result.Errors.First() + "\n"; } if (UploadFileName == "") { UploadFileName = "User Successfuly loaded."; } ViewBag.ErrorMessage = UploadFileName; } } else if (cbxRequestType == "Mass") { string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = Upload.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = Upload.FileName; } // Get the complete folder path and store the file inside it. fname = Path.Combine(Server.MapPath("~/App_Data/Uploads/"), fname); Upload.SaveAs(fname); ExcelAPI API = new ExcelAPI(); API.CreateDataTableFromExcel(fname, dtUsers); foreach (DataRow dr in dtUsers.Rows) { model.UserName = dr["Name"].ToString(); model.Email = dr["Email"].ToString(); model.Roles = dr["Roles"].ToString(); model.Password = model.PasswordName; model.ConfirmPassword = model.ConfirmPasswordName; // Attempt to register the user var user = new ApplicationUser { UserName = dr["Name"].ToString(), Email = dr["Email"].ToString(), CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.PasswordName); if (result.Succeeded) { Models.DBContext dbContext = new Models.DBContext(); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles.Replace("Planner", "Player"); usr.CompanyName = model.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); try { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "'> " + "link" + "</a>"; //HTML Template for Send email string subject = "Login Created"; string body = "<b>Dear " + model.UserName + ", </b><br/><br/>"; body = body + "<b>Your login credentials created, Kindly change the pasword at the earliest" + lnkHref + "</b><br/>"; body = body + "<b>User Name : " + model.UserName + "</b><br/>";; body = body + "<b>Password : "******"</b><br/>";; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>" + model.CompanyName + "Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } catch (Exception ex) { UploadFileName += model.UserName + " email not sent to this user(" + ex.Message + ")\n"; } } else { UploadFileName += result.Errors.First() + "\n"; } } if (UploadFileName == "") { UploadFileName = "Users Successfuly loaded."; } ViewBag.ErrorMessage = UploadFileName; } // If we got this far, something failed, redisplay form return(View(model)); }