Exemplo n.º 1
0
        public ActionResult Edit(AlbumEdit model)
        {
            if (!OptionalDateTime.IsValid(model.ReleaseYear, model.ReleaseDay, model.ReleaseMonth))
            {
                ModelState.AddModelError("ReleaseYear", "Invalid date");
            }

            var coverPicUpload = Request.Files["coverPicUpload"];
            PictureDataContract pictureData = ParseMainPicture(coverPicUpload, "CoverPicture");

            ParseAdditionalPictures(coverPicUpload, model.Pictures);

            if (!ModelState.IsValid)
            {
                var oldContract = Service.GetAlbumForEdit(model.Id);
                model.CopyNonEditableFields(oldContract);
                return(View(model));
            }

            var contract = model.ToContract();

            Service.UpdateBasicProperties(contract, pictureData);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Exemplo n.º 2
0
        public ActionResult Edit(AlbumEditViewModel viewModel)
        {
            var model = viewModel.EditedAlbum;

            // Note: name is allowed to be whitespace, but not empty.
            if (model.Names.All(n => string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Names", AlbumValidationErrors.UnspecifiedNames);
            }

            if (!OptionalDateTime.IsValid(model.OriginalRelease.ReleaseDate.Year, model.OriginalRelease.ReleaseDate.Day, model.OriginalRelease.ReleaseDate.Month))
            {
                ModelState.AddModelError("ReleaseYear", "Invalid date");
            }

            var coverPicUpload = Request.Files["coverPicUpload"];
            var pictureData    = ParsePicture(coverPicUpload, "CoverPicture");

            if (coverPicUpload == null)
            {
                AddFormSubmissionError("Cover picture was null");
            }

            if (model.Pictures == null)
            {
                AddFormSubmissionError("List of pictures was null");
            }

            if (coverPicUpload != null && model.Pictures != null)
            {
                ParseAdditionalPictures(coverPicUpload, model.Pictures);
            }

            try {
                viewModel.CheckModel();
            } catch (InvalidFormException x) {
                AddFormSubmissionError(x.Message);
            }

            if (!ModelState.IsValid)
            {
                return(View(new AlbumEditViewModel(Service.GetAlbum(model.Id), PermissionContext, model)));
            }

            queries.UpdateBasicProperties(model, pictureData);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Exemplo n.º 3
0
        public ActionResult Edit(AlbumEditViewModel viewModel)
        {
            // Unable to continue if viewmodel is null because we need the ID at least
            if (viewModel == null || viewModel.EditedAlbum == null)
            {
                log.Warn("Viewmodel was null");
                return(HttpStatusCodeResult(HttpStatusCode.BadRequest, "Viewmodel was null - probably JavaScript is disabled"));
            }

            try {
                viewModel.CheckModel();
            } catch (InvalidFormException x) {
                AddFormSubmissionError(x.Message);
            }

            var model = viewModel.EditedAlbum;

            // Note: name is allowed to be whitespace, but not empty.
            if (model.Names != null && model.Names.All(n => n == null || string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Names", AlbumValidationErrors.UnspecifiedNames);
            }

            if (model.OriginalRelease != null && model.OriginalRelease.ReleaseDate != null && !OptionalDateTime.IsValid(model.OriginalRelease.ReleaseDate.Year, model.OriginalRelease.ReleaseDate.Day, model.OriginalRelease.ReleaseDate.Month))
            {
                ModelState.AddModelError("ReleaseYear", "Invalid date");
            }

            var coverPicUpload = Request.Files["coverPicUpload"];
            var pictureData    = ParsePicture(coverPicUpload, "CoverPicture");

            if (coverPicUpload == null)
            {
                AddFormSubmissionError("Cover picture was null");
            }

            if (model.Pictures == null)
            {
                AddFormSubmissionError("List of pictures was null");
            }

            if (coverPicUpload != null && model.Pictures != null)
            {
                ParseAdditionalPictures(coverPicUpload, model.Pictures);
            }

            if (!ModelState.IsValid)
            {
                return(View(CreateAlbumEditViewModel(model.Id, model)));
            }

            try {
                queries.UpdateBasicProperties(model, pictureData);
            } catch (InvalidPictureException) {
                ModelState.AddModelError("ImageError", "The uploaded image could not processed, it might be broken. Please check the file and try again.");
                return(View(CreateAlbumEditViewModel(model.Id, model)));
            }

            return(RedirectToAction("Details", new { id = model.Id }));
        }