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.Street street) { dataManager.StreetRepos.Remove(street.Id, out string Res); return(RedirectToAction("Index")); }