//===================== Apartments CSV Import=======================
        public async Task<ActionResult> ProcessCsv(EventItem[] model)
        {
            int BuildingID = (int)Session["BuildingID"];

            if (ModelState.IsValid)

                //if(User.Identity.IsAuthenticated)
                {
                    {
                        foreach (var item in model)
                        {
                            var apartment = new Apartment
                             {
                                 ApartmentNumber = item.AparmentNumber,
                                 BuildingID = BuildingID,
                                 FloorNumber = item.Floor
                             };
                            db.Apartment.Add(apartment);
                            await db.SaveChangesAsync();

                            //======================insert Add Building Activity================
                            var UserID = User.Identity.GetUserId();// gets logged user ID
                            AspNetUsers myUser =  await db.AspNetUsers.FirstOrDefaultAsync(c => c.Id == UserID);// select from db where logged use match
                            var newActivity = new UserActivityLog
                           {
                               BuildingID = BuildingID,
                               UserID = "84a4092e-0bcc-4e4f-b007-c87a99eccae3",
                               DateOfEvent = DateTime.Now,
                               FunctionPerformed = "Added apartment",
                               Message = "Apartment # "+ item.AparmentNumber +" was added by " + myUser.UserName
                           };
                            db.UserActivityLog.Add(newActivity);
                           await db.SaveChangesAsync();
                        }
                    }
                }
            
            return RedirectToAction("BuildingProfile", "Building");
        }
        public ActionResult deleteApartment(Apartment model, int id)
        {

            if (ModelState.IsValid) {
                var b = db.Apartment.Find(id);
                db.Apartment.Remove(b);
                db.SaveChanges();
            }
            return RedirectToAction("BuildingProfile", new { BuildingID = model.BuildingID });
        
        }
        public async Task<ActionResult> AddApartment(ApartmentVM apartmentvm, int buildingID)
        {
            
            
            if (ModelState.IsValid)
            { 
                //if (User.Identity.IsAuthenticated)
                //{
                 
                        var apartment = new Apartment
                          {
                              ApartmentNumber = apartmentvm.ApartmentNumber,
                              BuildingID =buildingID,
                              FloorNumber = apartmentvm.FloorNumber
                          };
                        db.Apartment.Add(apartment);
                        await db.SaveChangesAsync();

                        //======================insert Add Building Activity================
                        //var UserID = User.Identity.GetUserId();// gets logged user ID
                        //AspNetUsers myUser = await db.AspNetUsers.FirstOrDefaultAsync(c => c.Id == UserID);select from db where logged use match
                        //var newActivity = new UserActivityLog
                        //{
                        //    BuildingID = BuildingID,
                        //    UserID = User.Identity.GetUserId(),
                        //    DateOfEvent = DateTime.Now,
                        //    FunctionPerformed = "Added apartment",
                        //    Message = "Apartment # " + apartmentvm.ApartmentNumber + " was added by " + myUser.UserName
                        //};
                        //db.UserActivityLog.Add(newActivity);
                        //await db.SaveChangesAsync();
                   
            }
                //}
            return RedirectToAction("BuildingProfile", "Building", new { BuildingID = buildingID});
        }