public ActionResult SignIn(string Login, string Password, bool SaveToCookies, bool redirectToIndex = false, bool manual = true) { Debug.WriteLine("Trying to sign in"); Debug.WriteLine("Login:"******"Password:"******"Index", "Home")); } } } if (redirectToIndex) { Session[GlobalResources.SiteResources.Last_Url] = "/Home/Index"; } else { Session[GlobalResources.SiteResources.Last_Url] = System.Web.HttpContext.Current.Request.UrlReferrer.AbsolutePath; } Session[GlobalResources.SiteResources.Last_sing_in_error] = new Tuple <string, string>(Source, Message); if (manual) { return(RedirectToAction("FailedLogIn")); } else { return(RedirectToAction("Index")); } }
public ActionResult Add(Models.EDM.User user) { Check(user); if (ModelState.IsValid) { dataManager.UsersRepos.Add(user.UserType, user.Login, user.Password, out string Res); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(Models.EDM.User user) { Check(user); if (ModelState.IsValid) { dataManager.UsersRepos.Change(user.Id, user.UserType, user.Login, user.Password, out string Res); return(RedirectToAction("Index")); } ViewData.Model = dataManager.UsersRepos.Find(user.Id); return(View()); }
public void Check(Models.EDM.User user) { if (string.IsNullOrWhiteSpace(user.Login)) { ModelState.AddModelError("Login", GlobalResources.SiteResources.PleaseInput + GlobalResources.SiteResources.User_Login); } if (string.IsNullOrWhiteSpace(user.Password)) { ModelState.AddModelError("Password", GlobalResources.SiteResources.PleaseInput + GlobalResources.SiteResources.User_Password); } }
public ActionResult SignUp(Models.EDM.User user) { Check(user); if (ModelState.IsValid) { bool res = dataManager.UsersRepos.Add(Models.EDM.UserType.Normal, user.Login, user.Password, out string Res); if (res) { return(SignIn(user.Login, user.Password, true, true)); } else { ModelState.AddModelError("Login", Res); } } return(View()); }
public ActionResult SignIn(string Login, string Password, string SaveMe) { bool Save = SaveMe != null && SaveMe == "on"; if (string.IsNullOrEmpty(Login)) { ModelState.AddModelError("Login", "Логин не заполнен"); } if (string.IsNullOrEmpty(Password)) { ModelState.AddModelError("Password", "Пароль не заполнен"); } if (!ModelState.IsValid) { return(View()); } Models.EDM.User user = _DataManager.UserRepo.GetUser(Login); if (user == null) { ModelState.AddModelError("Login", "Пользователь не найден"); } if (!ModelState.IsValid) { return(View()); } if (user?.Password != Password) { ModelState.AddModelError("Password", "Пароль введён неверно"); } if (ModelState.IsValid) { Session["UserLogin"] = Login; Session["UserAdmin"] = user.AdminPrivileges.ToString().ToLower(); Session["UserFullName"] = user.FullName; HttpCookie aCookie = Request.Cookies["userInfo"]; if (aCookie == null && Save) { aCookie = new HttpCookie("userInfo"); aCookie.Values["UserLogin"] = Login; aCookie.Values["UserPass"] = Password; aCookie.Values["LastVisit"] = DateTime.Now.ToString(); aCookie.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(aCookie); } if (user.AdminPrivileges) { return(RedirectToAction("Index", "Admin")); } return(RedirectToAction("Index", "User")); } return(View()); }
public ActionResult Index(Models.UtilityModels.OperatorViewModel operatorViewModel) { string City, House, Street; Check(operatorViewModel.Flat, operatorViewModel.FIO, operatorViewModel.Passport, operatorViewModel.PhoneNumber, operatorViewModel.IsCompany, operatorViewModel.CompanyName, operatorViewModel.INN, operatorViewModel.FullAddress); if (dataManager.AddressRepos.ParseAddress(operatorViewModel.FullAddress, out City, out Street, out House) && ModelState.IsValid) { Models.EDM.City city = dataManager.CityRepos.Select(x => x.Name == City).FirstOrDefault(); if (city == null) { throw new Exception("Данный город не поддерживается :("); } Models.EDM.Street street = dataManager.StreetRepos.Select(x => x.Name == Street && x.City.Id == city.Id).FirstOrDefault(); if (street == null) { dataManager.StreetRepos.Street(Street, city, out string Res); street = dataManager.StreetRepos.Select(x => x.Name == Street && x.City.Id == city.Id).FirstOrDefault(); } Models.EDM.House house = dataManager.HouseRepos.Select(x => x.Number == House && x.Street.Id == street.Id).FirstOrDefault(); if (house == null) { dataManager.HouseRepos.Add(House, street, out string Res); house = dataManager.HouseRepos.Select(x => x.Number == House && x.Street.Id == street.Id).FirstOrDefault(); } Models.EDM.Address address = dataManager.AddressRepos.Select(x => x.Flat == operatorViewModel.Flat && x.House.Id == house.Id).FirstOrDefault(); if (address == null) { dataManager.AddressRepos.Add(operatorViewModel.Flat, house, out string Res); address = dataManager.AddressRepos.Select(x => x.Flat == operatorViewModel.Flat && x.House.Id == house.Id).FirstOrDefault(); } Models.EDM.Customer customer; if (operatorViewModel.IsCompany) { customer = dataManager.CustomerRepos.Select(x => (x is Models.EDM.Company) && x.Passport == operatorViewModel.Passport && ((Models.EDM.Company)x).INN == operatorViewModel.INN).FirstOrDefault(); } else { customer = dataManager.CustomerRepos.Select(x => x.Passport == operatorViewModel.Passport && !(x is Models.EDM.Company)).FirstOrDefault(); } if (customer == null) { if (operatorViewModel.IsCompany) { dataManager.CompanyRepos.Add(operatorViewModel.FIO, operatorViewModel.Passport, operatorViewModel.PhoneNumber, operatorViewModel.CompanyName, operatorViewModel.INN, out string Res); customer = dataManager.CustomerRepos.Select(x => (x is Models.EDM.Company) && x.Passport == operatorViewModel.Passport && ((Models.EDM.Company)x).INN == operatorViewModel.INN).FirstOrDefault(); } else { dataManager.CustomerRepos.Add(operatorViewModel.FIO, operatorViewModel.Passport, operatorViewModel.PhoneNumber, out string Res); customer = dataManager.CustomerRepos.Select(x => x.Passport == operatorViewModel.Passport && !(x is Models.EDM.Company)).FirstOrDefault(); } } Models.EDM.User user = Session[GlobalResources.SiteResources.User] as Models.EDM.User; dataManager.OrderRepos.Add( dataManager.UsersRepos.Find(user.Id), dataManager.CustomerRepos.Select(x => x.Id == customer.Id).First(), dataManager.AddressRepos.Find(address.Id), out string res, out int result); var order = dataManager.OrderRepos.Find(result); var status = dataManager.StatusRepos.Find(1); if (operatorViewModel.MetersCounts != null) { var Meters = dataManager.MeterRepos.Select(x => true).ToArray(); for (int i = 0; i < operatorViewModel.MetersCounts.Count; i++) { for (int j = 0; j < operatorViewModel.MetersCounts[i]; ++j) { dataManager.OrderEntryRepos.Add(order, DateTime.Now, null, null, dataManager.MeterRepos.Find(Meters[i].Id), null, status, out string Res); } } } } ViewData[GlobalResources.SiteResources.Meter] = dataManager.MeterRepos.Select(x => true); int count = (ViewData[GlobalResources.SiteResources.Meter] as IEnumerable <Models.EDM.Meter>).Count(); return(View()); }
public ActionResult Delete(Models.EDM.User user) { dataManager.UsersRepos.Remove(user.Id, out string Res); return(RedirectToAction("Index")); }