Esempio n. 1
0
        public ActionResult EditPictureProjection(ChangeProjectionPictureViewModel model)
        {
            List <Projection>    allProjections = new List <Projection>();
            ApplicationDbContext dbCtx          = ApplicationDbContext.Create();

            allProjections = dbCtx.Projections.ToList();
            Projection projectionForEdit = new Projection();


            foreach (Projection p in allProjections)
            {
                if (p.Id.Equals(model.Id))
                {
                    if (model.ImageUpload == null)
                    {
                        ModelState.AddModelError("", "Name can not be empty.");
                        return(View(p));
                    }
                    else
                    {
                        var validImageTypes = new string[]
                        {
                            "image/gif",
                            "image/jpeg",
                            "image/pjpeg",
                            "image/png"
                        };

                        if (validImageTypes.Contains(model.ImageUpload.ContentType))
                        {
                            var uploadDir = "~/images/projectionPosters";
                            var imagePath = Path.Combine(Server.MapPath(uploadDir), model.ImageUpload.FileName);
                            var imageUrl  = Path.Combine(uploadDir, model.ImageUpload.FileName);
                            imageUrl = imageUrl.Replace("\\", "/");
                            model.ImageUpload.SaveAs(imagePath);
                            imageUrl = imageUrl.Substring(1);
                            imageUrl = ".." + imageUrl;

                            p.PosterUrl = imageUrl;
                        }

                        projectionForEdit = p;
                    }
                }
            }

            dbCtx.SaveChanges();
            return(EditProjection(projectionForEdit.Id));
        }
Esempio n. 2
0
        public ActionResult ChangePictureProjection(Guid projekcija)
        {
            List <Projection>    allProjections = new List <Projection>();
            ApplicationDbContext dbCtx          = ApplicationDbContext.Create();

            allProjections = dbCtx.Projections.ToList();
            Projection projectionForEdit = new Projection();

            foreach (Projection p in allProjections)
            {
                if (p.Id.Equals(projekcija))
                {
                    projectionForEdit = p;
                }
            }
            ChangeProjectionPictureViewModel vm = new ChangeProjectionPictureViewModel
            {
                Id          = projectionForEdit.Id,
                ImageUpload = null
            };

            return(View("ChangePictureProjection", vm));
        }