public ActionResult CustUser(string id) { AbzContext db = new AbzContext(); List <UserAdmin> userincust = db.UserAdmins.Where(d => d.UserId == id).ToList(); return(View(userincust)); }
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 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 TrancportView(int ord, int custid) { AbzContext db = new AbzContext(); this.Transports = db.Transports.Where(p => p.CustID == custid).OrderBy(x => x.Dat).ToList(); OrderId = ord; Centr = true; }
public AdresView(int ord, int custid) { AbzContext db = new AbzContext(); this.Adres = db.Adreses.Where(p => p.CustId == custid).OrderBy(x => x.txt).ToList(); OrderId = ord; Centr = true; }
public DatView(int id) { AbzContext db = new AbzContext(); OrderV order = db.OrderVs.Find(id); OrderId = id; Dat = order.DateExec; CDat = DateToString.CDat(order.DateExec); SmenaID = order.SmenaID; this.Smena = order.Smena; //SelectSmena = new SelectList( db.Smenas.ToList(), "SmenaID", "Name", SmenaID); }
public PersonView(int id) { AbzContext db = new AbzContext(); OrderV order = db.OrderVs.Find(id); OrderId = id; Person = order.Person; PersonId = order.PersonId; List <Person> persons = db.Persons.Where(p => p.CustId == order.CustId | p.PersonId == 0).ToList(); SelectPerson = new SelectList(persons, "PersonId", "Name", PersonId); }
public async Task <ActionResult> DelCust(int id) { //string iduser = (string)Session["usrid"]; AbzContext db = new AbzContext(); UserInCust userInCust = await db.UserInCusts.FindAsync(id); db.UserInCusts.Remove(userInCust); await db.SaveChangesAsync(); return(RedirectToAction("CustUser")); }
//[UserAttribute] //[MyAuthAttribute] public ActionResult LoginPartial() { ViewBag.Login = "******"; string auth = GetCookie("Auth"); if (!String.IsNullOrWhiteSpace(auth)) { AbzContext db = new AbzContext(); AbzHash abzHash = db.AbzHashes.Find(auth); ViewBag.Login = abzHash.Email; } return(PartialView()); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { string auth = GetCookie("Auth", httpContext); if (!String.IsNullOrWhiteSpace(auth)) { AbzContext db = new AbzContext(); AbzHash abzHash = db.AbzHashes.Find(auth); if (abzHash != null) { return(true); } } return(false); }
public ActionResult CustUser(string id) { if (id == null) { id = (string)Session["usrid"]; } var user = UserManager.FindById(id); Session["usrid"] = id; ViewBag.Use = user.UserName; AbzContext db = new AbzContext(); List <UserAdmin> userincust = db.UserAdmins.Where(d => d.UserId == id).ToList(); return(View(userincust)); }
//public async Task<ActionResult> Login(Usr model, string returnUrl) public async Task <ActionResult> Login(Usr model, string rememberme) { AbzContext db = new AbzContext(); AbzHashRepo hashRepo = new AbzHashRepo(); if (!ModelState.IsValid) { return(View(model)); } Usr usr = db.Users.FirstOrDefault(u => u.Email == model.Email && u.Password == model.Password); if (usr == null) { return(View(model)); } if (rememberme == "true") { SetCookie("RememberMe", "true", 365); SetCookie("RememberUser", model.Email, 365); SetCookie("RememberPw", model.Password, 365); } else { SetCookie("RememberMe", "false", 365); DeleteCookie("RememberUser"); DeleteCookie("RememberPw"); } //Зарегить юзера, со значениями по умолчанию AbzHash abzHash = new AbzHash(); abzHash.AbzHashID = Guid.NewGuid().ToString(); abzHash.Email = model.Email; //abzHash.Password = MyCrypto.Shifrovka(model.Password); abzHash.UserId = usr.UserId; abzHash.TerminationDate = DateTime.Now.AddDays(2); string ip = HttpContext.Request.UserHostAddress; abzHash.IP = ip; hashRepo.SetDafault(abzHash); SetCookie("Auth", abzHash.AbzHashID); SetCookie("AuthUser", abzHash.Email); //return RedirectToLocal(returnUrl); return(RedirectToAction("Index", "Home")); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); ViewBag.AuthSuccess = false; db = new AbzContext(); hashRepo = new AbzHashRepo(); abzHash = hashRepo.GetHash(GetCookie("Auth").ToString()); if (abzHash != null) { Cust = db.Custs.Find((int)abzHash.CustID); CustID = (int)abzHash.CustID; UserID = abzHash.UserId; ViewBag.AuthSuccess = true; } }
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 OrderView(Order order) { AbzContext db = new AbzContext(); Good good = db.Goods.Find(order.GoodId); Good = good.txt; Adres adres = db.Adreses.Find(order.AdresId); Adres = adres.txt; Contract contr = db.Contracts.Find(order.ContractID); Contract = contr.Num; Person cnt = db.Persons.Find(order.PersonID); if (cnt != null) { Person = cnt.Name; } Centr = order.Centr; Dat = order.Dat; Quant = order.Quant; Note = order.Note; }
public CRepository() { dbcontext = new AbzContext(); dbset = dbcontext.Set <TEntity>(); }
public CRepository(AbzContext dbcntxt) { dbcontext = dbcntxt; dbset = dbcontext.Set <TEntity>(); }