Esempio n. 1
0
        public ActionResult Edit(SongEditViewModel viewModel)
        {
            var model = viewModel.EditedSong;

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

            if (model.Lyrics.Any(n => string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Lyrics", "Lyrics cannot be empty");
            }

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

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

            queries.UpdateBasicProperties(model);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Esempio n. 2
0
        public async Task <ActionResult> Edit(SongEditViewModel viewModel)
        {
            // Unable to continue if viewmodel is null because we need the ID at least
            if (viewModel?.EditedSong == null)
            {
                s_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.EditedSong;

            // 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", SongValidationErrors.UnspecifiedNames);
            }

            if (model.Lyrics != null && model.Lyrics.Any(n => string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Lyrics", "Lyrics cannot be empty");
            }

            if (!ModelState.IsValid)
            {
                return(View(Service.GetSong(model.Id, song => new SongEditViewModel(new SongContract(song, PermissionContext.LanguagePreference, false),
                                                                                    PermissionContext, EntryPermissionManager.CanDelete(PermissionContext, song), InstrumentalTagId, model))));
            }

            await _queries.UpdateBasicProperties(model);

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