public ActionResult CreateLocation(Location location, FormCollection form)
        {
            if (NotAllowedHere()) return RedirectAway();

            if (ModelState.IsValid)
            {
                var theOldPost = _locationRepo.FindByID(location.ID);
                if (theOldPost == null)
                    theOldPost = location;
                if (theOldPost.Images == null)
                    theOldPost.Images = new List<Image>();
                var oldImages = theOldPost.Images.ToList();
                var listOfImagesPaths = form["image"];
                string[] arrayOfImagesPaths = null;
                if (listOfImagesPaths != null)
                    arrayOfImagesPaths = listOfImagesPaths.Split(',');

                oldImages = theOldPost.Images.ToList();
                if (arrayOfImagesPaths != null && arrayOfImagesPaths.Count() > 0)
                {
                    foreach (var addedimg in _imgRepo.FindAll(c =>
                arrayOfImagesPaths.Any(cat => cat == c.ImagePath.ToString()) &&
                !c.Posts.Any(p => p.ID == theOldPost.ID)).ToList())
                        theOldPost.Images.Add(addedimg);
                }
                foreach (var removedimg in oldImages.Where(c => arrayOfImagesPaths
                == null || !arrayOfImagesPaths.Any(cat2 => cat2 == c.ImagePath.ToString())))
                    theOldPost.Images.Remove(removedimg);
                _locationRepo.Save(location);

                return RedirectToAction("ListLocations");
            }

            return View(location);
        }
        public ActionResult CreateLocation(Location location)
        {
            if (NotAllowedHere()) return RedirectAway();

            if (ModelState.IsValid)
            {
                (new Repository<Location>()).Save(location);

                return RedirectToAction("ListLocations");
            }

            return View(location);
        }
        public ActionResult _FileUploadPartial(int postID = -1,  int categoryID = -1, int eventID = -1, int locationID = -1, bool badges = false)
        {
            var fuVM = new FileUploadViewModel();

            Post post = new Post();
            Category category = new Category();
            Event Event = new Event();
            Location Location = new Location();
            if (badges == true) {
                fuVM.Badges = true;
            }

            if (postID != -1) {
                post = _postRepo.FindAll().Where(p => p.ID == postID).Include(i => i.Images).Include(b => b.Badges).FirstOrDefault();
                fuVM.post = post;
            } if (categoryID != -1)
            {
                category = _categoryRepo.FindByID(categoryID);
                fuVM.Category = category;
            } if (eventID != -1)
            {
                Event = _eventRepo.FindByID(eventID);
                fuVM.Event = Event;
            } if (locationID != -1)
            {
                Location = _locationRepo.FindByID(locationID);
                fuVM.Location = Location;
            }
            var uploadedFiles = new List<UploadedFile>();

            var files = Directory.GetFiles(Server.MapPath("~/Content/image-uploads"));

            foreach (var file in files)
            {

                var uploadedFile = new UploadedFile() { Title = Path.GetFileName(file) };

                uploadedFile.PathUrl = ("/Content/image-uploads/") + Path.GetFileName(file);
                if (_imgRepo.FindAll().Where(i => i.ImagePath == uploadedFile.PathUrl).FirstOrDefault() == null)
                {
                    Image imageObj = new Image();
                    imageObj.ImagePath = uploadedFile.PathUrl;
                    _imgRepo.Save(imageObj);
                }

                var fileInfo = new FileInfo(file);
                if (postID >= 1 && (badges == false)) {
                        foreach (var postimage in post.Images)
                        {
                            if (postimage.ImagePath == uploadedFile.PathUrl)
                            {
                                uploadedFile.Checked = true;
                            }
                        }
                } if (postID >= 1 && (badges == true))
                {
                    foreach (var badgeImage in post.Badges)
                    {
                        if (badgeImage.ImagePath == uploadedFile.PathUrl)
                        {
                            uploadedFile.Checked = true;
                        }
                    }
                } if (categoryID >= 1)
                {
                        foreach (var categoryimage in category.Images)
                        {
                            if (categoryimage.ImagePath == uploadedFile.PathUrl)
                            {
                                uploadedFile.Checked = true;
                            }
                        }
                } if (eventID >= 1)
                {
                    foreach (var eventimage in Event.Images)
                    {
                        if (eventimage.ImagePath == uploadedFile.PathUrl)
                        {
                            uploadedFile.Checked = true;
                        }
                    }
                } if (locationID >= 1)
                {

                    foreach (var locationimage in Location.Images)
                    {
                        if (locationimage.ImagePath == uploadedFile.PathUrl)
                        {
                            uploadedFile.Checked = true;
                        }
                    }
                }

                uploadedFiles.Add(uploadedFile);
            }
            fuVM.UploadedFiles = uploadedFiles;

            return PartialView("_FileUploadPartialView", fuVM);
        }
        public ActionResult EditLocation(Location location)
        {
            if (NotAllowedHere()) return RedirectAway();
            if (ModelState.IsValid)
            {
                _locationRepo.Save(location);

                return RedirectToAction("ListLocations");
            }

            return View(location);
        }