Ejemplo n.º 1
0
        public ActionResult New(int? originalId = null, string language = "en")
        {
            ViewBag.MainNav = Navigator.Main.NEWS;
            ViewBag.SubNav = Navigator.Sub.NEWSLIST;

            KeyIssue KI = new KeyIssue();
            KI.PublishDate = DateTime.Now;
            KI.IsInNews = true;
            if (originalId != null)
            {
                KeyIssue ol_keyissue = keyIssueService.GetKeyIssue(originalId.Value);
                KI.OriginalId = originalId;
                KI.Language = language;
                KI.Tags = ol_keyissue.Tags;
                FillTopics(ol_keyissue.TopicID);
                FillAuthors(ol_keyissue.AuthorID);
                FillSources(ol_keyissue.SourceID);
                FillTypes(ol_keyissue.TypeID);
                FillCountries(ol_keyissue.Countries == null ? null : ol_keyissue.Countries.Select(k => k.ID).ToList());
                ViewBag.OriginalVersion = originalId;
            }
            else
            {
                FillTopics(null);
                FillAuthors(null);
                FillSources(null);
                FillTypes(null);
                FillCountries(null);
            }

           
            return View(KI);
        }
Ejemplo n.º 2
0
        public ActionResult New(KeyIssue keyissue, IEnumerable<HttpPostedFileBase> Images, IEnumerable<HttpPostedFileBase> Files, List<string> ArabicTags, List<string> EnglishTags, List<int> KCountries)
        {
            ViewBag.MainNav = Navigator.Main.NEWS;
            ViewBag.SubNav = Navigator.Sub.NEWSLIST;

            FillTopics(keyissue.TopicID);
            FillAuthors(keyissue.AuthorID);
            FillSources(keyissue.SourceID);
            FillTypes(keyissue.TypeID);
            FillCountries(KCountries);

            if (ModelState.IsValid)
            {
                string cleaned_url = URLValidator.CleanURL(keyissue.FriendlyURL);
                
                if (keyIssueService.IsURLExist(cleaned_url, -1))
                {
                    ModelState.AddModelError("FriendlyURL", new Exception());
                    TempData["ErrorMessage"] = "Key Issue Failed To Edit, Friendly URL Already Exist";
                }
                else if (Images != null && Images.Count() > 0 && !ImageService.IsValid(Images))
                 {
                     TempData["ErrorMessage"] = "News Failed To Add, Invalid Image File";
                 }
                else if (!URLValidator.IsValidURLPart(keyissue.FriendlyURL))
                {
                    ModelState.AddModelError("FriendlyURL", new Exception());
                    TempData["ErrorMessage"] = "News Failed To Add, Friendly URL Not Valid";
                }
                 else
                {
                    keyissue.FriendlyURL = cleaned_url;
                    int new_id = keyIssueService.AddKeyIssue(keyissue, ArabicTags, EnglishTags, Images, Files, KCountries);

                    if (new_id > 0)
                    {
                        TempData["SuccessMessage"] = "News Added Successfully";
                        return RedirectToAction("Edit", new { id = new_id });
                    }
                    else
                        TempData["ErrorMessage"] = "News Failed To Add";
                }
                
            }
            return View(keyissue);
        }
