public ActionResult Edit(Entry entry, int[] selectedCategories, string huKeywords, string enKeywords, string toDeleteFiles)
        {
            var toEditEntry = db.Entries.Where(e => e.Id == entry.Id).First();
            KeywordsProcedure(toEditEntry, huKeywords, enKeywords);

            var attachments = TempData["Attachments"] as List<string>;
            var featuredImage = TempData["FeaturedImage"] as List<string>;

            if (ModelState.IsValid)
            {
                toEditEntry.enContent = entry.enContent;
                toEditEntry.enIntroduction = entry.enIntroduction;
                toEditEntry.enTitle = entry.enTitle;
                toEditEntry.huContent = entry.huContent;
                toEditEntry.huIntroduction = entry.huIntroduction;
                toEditEntry.huTitle = entry.huTitle;
                toEditEntry.IsFeatured = entry.IsFeatured;
                toEditEntry.Published = entry.Published;
                toEditEntry.PublishedDate = entry.PublishedDate;
                toEditEntry.UserId = int.Parse((string)Session["UserId"]);
                toEditEntry.Categories.Clear();
                foreach (var id in selectedCategories.ToList())
                {
                    Category category = db.Categories.Single(e => e.Id == id);
                    toEditEntry.Categories.Add(category);
                }
                //Delete to delete
                List<string> fileNames = new List<string>();
                foreach (var idString in toDeleteFiles.Split(',').Where(e => e != ""))
                {
                    int id = int.Parse(idString);
                    var file = db.Files.Where(e => e.Id == id).First();
                    fileNames.Add(file.Name);
                    toEditEntry.Files.Remove(file);
                    db.Files.Remove(file);
                }
                var ctrl = new UploadController();
                ctrl.PathValue = "/Public/Files/";
                ctrl.Remove(fileNames.ToArray());
                //Add new ones
                if (attachments != null)
                {
                    foreach (var att in attachments)
                    {
                        WebApplication.File newAtt = new WebApplication.File { Entry = toEditEntry, Location = Guid.NewGuid().ToString(), Name = Path.GetFileName(att) };
                        db.Files.Add(newAtt);
                    }
                }
                if (featuredImage != null && featuredImage.Count > 0)
                {
                    string[] fileName = { Path.GetFileName(entry.FeaturedImage) };
                    ctrl.PathValue = "/Public/Images/";
                    ctrl.Remove(fileName);
                    toEditEntry.FeaturedImage = featuredImage[0];
                }
                else if (string.IsNullOrEmpty(entry.FeaturedImage))
                {
                    toEditEntry.FeaturedImage = "";
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                }

                TempData["Attachments"] = null;
                TempData["FeaturedImage"] = null;

                return RedirectToAction("Index");
            }

            ViewBag.Categories = db.Categories.Select(e => e);
            ViewBag.SelectedCategories = selectedCategories.ToList();
            ViewBag.enKeywords = db.Keywords.Where(e => e.Type == true);
            ViewBag.huKeywords = db.Keywords.Where(e => e.Type == false);
            return View(entry);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Entry entry = db.Entries.Single(e => e.Id == id);
            var fileNames = entry.Files.Select(e => e.Name).ToArray();
            var ctrl = new UploadController();
            ctrl.PathValue = "/Public/Files/";
            ctrl.Remove(fileNames.ToArray());

            foreach (var file in entry.Files.ToList())
            {
                db.Files.Remove(file);
            }
            if (!string.IsNullOrEmpty(entry.FeaturedImage))
            {
                string[] filenames = { Path.GetFileName(entry.FeaturedImage) };
                ctrl.PathValue = "/Public/Images/";
                ctrl.Remove(fileNames);

            }
            var categories = entry.Categories.ToList();
            foreach (var category in categories)
            {
                category.Entries.Remove(entry);
            }
            var keywords = entry.Keywords.ToList();
            foreach (var keyword in keywords)
            {
                keyword.Entries.Remove(entry);
                if (keyword.Entries.Count == 0)
                    db.Keywords.Remove(keyword);
            }
            db.Entries.Remove(entry);
            db.SaveChanges();
            return RedirectToAction("Index");
        }