public async Task <ActionResult> Register(RegisterAdmin reg) { reg.Email.Trim(); AbzContext db = new AbzContext(); Usr user = new Usr(); user.Email = reg.Email; string Password = GenerateRandomPassword(6); user.Password = Password; user.UserId = Guid.NewGuid().ToString(); db.Users.Add(user); db.SaveChanges(); UserInCust uc = new UserInCust(); uc.CustID = reg.CustId; uc.UserId = user.UserId; uc.LastDat = DateTime.Now; uc.Email = reg.Email; //uc.Pwd = Password; db.UserInCusts.Add(uc); db.SaveChanges(); await EmailSend.EMailRegAsync(reg.Email, Password); return(RedirectToAction("Index", "Home")); }
public void SetDafault(AbzHash hash) { CustRepository repo = new CustRepository(); string usr = hash.Email; hash.CustID = db.UserAdmins.FirstOrDefault(u => u.Email == usr).CustID; hash.ContractID = repo.GetContract((int)hash.CustID).ContractID; db.AbzHashes.Add(hash); db.SaveChanges(); }
public ActionResult CustSearch(int id) { AbzContext context = new AbzContext(); CustRepository repo = new CustRepository(); Cust cust; cust = repo.Get(id); UserInCust usr = new UserInCust(); usr.CustID = cust.CustId; usr.Inn = cust.Inn; usr.UserId = UserID; usr.Email = abzHash.Email; usr.LastDat = DateTime.Now; context.UserInCusts.Add(usr); context.SaveChanges(); ////Теперь надо прописать в юзера //ApplicationUser user = UserManager.FindById(usr.UserId); //user.CustID = cust.CustId; //UserManager.Update(user); //ViewBag.UserName = user.UserName; return(View(cust)); }
public ActionResult DelVisible(int id) { Good good = db.Goods.Find(id); good.to_site = 1; db.SaveChanges(); return(RedirectToAction("Index", "Good")); //, new { act = "Products", cont = "Admin" }); }
public ActionResult NewAdres(Adres adres) { adres.CustId = Menu.CustId; db.Adreses.Add(adres); db.SaveChanges(); ShipView order = (ShipView)Session["Order"]; int sid = order.ShipViewId; return(RedirectToAction("Edit", "VShips", new { id = sid })); }
public void delete(int id) { TrustTecDet tecDet = db.TrustTecDets.Find(id); TrustTec tec = db.TrustTecs.Find(tecDet.TrustTecId); int cnt = db.TrustTecDets.Count(c => c.TrustTecId == tec.TrustTecId); if (cnt < 2) { db.TrustTecs.Remove(tec); } db.TrustTecDets.Remove(tecDet); db.SaveChanges(); }
public virtual void Added(TEntity entity) { dbcontext.Configuration.AutoDetectChangesEnabled = false; dbcontext.Entry(entity).State = EntityState.Added; dbcontext.ChangeTracker.DetectChanges(); dbcontext.SaveChanges(); dbcontext.Configuration.AutoDetectChangesEnabled = true; }
public void CustUser(string userId, int custId, string ip, string adres) { Statistic statistic = new Statistic(); statistic.CustID = custId; statistic.UserId = userId; statistic.UserAdres = ip; statistic.UserHost = adres; db.Statistics.Add(statistic); UserInCust userInCust = db.UserInCusts.FirstOrDefault(u => u.UserId == userId && u.CustID == custId); if (userInCust != null) { userInCust.LastDat = DateTime.Now; db.Entry(userInCust).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { AbzContext db = new AbzContext(); Usr user = db.Users.FirstOrDefault(u => u.Email == model.Email); if (user == null) { return(View("Error")); } string NewPassword = GenerateRandomPassword(6); user.Password = NewPassword; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); EmailSend.EMailFPassw(model.Email, NewPassword); return(View("ForgotPasswordConfirmation")); } return(View(model)); }
public async Task <ActionResult> Register(RegisterAdmin reg) { //Отладка //EmailSend.EMailReg("*****@*****.**", "123"); //return View("NoRegister"); AbzContext db = new AbzContext(); var user = new ApplicationUser { UserName = reg.Email, Email = reg.Email, CustID = reg.CustId }; string Password = GenerateRandomPassword(6); var result = UserManager.Create(user, Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "CustManager"); SignInManager.SignIn(user, isPersistent: false, rememberBrowser: false); UserInCust uc = new UserInCust(); uc.CustID = reg.CustId; uc.UserId = user.Id; uc.LastDat = DateTime.Now; db.UserInCusts.Add(uc); db.SaveChanges(); await EmailSend.EMailRegAsync(reg.Email, Password); //EmailSend.EMailRegAsync(reg.Email, Password); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Отправка сообщения электронной почты с этой ссылкой // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>"); return(RedirectToAction("Index", "Home")); } return(View("NoRegister")); }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } AbzHashRepo hashRepo = new AbzHashRepo(); string auth = GetCookie("Auth"); AbzHash abzHash = hashRepo.GetHash(auth); AbzContext db = new AbzContext(); Usr usr = db.Users.FirstOrDefault(u => u.Email == abzHash.Email); if ((usr != null) && (usr.Password == model.OldPassword)) { usr.Password = model.NewPassword; db.Entry(usr).State = EntityState.Modified; db.SaveChanges(); await EmailSend.EMailRegAsync(abzHash.Email, model.NewPassword); } return(RedirectToAction("Index", "Home")); }
public InvoiceView Insert(InvoiceView invSession) { Invoice invoice = new Invoice(); invoice.GoodId = invSession.GoodId; invoice.CustId = custID; invoice.Quant = invSession.Quant; Price price = GetPrice(invoice.GoodId); invSession.Price = price.Nprice; invoice.Sm = invoice.Quant * invSession.Price; invSession.Sm = invoice.Sm; //Num num = db.Nums.First(n => n.NumId == 2); //invoice.Num = num.NumT; //invSession.Num = invoice.Num; //num.NumT = num.NumT + 1; //if (invParam.ContractView != null) //{ // //ContractRepository contract = new ContractRepository(custID); // Contract contr; // invoice.ContractID = Convert.ToInt32(invParam.ContractView.SelectedID); // contr = contract.GetContract(invoice.ContractID); // invSession.ContractNum = contr.Num; //} db.Invoices.Add(invoice); db.SaveChanges(); return(invSession); }