Ejemplo n.º 1
0
        public IActionResult Update(int id, GlobalImage globalImage, IList <IFormFile> imageUpload)
        {
            var current = Context.GlobalImages.FirstOrDefault(a => a.Id == id);

            if (current != null)
            {
                if (string.IsNullOrEmpty(current.FileLocation))
                {
                    if (System.IO.File.Exists(HostingEnv.WebRootPath + current.FileLocation))
                    {
                        System.IO.File.Delete(HostingEnv.WebRootPath + current.FileLocation);
                    }
                }
                current.Title    = globalImage.Title;
                current.SubTitle = globalImage.SubTitle;
                current.IsActive = globalImage.IsActive;
                if (imageUpload.Any())
                {
                    current.FileLocation = imageUpload.Any()
                        ? imageUpload.ImageUpload(HostingEnv.WebRootPath, false).First().Location
                        : null;
                }
                Context.Update(current);
                Context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult Create(GlobalImage globalImage, IList <IFormFile> imageUpload)
        {
            globalImage.FileLocation = imageUpload.Any()
                ? imageUpload.ImageUpload(HostingEnv.WebRootPath, false).First().Location
                : null;
            Context.Add(globalImage);
            Context.SaveChanges();

            return(RedirectToAction("Index"));
        }