public static HousingViewModel Create(Housing building, bool isAuth) { var model = new HousingViewModel() { Street = building.Street.Name, District = building.District.Name, DistrictId = building.DistrictId, CityId = building.CityId, Phone = isAuth ? (building.Phones.FirstOrDefault()?.Number ?? string.Empty) : (string.Empty), HouseTypeId = building.TypesHousing.Id, HouseType = building.TypesHousing.Name, Price = (int)building.Sum, Description = building.Comment, RentId = building.Id, CityName = building.City.Name }; return model; }
public static HousingEditModel Create(ApplicationDbContext context, Housing housing, ClaimsPrincipal user) { var typesHousings = context.TypesHousing.ToList(); return Create(housing, typesHousings, user); }
private static void UpdatePhone(Housing item, int order, string phone) { var housingPhone = item.Phones.SingleOrDefault(x => x.Order == order); if (housingPhone != null) { housingPhone.Number = phone; } else if(!string.IsNullOrEmpty(phone)) { housingPhone = new HousingPhone { Number = phone, Order = order }; item.Phones.Add(housingPhone); } }
public void UpdateEntity(Housing item) { item.FirstName = FirstName; item.MidleName = MidleName; item.LastName = LastName; item.Sum = Cost; item.Comment = Comment; item.CityId = CityId; item.DistrictId = DistrictId; item.StreetId = StreetId; item.House = HouseNumber; item.Building = HouseBuilding; item.Room = Room; item.TypesHousingId = HouseTypeId; item.EndDate = EndDate; item.IsArchive = IsArchived; item.PartherShip = IsPartnerShip; UpdatePhone(item, 0, Phone1); UpdatePhone(item, 1, Phone2); UpdatePhone(item, 2, Phone3); }
public static HousingEditModel Create(Housing housing, List<TypesHousing> typesHousings, ClaimsPrincipal user) { var item = new HousingEditModel { EditId = housing.Id, Comment = housing.Comment, FirstName = housing.FirstName, LastName = housing.LastName, MidleName = housing.MidleName, Cost = housing.Sum, EndDate = housing.EndDate, Phone1 = housing.Phones.SingleOrDefault(x => x.Order == 0)?.Number, Phone2 = housing.Phones.SingleOrDefault(x => x.Order == 1)?.Number, Phone3 = housing.Phones.SingleOrDefault(x => x.Order == 2)?.Number, HouseNumber = housing?.House, HouseBuilding = housing?.Building, Room = housing?.Room, IsArchived = housing.IsArchive, IsPartnerShip = housing.PartherShip, HouseType = housing.TypesHousing?.Name ?? "Не указано", HouseTypeId = housing.TypesHousingId, CityId = housing.CityId, DistrictId = housing.DistrictId, StreetId = housing.StreetId, Calls = housing.Calls.Select(HousingCallViewModel.Create).ToList() }; var addressParts = new List<string>(); if (housing.City != null) { addressParts.Add(housing.City.Name); } if (housing.District != null) { addressParts.Add(housing.District.Name); } if (housing.Street != null) { addressParts.Add(housing.Street.Name); } addressParts.Add(housing.House); addressParts.Add(housing.Building); addressParts.Add(housing.Room); item.FullAddress = addressParts.Where(x => !string.IsNullOrEmpty(x)).Aggregate("", (x, y) => x + ", " + y).Trim(','); return item; }
private static Housing CreateHousingRadnom(ApplicationDbContext DbContext) { var houseType = DbContext.TypesHousing.ToList()[Random.Next(0, DbContext.TypesHousing.Count())]; var city = DbContext.Cities.ToList()[Random.Next(0, DbContext.Cities.Count())]; ; var district = DbContext.Districts.ToList()[Random.Next(0, DbContext.Districts.Count())]; ; var street = DbContext.Streets.ToList()[Random.Next(0, DbContext.Streets.Count())]; ; var sum = Random.Next(5, 30) * 1000; Housing item = new Housing() { City = city, Street = street, District = district, TypesHousing = houseType, Comment = Descriptions[Random.Next(0, Descriptions.Length)], Sum = sum, Phones = new List<HousingPhone> { new HousingPhone { Number = "+123456789" } } }; return item; }
public IActionResult Create(HousingEditModel housing) { if (ModelState.IsValid) { var newHousingItem = new Housing() { Phones = new List<HousingPhone>() }; housing.UpdateEntity(newHousingItem); _context.Housing.Add(newHousingItem); _context.SaveChanges(); return RedirectToAction("Index"); } return View("Save", housing); }
public IActionResult Create() { var city = User.IsInRole(RoleNames.Employee) ? CurrentUser?.City : _context.Cities.Include(x => x.Districts).FirstOrDefault(); var housing = new Housing() { City = city, CityId = city?.Id ?? 0, Phones = new List<HousingPhone>(), Calls = new List<HousingCall>() }; var model = HousingEditModel.Create(_context, housing, User); return View("Save", model); }