public ActionResult New(Source source, IEnumerable<HttpPostedFileBase> Images, IEnumerable<HttpPostedFileBase> Logo)
        {
            ViewBag.MainNav = Navigator.Main.SOURCE;

            if (ModelState.IsValid)
            {
                if (Images != null && Images.Count() > 0 && !ImageService.IsValid(Images))
                 {
                     TempData["ErrorMessage"] = "Source Failed To Add, Invalid Image File";
                 }
                else if (Logo != null && Logo.Count() > 0 && !ImageService.IsValid(Logo))
                {
                    TempData["ErrorMessage"] = "Source Failed To Add, Invalid Logo File";
                }
                 else
                {
                    int new_id = sourceService.AddSource(source, Images, Logo);

                    if (new_id > 0)
                    {
                        TempData["SuccessMessage"] = "Source Added Successfully";
                        return RedirectToAction("Edit", new { id = new_id });
                    }
                    else
                        TempData["ErrorMessage"] = "Source Failed To Add";
                }
                
            }
            return View();
        }
Esempio n. 2
0
        public int AddSource(Source source, IEnumerable<HttpPostedFileBase> Images = null, IEnumerable<HttpPostedFileBase> Logo = null)
        {
            DbContext.Sources.Add(source);
            try
            {
                DbContext.SaveChanges();

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

                if (source.ID > 0 && Logo != null && Logo.Count() > 0 && Logo.Where(i => i != null).Count() > 0)
                {
                    AddSourceLogo(source.ID, Logo);
                }

                return source.ID;
            }
            catch(Exception ex)
            {
                return -1;
            }
        }
Esempio n. 3
0
        public int UpdateSource(Source source, IEnumerable<HttpPostedFileBase> Images = null, IEnumerable<HttpPostedFileBase> Logo = null)
        {
            Source A = DbContext.Sources.Where(a => a.ID == source.ID).FirstOrDefault();

            if (A == null)
                return -1;

            A.Name = source.Name;
            A.NameAr = source.NameAr;

            try
            {
                DbContext.SaveChanges();

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

                if (A.ID > 0 && Logo != null && Logo.Where(i => i != null).Count() > 0)
                {
                    if (A.LogoURL != null && A.LogoURL != "")
                    {
                        ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.LogoURL));
                        ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.LogoURL), 150.ToString(), 80.ToString());
                    }
                    AddSourceLogo(A.ID, Logo);
                }
                return A.ID;
            }
            catch(Exception ex)
            {
                return -1;
            }
           
        }