public IActionResult Edit(HousingEditModel housing, int editId)
        {
            if (ModelState.IsValid)
            {
                var dbItem = _context.Housing.GetFullById(editId);
                housing.UpdateEntity(dbItem);
                _context.Update(dbItem);
                _context.SaveChanges();

                TempData["CrmSuccessMessage"] = "Запись была успешно сохранена";
                return RedirectToAction("Index");
            }

            var errors = ModelState.Values.Where(x => x.Errors.Any()).ToList();
            return View("Save", housing);
        }
        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;
        }
 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);
 }