public IActionResult ResetPassword(ForgotPasswordModel userModel) { long id; if (userModel.ConfirmPassword != userModel.Password) { TempData[Enums.NotifyType.Error.GetDescription()] = "Password and Confirm Password must be same."; return(View("ResetPassword")); } TblUser model = _service.GetById(userModel.UserId); model.Password = EncryptionDecryption.GetEncrypt(userModel.Password); using (PolyFilmsContext contex = BaseContext.GetDbContext()) { model.Token = null; model.TokenExpiryDateTime = null; contex.TblUser.Update(model); id = contex.SaveChanges(); } if (id > 0) { TempData[Enums.NotifyType.Success.GetDescription()] = "Password reset successful."; return(View("Login", new LoginModel())); } TempData[Enums.NotifyType.Error.GetDescription()] = "Something went wrong. Please try again later."; return(View("ResetPassword")); }
public string UpdateRate(IEnumerable <InvoiceSlittingList> slittingList) { try { using (PolyFilmsContext context = BaseContext.GetDbContext()) { foreach (InvoiceSlittingList rate in slittingList) { TblSlitting currentModel = context.Set <TblSlitting>().Find(rate.SlittingId); currentModel.UnitPrice = rate.UnitPrice; currentModel.TotalPrice = rate.UnitPrice * currentModel.Netweight; _repository.Update(currentModel, context); } context.SaveChanges(); } return(string.Empty); } catch (Exception ex) { return(CommonHelper.GetErrorMessage(ex)); } }
public IActionResult ForgotPassword(string Email) { try { TblUser model = _service.GetByEmail(Email); string token = Guid.NewGuid().ToString(); if (model.UserId > 0) { string link = Url.Action("ResetPassword", "Login", new RouteValueDictionary(new { Token = token }), HttpHelper.HttpContext.Request.Scheme); string resetLink = "<a href='" + link + "'>" + link + "</a>"; string toEmail = model.EmailAddress; string file = System.IO.Path.Combine(_env.WebRootPath, "MailTemplate/ForgotPassword.html"); string bodyTemplate = System.IO.File.ReadAllText(file); bodyTemplate = bodyTemplate.Replace("[@FirstName]", model.Name); bodyTemplate = bodyTemplate.Replace("[@link]", resetLink); Task task = new Task(() => EmailHelper.SendAsyncEmail(toEmail, resLabels.ForgotPassword, bodyTemplate, true)); task.Start(); model.Token = token; model.TokenExpiryDateTime = DateTime.Now.AddDays(1); using (PolyFilmsContext contex = BaseContext.GetDbContext()) { contex.TblUser.Update(model); contex.SaveChanges(); } TempData[Enums.NotifyType.Success.GetDescription()] = "Email For Reset Passsword has been sent. Please check your email."; return(View("Login")); } TempData[Enums.NotifyType.Error.GetDescription()] = "Invalid Email Address."; return(View()); } catch (Exception ex) { return(Json(CommonHelper.GetErrorMessage(ex))); } }