private void DeleteUserAlbum() { if (String.IsNullOrEmpty(this.txtNewUserUserName.Text)) { return; } if (GallerySettings.EnableUserAlbum) { IAlbum album = null; try { IUserGalleryProfile profile = ProfileController.GetProfileForGallery(this.txtNewUserUserName.Text.Trim(), GalleryId); if (profile != null) { album = AlbumController.LoadAlbumInstance(profile.UserAlbumId); } } catch (InvalidAlbumException) { return; } if (album != null) { AlbumController.DeleteAlbum(album); } } }
public async Task <IActionResult> Delete(int id) { try { await _albumController.DeleteAlbum(id); return(Ok($"Album {id} deleted...")); } catch (InvalidAlbumException) { // HTTP specification says the DELETE method must be idempotent, so deleting a nonexistent item must have // the same effect as deleting an existing one. So we simply return HttpStatusCode.OK. return(Ok($"Album with ID {id} does not exist.")); } catch (GallerySecurityException ex) { AppEventController.LogError(ex); return(Forbid()); } catch (CannotDeleteAlbumException ex) { AppEventController.LogError(ex); return(Forbid()); } catch (Exception ex) { AppEventController.LogError(ex); return(StatusCode(500, _exController.GetExString(ex))); } }
public void DeleteAlbum_Should_ReturnOk() { var albumId = 1; mockService.Setup(s => s.RemoveAlbumAsync(albumId, userId)).Verifiable(); controller.DeleteAlbum(albumId).Result.Should().BeOfType <OkResult>(); mockService.Verify(); }
private bool btnOkClicked() { // User clicked 'Delete selected objects'. string[] selectedItems = RetrieveUserSelections(); if (selectedItems.Length == 0) { // No objects were selected. Inform user and exit function. ucUserMessage.MessageTitle = Resources.GalleryServerPro.Task_No_Objects_Selected_Hdr; ucUserMessage.MessageDetail = Resources.GalleryServerPro.Task_No_Objects_Selected_Dtl; ucUserMessage.Visible = true; return(false); } if (!ValidateBeforeObjectDeletion(selectedItems)) { return(false); } try { HelperFunctions.BeginTransaction(); // Convert the string array of IDs to integers. Also assign whether each is an album or media object. // (Determined by the first character of each id's string: a=album; m=media object) foreach (string selectedItem in selectedItems) { int id = Convert.ToInt32(selectedItem.Substring(1), CultureInfo.InvariantCulture); char idType = Convert.ToChar(selectedItem.Substring(0, 1), CultureInfo.InvariantCulture); // 'a' or 'm' if (idType == 'm') { IGalleryObject go = Factory.LoadMediaObjectInstance(id); go.Delete(); } if (idType == 'a') { IAlbum go = Factory.LoadAlbumInstance(id, false); AlbumController.DeleteAlbum(go); } } HelperFunctions.CommitTransaction(); } catch { HelperFunctions.RollbackTransaction(); throw; } HelperFunctions.PurgeCache(); return(true); }
protected void Delete_Click(object sender, EventArgs e) { LinkButton btn = (LinkButton)sender; int AlbumID = int.Parse(btn.CommandArgument); AlbumController dc = new AlbumController(); dc.DeleteAlbum(AlbumID); rptAlbums.DataSource = dc.GetAlbums(); rptAlbums.DataBind(); }
private static void SaveProfile(ProfileEntity userProfile) { // Get reference to user's album. We need to do this *before* saving the profile, because if the user disabled their user album, // this method will return null after saving the profile. IAlbum album = UserController.GetUserAlbum(); if (!userProfile.EnableUserAlbum) { userProfile.UserAlbumId = 0; } ProfileController.SaveProfile(userProfile); if (!userProfile.EnableUserAlbum) { AlbumController.DeleteAlbum(album); } }
/// <summary> /// Deletes the album with the specified <paramref name="id" /> from the data store. /// </summary> /// <param name="id">The ID of the album to delete.</param> /// <returns>An instance of <see cref="HttpResponseMessage" />.</returns> /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the current user doesn't have /// permission to delete the album, deleting the album would violate a business rule, or some other /// error occurs. /// </exception> public HttpResponseMessage Delete(int id) { try { AlbumController.DeleteAlbum(id); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(String.Format("Album {0} deleted...", id)) }); } catch (InvalidAlbumException) { // HTTP specification says the DELETE method must be idempotent, so deleting a nonexistent item must have // the same effect as deleting an existing one. So we simply return HttpStatusCode.OK. return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(String.Format("Album with ID = {0} does not exist.", id)) }); } catch (GallerySecurityException ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (CannotDeleteAlbumException ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (Exception ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = Utils.GetExStringContent(ex), ReasonPhrase = "Server Error" }); } }
private void SaveProfile(IUserProfile userProfile) { // Get reference to user's album. We need to do this *before* saving the profile, because if the user disabled their user album, // this method will return null after saving the profile. IAlbum album = UserController.GetUserAlbum(GalleryId); IUserGalleryProfile profile = userProfile.GetGalleryProfile(GalleryId); if (!profile.EnableUserAlbum) { AlbumController.DeleteAlbum(album); } if (!profile.EnableUserAlbum) { profile.UserAlbumId = 0; } ProfileController.SaveProfile(userProfile); }
private bool btnOkClicked() { //User clicked 'Delete album'. try { AlbumController.DeleteAlbum(this.GetAlbum()); HelperFunctions.PurgeCache(); return(true); } catch (ErrorHandler.CustomExceptions.CannotDeleteAlbumException ex) { ucUserMessage.MessageTitle = Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_User_Album_Parent_Hdr; ucUserMessage.MessageDetail = ex.Message; ucUserMessage.Visible = true; return(false); } }
public void DeleteAlbum_IfUserAlbumsContaintsAlbum_ShouldDeleteAlbum() { var removeAlbum = new Album { Id = 3, Name = "testPost", User = new User { Id = "1", UserName = "******" }, UserId = "1", Photos = new List <Photo>() }; _albums.Add(removeAlbum); _albumService = new Mock <IAlbumService>(); _albumService.Setup(a => a.Albums).Returns(_albums); _albumService.Setup(a => a.GetAlbumById(3)).Returns(removeAlbum); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "test1"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("custom-claim", "example claim value"), }, "mock")); _userManager.Setup(u => u.FindByNameAsync("test1")).Returns(Task.FromResult(new User { Id = "1", UserName = "******", Albums = new List <Album>() { removeAlbum } })); var controller = new AlbumController(_albumService.Object, _mapper, _userManager.Object); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } }; controller.DeleteAlbum(removeAlbum.Id); _albumService.Verify(c => c.DeleteAlbum(3), Times.Once()); }
private void DeleteUserAlbum() { if (String.IsNullOrEmpty(this.txtNewUserUserName.Text)) { return; } if (Core.EnableUserAlbum) { IAlbum album; try { album = Factory.LoadAlbumInstance(ProfileController.GetProfile(this.txtNewUserUserName.Text).UserAlbumId, false); } catch (InvalidAlbumException) { return; } if (album != null) { AlbumController.DeleteAlbum(album); } } }
private bool btnOkClicked() { //User clicked 'Delete album'. try { AlbumController.DeleteAlbum(this.GetAlbum(), !chkDeleteDbRecordsOnly.Checked); HelperFunctions.PurgeCache(); return(true); } catch (Events.CustomExceptions.CannotDeleteAlbumException ex) { ClientMessage = new ClientMessageOptions { Title = Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_User_Album_Parent_Hdr, Message = Utils.HtmlEncode(ex.Message), Style = MessageStyle.Error }; return(false); } }
private bool btnOkClicked() { // User clicked 'Delete selected objects'. string[] selectedItems = RetrieveUserSelections(); if (selectedItems.Length == 0) { // No objects were selected. Inform user and exit function. ucUserMessage.MessageTitle = Resources.GalleryServerPro.Task_No_Objects_Selected_Hdr; ucUserMessage.MessageDetail = Resources.GalleryServerPro.Task_No_Objects_Selected_Dtl; ucUserMessage.Visible = true; return(false); } if (!ValidateBeforeObjectDeletion(selectedItems)) { return(false); } try { HelperFunctions.BeginTransaction(); // Convert the string array of IDs to integers. Also assign whether each is an album or media object. // (Determined by the first character of each id's string: a=album; m=media object) foreach (string selectedItem in selectedItems) { int id = Convert.ToInt32(selectedItem.Substring(1), CultureInfo.InvariantCulture); char idType = Convert.ToChar(selectedItem.Substring(0, 1), CultureInfo.InvariantCulture); // 'a' or 'm' if (idType == 'm') { IGalleryObject go; try { go = Factory.LoadMediaObjectInstance(id); } catch (InvalidMediaObjectException) { continue; // Media object may have been deleted by someone else, so just skip it. } if (UserCanDeleteMediaObject) { if (chkDeleteDbRecordsOnly.Checked) { go.DeleteFromGallery(); } else { go.Delete(); } } } if (idType == 'a') { IAlbum album; try { album = AlbumController.LoadAlbumInstance(id, false); } catch (InvalidAlbumException) { continue; // Album may have been deleted by someone else, so just skip it. } if (UserCanDeleteChildAlbum) { AlbumController.DeleteAlbum(album, !chkDeleteDbRecordsOnly.Checked); } } } HelperFunctions.CommitTransaction(); } catch { HelperFunctions.RollbackTransaction(); throw; } HelperFunctions.PurgeCache(); return(true); }