Ejemplo n.º 3
0
        public int UpdateKeyIssue(KeyIssue keyissue, List<string> ArabicTags, List<string> EnglishTags, IEnumerable<HttpPostedFileBase> Images = null, IEnumerable<HttpPostedFileBase> Files = null,List<int> Countries = null)
        {
            KeyIssue A = DbContext.KeyIssues.Where(a => a.ID == keyissue.ID).Include(a => a.Tags).Include(a=> a.Countries).FirstOrDefault();

            if (A == null)
                return -1;

            A.AuthorID = keyissue.AuthorID;
            A.Description = keyissue.Description;
            A.FeatureVideoLink = keyissue.FeatureVideoLink;
            A.FriendlyURL = keyissue.FriendlyURL;
            A.IsOnline = keyissue.IsOnline;
            A.MetaDescription = keyissue.MetaDescription;
            A.MetaTitle = keyissue.MetaTitle;
            A.PublishDate = keyissue.PublishDate;
            A.SourceID = keyissue.SourceID;
            A.Title = keyissue.Title;
            A.TopicID = keyissue.TopicID;
            A.IsFeatured = keyissue.IsFeatured;
            A.InScroller = keyissue.InScroller;
            A.TypeID = keyissue.TypeID;
            A.OriginalId = keyissue.OriginalId;
            A.Language = keyissue.Language;
            A.IsHomeVideoFeatured = keyissue.IsHomeVideoFeatured;

            try
            {
                foreach (Tag tag in A.Tags.ToList())
                    DbContext.Tags.Remove(tag);

                A.Tags = new List<Tag>();
                if (ArabicTags != null)
                    foreach (string t in ArabicTags)
                        A.Tags.Add(new Tag() { Name = t, Language = "ar" });
                if (EnglishTags != null)
                    foreach (string t in EnglishTags)
                        A.Tags.Add(new Tag() { Name = t, Language = "en" });
                DbContext.SaveChanges();

                foreach (Country country in A.Countries.ToList())
                    A.Countries.Remove(country);

                if (Countries != null)
                {
                    A.Countries = new List<Country>();
                    foreach (int c in Countries)
                    {
                        Country country = DbContext.Countries.Where(cc => cc.ID == c).FirstOrDefault();
                        if (country != null)
                            A.Countries.Add(country);
                    }
                }
                DbContext.SaveChanges();

                if (A.ID > 0 && Images != null && Images.Where(i => i != null).Count() > 0)
                {
                    if (A.FeatureImageURL != null && A.FeatureImageURL != "")
                    {
                        ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.FeatureImageURL));
                        foreach (ImageSize IS in LogiConfig.KeyIssuesImageSizes)
                            ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.FeatureImageURL), IS.Width.ToString(), IS.Height.ToString());
                    }
                    AddKeyIssueImages(A.ID, Images);
                }

                if (Files != null && Files.Where(f => f != null).Count() > 0)
                {
                    FilesService fs = new FilesService();
                    if (A.FileURL != null && A.FileURL != "")
                    {
                        fs.DeleteFile(A.FileURL);
                    }

                    string file_url = fs.SaveFiles(Files);
                    A.FileURL = file_url;
                    DbContext.SaveChanges();
                }

                return A.ID;
            }
            catch (Exception ex)
            {
                return -1;
            }

        }
Ejemplo n.º 4
0
        public int AddKeyIssue(KeyIssue keyissue, List<string> ArabicTags, List<string> EnglishTags, IEnumerable<HttpPostedFileBase> Images = null, IEnumerable<HttpPostedFileBase> Files = null,List<int> Countries = null)
        {
            DbContext.KeyIssues.Add(keyissue);
            try
            {
                //add tags
                keyissue.Tags = new List<Tag>();
                if (ArabicTags != null)
                    foreach (string t in ArabicTags)
                        keyissue.Tags.Add(new Tag() { Name = t, Language = "ar" });

                if (EnglishTags != null)
                    foreach (string t in EnglishTags)
                        keyissue.Tags.Add(new Tag() { Name = t, Language = "en" });

                if(Countries !=null)
                {
                    keyissue.Countries = new List<Country>();
                    foreach(int c in Countries)
                    {
                        Country country = DbContext.Countries.Where(cc=> cc.ID == c).FirstOrDefault();
                        if (country != null)
                            keyissue.Countries.Add(country);
                    }
                }

                DbContext.SaveChanges();

                if (keyissue.ID > 0 && Images != null && Images.Count() > 0 && Images.Where(i => i != null).Count() > 0)
                {
                    AddKeyIssueImages(keyissue.ID, Images);
                }

                if (Files != null && Files.Where(f => f != null).Count() > 0)
                {
                    FilesService fs = new FilesService();

                    string file_url = fs.SaveFiles(Files);
                    keyissue.FileURL = file_url;
                }
                DbContext.SaveChanges();

                return keyissue.ID;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }