/// <summary> /// Delete the user based on userid /// </summary> /// <param name="Id"></param> /// <returns></returns> public ActionResult Delete(string Id) { if (ModelState.IsValid) { try { var user = context.AspNetUsers.Find(Id); context.AspNetUsers.Remove(user); context.SaveChanges(); eventLog.SaveEventLog(ConstantEvent.UserDeleted, ConstantEvent.Successful); return(RedirectToAction("List")); } catch (Exception ex) { string mailSubjectForRegistration = "Deleting user Failure"; string mailBodyForRegistration = ""; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html"))) { mailBodyForRegistration = reader.ReadToEnd(); } mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDate]", DateTime.Now.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDetail]", ex.StackTrace.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[MessageDetail]", "the system tried to delete user from the MarketR System."); SendingEmail.SendMail(mailSubjectForRegistration, mailBodyForRegistration); } } return(View()); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> Register(AccountRegistrationModel viewModel) { // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { return(View(viewModel)); } // Prepare the identity with the provided information var user = new IdentityUser { UserName = viewModel.Username ?? viewModel.Email, Email = viewModel.Email }; // Try to create a user with the given identity try { var result = await _manager.CreateAsync(user, viewModel.Password); // If the user could not be created if (!result.Succeeded) { // Add all errors to the page so they can be used to display what went wrong AddErrors(result); return(View(viewModel)); } // If the user was able to be created we can sign it in immediately // Note: Consider using the email verification proces await SignInAsync(user, false); return(RedirectToLocal()); } catch (DbEntityValidationException ex) { // Add all errors to the page so they can be used to display what went wrong AddErrors(ex); string mailSubjectForRegistration = "User registration Failure"; string mailBodyForRegistration = ""; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html"))) { mailBodyForRegistration = reader.ReadToEnd(); } mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDate]", DateTime.Now.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDetail]", ex.StackTrace.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[MessageDetail]", "the system tried to register a user into the MarketR System."); SendingEmail.SendMail(mailSubjectForRegistration, mailBodyForRegistration); return(View(viewModel)); } }
public async Task <ActionResult> CreateUser(AccountRegistrationModel viewModel) { // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { return(View(viewModel)); } // Prepare the identity with the provided information var user = new IdentityUser { UserName = viewModel.Username ?? viewModel.Email, Email = viewModel.Email }; // Try to create a user with the given identity try { var result = await _manager.CreateAsync(user, viewModel.Password); // If the user could not be created if (!result.Succeeded) { eventLog.SaveEventLog(ConstantEvent.NewUserCreated, ConstantEvent.Failed); return(View(viewModel)); } eventLog.SaveEventLog(ConstantEvent.NewUserCreated, ConstantEvent.Successful); return(RedirectToAction("List")); } catch (DbEntityValidationException ex) { string mailSubjectForRegistration = "Creating user Failure"; string mailBodyForRegistration = ""; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html"))) { mailBodyForRegistration = reader.ReadToEnd(); } mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDate]", DateTime.Now.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDetail]", ex.StackTrace.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[MessageDetail]", "the system tried to create user into the MarketR System."); SendingEmail.SendMail(mailSubjectForRegistration, mailBodyForRegistration); return(View(viewModel)); } }
public ActionResult AsyncUpload(IEnumerable <HttpPostedFileBase> files) { int count = 0; try { if (files != null) { foreach (var file in files) { if (file != null && file.ContentLength > 0) { var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); var path = Path.Combine(Server.MapPath("~/UploadedFiles"), fileName); file.SaveAs(path); count++; } } } return(new JsonResult { Data = "Successfully " + count + " file(s) uploaded" }); } catch (Exception ex) { string mailSubjectForRegistration = "Creating user Failure"; string mailBodyForRegistration = ""; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html"))) { mailBodyForRegistration = reader.ReadToEnd(); } mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDate]", DateTime.Now.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDetail]", ex.StackTrace.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[MessageDetail]", "the system tried to create user into the MarketR System."); SendingEmail.SendMail(mailSubjectForRegistration, mailBodyForRegistration); throw ex; } }
/// <summary> /// Showing Nostro Deals /// </summary> /// <param name="Id"></param> /// <returns></returns> public ActionResult NostroDeals() { List <FolderPermission> folderPermission = new List <FolderPermission>(); try { if (Session["UserId"] != null) { if (Session["UserRole"].ToString() == "Admin" || Session["UserRole"].ToString() == "Middle") { folderPermission = context.FolderPermissions.ToList(); } else if (Session["UserRole"].ToString() == "DR") { folderPermission = context.FolderPermissions.Where(x => x.Folder == "Non Nostro").ToList(); } else if (Session["UserRole"].ToString() == "Nostro") { folderPermission = context.FolderPermissions.Where(x => x.Folder == "Nostro").ToList(); } } } catch (Exception ex) { string mailSubjectForRegistration = "Nostro/Non-Nostro deals loading Failure"; string mailBodyForRegistration = ""; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html"))) { mailBodyForRegistration = reader.ReadToEnd(); } mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDate]", DateTime.Now.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[ErrorDetail]", ex.StackTrace.ToString()); mailBodyForRegistration = mailBodyForRegistration.Replace("[MessageDetail]", "the system tried to load all the deals into the MarketR System."); SendingEmail.SendMail(mailSubjectForRegistration, mailBodyForRegistration); } return(View(folderPermission)); }