예제 #1
0
        public int AddTimeline(Timeline timeline, IEnumerable<HttpPostedFileBase> Images = null, List<int> Countries = null)
        {
            DbContext.Timelines.Add(timeline);
            try
            {
                if (Countries != null)
                {
                    timeline.Countries = new List<Country>();
                    foreach (int c in Countries)
                    {
                        Country country = DbContext.Countries.Where(cc => cc.ID == c).FirstOrDefault();
                        if (country != null)
                            timeline.Countries.Add(country);
                    }
                }

                DbContext.SaveChanges();
                if (timeline.ID > 0 && Images != null && Images.Count() > 0 && Images.Where(i => i != null).Count() > 0)
                {
                    AddTimelineImages(timeline.ID, Images);
                }
                return timeline.ID;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        public ActionResult New(Timeline timeline, IEnumerable<HttpPostedFileBase> Images, List<int> TCountries)
        {
            ViewBag.MainNav = Navigator.Main.TIMELINE;
            FillCountries(TCountries);

            if (ModelState.IsValid)
            {
                 if (Images != null && Images.Count() > 0 && !ImageService.IsValid(Images))
                 {
                     TempData["ErrorMessage"] = "Item Failed To Add, Invalid Image File";
                 }
                 else
                 {
                     int new_id = timelineService.AddTimeline(timeline, Images, TCountries);

                    if (new_id > 0)
                    {
                        TempData["SuccessMessage"] = "Timeline Item Added Successfully";
                        return RedirectToAction("Edit", new { id = new_id });
                    }
                    else
                        TempData["ErrorMessage"] = "Timeline Item Failed To Add";
               }
            }
            return View();
        }
예제 #3
0
        public int UpdateTimeline(Timeline timeline, IEnumerable<HttpPostedFileBase> Images = null, List<int> Countries = null)
        {
            Timeline T = DbContext.Timelines.Where(a => a.ID == timeline.ID).Include(a => a.Countries).FirstOrDefault();

            if (T == null)
                return -1;

            T.Description = timeline.Description;
            T.order = timeline.order;
            T.Period = timeline.Period;
            T.Title = timeline.Title;
            T.Type = timeline.Type;

            T.DescriptionAr = timeline.DescriptionAr;
            T.PeriodAr = timeline.PeriodAr;
            T.TitleAr = timeline.TitleAr;

            try
            {
                DbContext.SaveChanges();

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

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

                if (T.ID > 0 && Images != null && Images.Where(i => i != null).Count() > 0)
                {
                    if (T.ImageURL != null && T.ImageURL != "")
                    {
                        ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + T.ImageURL));
                        ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + T.ImageURL), TimelineImageWidth.ToString(), TimelineImageHeight.ToString());
                    }
                    AddTimelineImages(T.ID, Images);
                }
                return T.ID;
            }
            catch (Exception ex)
            {
                return -1;
            }

        }