public async Task<ActionResult> BuildingDelete(Buildings model, int BuildingID, int? ClientID)
        {
            if (ModelState.IsValid)
            {
                var mynewbuilding = new Buildings
                {
                     BuildingName = model.BuildingName,
                      Address = model.Address,
                       City =model.City,
                     State = model.City,
                     Zipcode = model.Zipcode,
                     ClientID = ClientID,
                     BuildingPhone = model.BuildingPhone,
                     NumberOfApartment = model.NumberOfApartment,
                     ID = model.ID


                };


                var Entry = db.Entry(mynewbuilding);
                if (Entry.State == EntityState.Detached) 
                { 
                    db.Buildings.Attach(mynewbuilding);
                }
               
                db.Buildings.Remove(mynewbuilding);
                await db.SaveChangesAsync();
            }

            return RedirectToAction("BuildingIndex", new { ClientID = ClientID });
        }
        public async Task<JsonResult> BuildingEdit(Buildings model)
        {
            if (ModelState.IsValid)
            {
                db.Buildings.Attach(model);
                var Entry = db.Entry(model);
                Entry.Property(c => c.BuildingName).IsModified = true;
                Entry.Property(c => c.Address).IsModified = true;
                Entry.Property(c => c.City).IsModified = true;
                Entry.Property(c => c.State).IsModified = true;
                Entry.Property(c => c.Manager).IsModified = true;
                Entry.Property(c => c.Zipcode).IsModified = true;
                Entry.Property(c => c.BuildingPhone).IsModified = true;
                await db.SaveChangesAsync();
            
            }

            var building = db.Buildings.Where(c => c.ID == model.ID).Select(c => new
            {

                BuildingName = c.BuildingName,
                BuildingAddress = c.Address,
                BuildingCity = c.City,
                BuildingState = c.State,
                BuildingZipcode = c.Zipcode,
                BuildingPhone = c.BuildingPhone
            }).FirstOrDefault();

            var mydata = Json(building);
            return new JsonResult { Data = mydata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        
        
        }
        public async Task<JsonResult> AddBuilding(Buildings apartmentvm)
        {if (ModelState.IsValid)
            {
                //if (User.Identity.IsAuthenticated)
                //{
            if(ModelState.IsValid)
            {
                    var apartment = new Buildings
                    {
                        BuildingName = apartmentvm.BuildingName,
                        Address = apartmentvm.Address,
                        BuildingPhone = apartmentvm.BuildingPhone,                      
                        City = apartmentvm.City,
                        State = apartmentvm.State,
                        Zipcode = apartmentvm.Zipcode,
                        Manager = apartmentvm.Manager,
                        ClientID = apartmentvm.ClientID
                    };

                    db.Buildings.Add(apartment);
                    await db.SaveChangesAsync();
                   
                    }  
                //}
            //TODO Exception 
            }
        var CBL = db.Buildings.Where(c => c.Clients.ID == apartmentvm.ClientID).Select(c => new
                {
                    BuildingName = c.BuildingName,
                    BuildingAddress = c.Address + " " + c.City + ", " + c.State + " " + c.Zipcode,
                    Phone = c.BuildingPhone,
                    BuildingID = c.ID

                }).ToList();

                var mydata = Json(CBL);

                return new JsonResult { Data = mydata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }