public ActionResult Edit(TagEditViewModel model) { var coverPicUpload = Request.Files["thumbPicUpload"]; UploadedFileContract uploadedPicture = null; if (coverPicUpload != null && coverPicUpload.ContentLength > 0) { CheckUploadedPicture(coverPicUpload, "thumbPicUpload"); uploadedPicture = new UploadedFileContract { Mime = coverPicUpload.ContentType, Stream = coverPicUpload.InputStream }; } try { model.CheckModel(); } catch (InvalidFormException x) { AddFormSubmissionError(x.Message); } if (!ModelState.IsValid) { return(RenderEdit(model)); } TagBaseContract result; try { result = queries.Update(model.ToContract(), uploadedPicture); } catch (DuplicateTagNameException x) { ModelState.AddModelError("Names", x.Message); return(RenderEdit(model)); } return(RedirectToAction("DetailsById", new { id = result.Id, slug = result.UrlSlug })); }
public ActionResult Edit(SongListEditViewModel model) { if (model == null) { return(HttpStatusCodeResult(HttpStatusCode.BadRequest, "View model was null - probably JavaScript is disabled")); } var coverPicUpload = Request.Files["thumbPicUpload"]; UploadedFileContract uploadedPicture = null; if (coverPicUpload != null && coverPicUpload.ContentLength > 0) { CheckUploadedPicture(coverPicUpload, "thumbPicUpload"); uploadedPicture = new UploadedFileContract { Mime = coverPicUpload.ContentType, Stream = coverPicUpload.InputStream }; } if (!ModelState.IsValid) { return(View(new SongListEditViewModel(model.ToContract(), PermissionContext))); } var listId = queries.UpdateSongList(model.ToContract(), uploadedPicture); return(RedirectToAction("Details", new { id = listId })); }
private void SetThumb(SongList list, UploadedFileContract uploadedFile) { if (uploadedFile != null) { var thumb = new EntryThumbMain(list, uploadedFile.Mime); list.Thumb = thumb; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(uploadedFile.Stream, thumb, SongList.ImageSizes, originalSize: Constants.RestrictedImageOriginalSize); } }
private void SetThumb(SongList list, UploadedFileContract uploadedFile) { if (uploadedFile != null) { var thumb = new EntryThumb(list, uploadedFile.Mime); list.Thumb = thumb; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(uploadedFile.Stream, thumb, ImageSizes.Original | ImageSizes.SmallThumb, originalSize: 500); } }
public ActionResult Edit(SongListEdit model) { var coverPicUpload = Request.Files["thumbPicUpload"]; UploadedFileContract uploadedPicture = null; if (coverPicUpload != null && coverPicUpload.ContentLength > 0) { CheckUploadedPicture(coverPicUpload, "thumbPicUpload"); uploadedPicture = new UploadedFileContract { Mime = coverPicUpload.ContentType, Stream = coverPicUpload.InputStream }; } if (!ModelState.IsValid) { return(View(model)); } var listId = queries.UpdateSongList(model.ToContract(), uploadedPicture); return(RedirectToAction("Details", new { id = listId })); }
public ActionResult Edit(TagEdit model) { var coverPicUpload = Request.Files["thumbPicUpload"]; UploadedFileContract uploadedPicture = null; if (coverPicUpload != null && coverPicUpload.ContentLength > 0) { CheckUploadedPicture(coverPicUpload, "thumbPicUpload"); uploadedPicture = new UploadedFileContract { Mime = coverPicUpload.ContentType, Stream = coverPicUpload.InputStream }; } if (!ModelState.IsValid) { var contract = queries.GetTagForEdit(model.Name); model.CopyNonEditableProperties(contract); return(View(model)); } queries.Update(model.ToContract(), uploadedPicture); return(RedirectToAction("Details", new { id = model.Name })); }
public TagBaseContract Update(TagForEditContract contract, UploadedFileContract uploadedImage) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditTags); return(repository.HandleTransaction(ctx => { var tag = LoadTagById(ctx, contract.Id); permissionContext.VerifyEntryEdit(tag); var diff = new TagDiff(); if (tag.CategoryName != contract.CategoryName) { diff.CategoryName.Set(); } diff.Description.Set(tag.Description.CopyFrom(contract.Description)); if (tag.HideFromSuggestions != contract.HideFromSuggestions) { diff.HideFromSuggestions.Set(); } if (tag.Targets != contract.Targets) { diff.Targets.Set(); } if (tag.TranslatedName.DefaultLanguage != contract.DefaultNameLanguage) { tag.TranslatedName.DefaultLanguage = contract.DefaultNameLanguage; diff.OriginalName.Set(); } var nameDiff = SyncNames(ctx.OfType <TagName>(), tag, contract.Names); if (nameDiff.Changed) { diff.Names.Set(); } if (!Tag.Equals(tag.Parent, contract.Parent)) { var newParent = GetRealTag(ctx, contract.Parent, tag); if (!Equals(newParent, tag.Parent)) { diff.Parent.Set(); tag.SetParent(newParent); } } var relatedTagsDiff = tag.SyncRelatedTags(contract.RelatedTags, tagId => ctx.Load(tagId)); ctx.Sync(relatedTagsDiff); diff.RelatedTags.Set(relatedTagsDiff.Changed); var webLinkDiff = tag.WebLinks.Sync(contract.WebLinks, tag); ctx.OfType <TagWebLink>().Sync(webLinkDiff); if (webLinkDiff.Changed) { diff.WebLinks.Set(); } if (tag.Status != contract.Status) { diff.Status.Set(); } tag.CategoryName = contract.CategoryName; tag.HideFromSuggestions = contract.HideFromSuggestions; tag.Status = contract.Status; tag.Targets = contract.Targets; if (uploadedImage != null) { diff.Picture.Set(); var thumb = new EntryThumb(tag, uploadedImage.Mime); tag.Thumb = thumb; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(uploadedImage.Stream, thumb, Tag.ImageSizes, originalSize: Constants.RestrictedImageOriginalSize); } var logStr = string.Format("updated properties for tag {0} ({1})", entryLinkFactory.CreateEntryLink(tag), diff.ChangedFieldsString); ctx.AuditLogger.AuditLog(logStr); var archived = Archive(ctx, tag, diff, EntryEditEvent.Updated, contract.UpdateNotes); AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), tag, EntryEditEvent.Updated, archived); ctx.Update(tag); return new TagBaseContract(tag, LanguagePreference); })); }
private SongList CreateSongList(IDatabaseContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile) { var user = GetLoggedUser(ctx); var newList = new SongList(contract.Name, user); newList.Description = contract.Description ?? string.Empty; newList.EventDate = contract.EventDate; if (EntryPermissionManager.CanManageFeaturedLists(permissionContext)) { newList.FeaturedCategory = contract.FeaturedCategory; } ctx.Save(newList); var songDiff = newList.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id)); ctx.OfType <SongInList>().Sync(songDiff); SetThumb(newList, uploadedFile); ctx.Update(newList); ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user); var archived = Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created, contract.UpdateNotes); if (newList.FeaturedList) { AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), newList, EntryEditEvent.Created, archived); } return(newList); }
public int UpdateSongList(SongListForEditContract contract, UploadedFileContract uploadedFile) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(repository.HandleTransaction(ctx => { var user = GetLoggedUser(ctx); SongList list; if (contract.Id == 0) { list = CreateSongList(ctx, contract, uploadedFile); } else { list = ctx.Load(contract.Id); var diff = new SongListDiff(); EntryPermissionManager.VerifyEdit(PermissionContext, list); if (list.Description != contract.Description) { diff.Description.Set(); list.Description = contract.Description ?? string.Empty; } if (list.Name != contract.Name) { diff.Name.Set(); list.Name = contract.Name; } if (EntryPermissionManager.CanManageFeaturedLists(PermissionContext) && list.FeaturedCategory != contract.FeaturedCategory) { diff.FeaturedCategory.Set(); list.FeaturedCategory = contract.FeaturedCategory; } if (list.EventDate != contract.EventDate) { diff.SetChanged(SongListEditableFields.EventDate); list.EventDate = contract.EventDate; } if (list.Status != contract.Status) { diff.Status.Set(); list.Status = contract.Status; } var songDiff = list.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id)); if (songDiff.Changed) { diff.Songs.Set(); } ctx.OfType <SongInList>().Sync(songDiff); if (uploadedFile != null) { diff.Thumbnail.Set(); SetThumb(list, uploadedFile); } ctx.Update(list); ctx.AuditLogger.AuditLog( string.Format("updated song list {0} ({1})", entryLinkFactory.CreateEntryLink(list), diff.ChangedFieldsString), user); var archived = Archive(ctx, list, diff, EntryEditEvent.Updated, contract.UpdateNotes); if (list.FeaturedList) { AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), list, EntryEditEvent.Updated, archived); } } return list.Id; })); }
public void Update(TagContract contract, UploadedFileContract uploadedImage) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.ManageDatabase); repository.HandleTransaction(ctx => { var tag = ctx.Load(contract.Name); permissionContext.VerifyEntryEdit(tag); var diff = new TagDiff(); var newAliasedTo = contract.AliasedTo ?? string.Empty; if (!Tag.Equals(tag.AliasedTo, contract.AliasedTo)) { diff.AliasedTo = true; tag.AliasedTo = GetRealTag(ctx, newAliasedTo, tag); } if (tag.CategoryName != contract.CategoryName) { diff.CategoryName = true; } if (tag.Description != contract.Description) { diff.Description = true; } if (!Tag.Equals(tag.Parent, contract.Parent)) { var newParent = GetRealTag(ctx, contract.Parent, tag); if (!Equals(newParent, tag.Parent)) { diff.Parent = true; tag.SetParent(newParent); } } if (tag.Status != contract.Status) { diff.Status = true; } tag.CategoryName = contract.CategoryName; tag.Description = contract.Description; tag.Status = contract.Status; if (uploadedImage != null) { diff.Picture = true; var thumb = new EntryThumb(tag, uploadedImage.Mime); tag.Thumb = thumb; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(uploadedImage.Stream, thumb, ImageSizes.Original | ImageSizes.SmallThumb, originalSize: 500); } var logStr = string.Format("updated properties for tag {0} ({1})", entryLinkFactory.CreateEntryLink(tag), diff.ChangedFieldsString); ctx.AuditLogger.AuditLog(logStr); Archive(ctx, tag, diff, EntryEditEvent.Updated); ctx.Update(tag); }); }
private SongList CreateSongList(IRepositoryContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile) { var user = GetLoggedUser(ctx); var newList = new SongList(contract.Name, user); newList.Description = contract.Description; if (EntryPermissionManager.CanManageFeaturedLists(permissionContext)) { newList.FeaturedCategory = contract.FeaturedCategory; } ctx.Save(newList); var songDiff = newList.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.SongId)); ctx.OfType <SongInList>().Sync(songDiff); SetThumb(newList, uploadedFile); ctx.Update(newList); ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user); Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created); return(newList); }