public static void DeletePhoto(String photoId) { if (photoId == null || photoId.Length == 0) { throw new Exception("Invalid photo id."); } String query = "UPDATE Posts " + "SET PhotoID = @val, Timestamp = @timestamp " + "WHERE PhotoID = @id"; SqlConnection con = new SqlConnection(@"Data Source=GHGRLH2\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True"); try { con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("id", photoId); cmd.Parameters.AddWithValue("val", DBNull.Value); cmd.Parameters.AddWithValue("timestamp", DateTime.Now); int updated = (int)cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { con.Close(); } Photo.Delete(photoId); }
public virtual ActionResult PhotoDel(long id) { var p = Photo.Get(id); var path = Path.Photo(WebUser.UserId, p.AddTime, p.Summary, ThumbType.Middle); IOFactory.StoreFile.Delete(path); Album.GetCountChange(p.AlbumId.Value, -1); Photo.Delete(p.Id); return(this.RedirectToReferrer()); }
public void Delete_DeletesCorrectPhoto_true() { User newUser = new User("mammaBear", "honey"); Photo newPhoto = new Photo(newUser.Id, "my/photo.jpeg", false); newPhoto.Save(); newPhoto.Delete(); List <Photo> allPhotos = Photo.GetAll(); Assert.Equal(0, allPhotos.Count); }
public static void Delete(String postId) { if (postId == null || postId.Length == 0) { throw new Exception("Invalid post id"); } // delete the post comments List <String> ids = Comments.GetCommentsIds(postId); foreach (String id in ids) { Comments.Delete(id); } String photoId = GetPhotoId(postId); String query = "DELETE FROM Posts WHERE Id = @id"; SqlConnection con = new SqlConnection(@"Data Source=GHGRLH2\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True"); try { con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("id", postId); int deleted = (int)cmd.ExecuteNonQuery(); if (deleted == 0) { throw new Exception("Post couldn't be deleted"); } }catch (Exception ex) { throw ex; } finally { con.Close(); } if (photoId.Length > 0) { Photo.Delete(photoId); } }
public GalleryItem SaveSingle(string WebPhotoID, string Caption, bool DoDelete, string NewWebPhotoCollectionID, int RotationValue, string strIndex) { member = (Member)Session["Member"]; GalleryItem galleryItem = new GalleryItem(); galleryItem.Index = strIndex; bool Update = false; if (member != null) { Photo photo = Photo.GetPhotoByWebPhotoIDWithJoin(WebPhotoID); if (photo != null) { if (photo.MemberID == member.MemberID) { PhotoCollection NewCollectionObject = GetLocalGalleryByWebPhotoColletionID(NewWebPhotoCollectionID); if (DoDelete) { photo.Delete(); galleryItem.IsRemoved = true; } else { // determine if a gallery move has been requested if (photo.PhotoCollectionID != NewCollectionObject.PhotoCollectionID) { photo.PhotoCollectionID = NewCollectionObject.PhotoCollectionID; galleryItem.IsRemoved = true; Update = true; } //if (photo.Tags != Tags) //{ // photo.Tags = Tags; // Update = true; // // update the tags here // photo.UpdateTags(); // galleryItem.Tags = photo.Tags; //} if (RotationValue != 0) { Photo.RotateGalleryImage(member, WebPhotoID, ASP.global_asax.DiskUserRoot, RotationValue); } //if (photo.CategoryID != CategoryID) //{ // photo.CategoryID = CategoryID; // Update = true; //} if (photo.Caption != Caption) { photo.Caption = Caption; Update = true; } if (Update) { photo.Save(); } } } } } return(galleryItem); }
protected void btnSave_Click(object sender, EventArgs e) { member = (Member)Session["Member"]; bool Update = false; if (member != null) { for (int i = 0; i < PhotoRepeater.Items.Count; i++) { HiddenField HiddenFieldWebPhotoID = (HiddenField)PhotoRepeater.Items[i].FindControl("WebPhotoID"); string WebPhotoID = HiddenFieldWebPhotoID.Value; Photo photo = GetLocalPhotoByWebPhotoID(WebPhotoID); if (photo != null) { if (photo.MemberID == member.MemberID) { CheckBox chbDelete = (CheckBox)PhotoRepeater.Items[i].FindControl("chbDelete"); bool DoDelete = chbDelete.Checked; DropDownList drpGallery = (DropDownList)PhotoRepeater.Items[i].FindControl("drpGallery"); string NewWebPhotoCollectionID = drpGallery.SelectedValue; PhotoCollection NewCollectionObject = GetLocalGalleryByWebPhotoColletionID(NewWebPhotoCollectionID); if (DoDelete) { photo.Delete(); } else { // determine if a gallery move has been requested if (photo.PhotoCollectionID != NewCollectionObject.PhotoCollectionID) { photo.PhotoCollectionID = NewCollectionObject.PhotoCollectionID; Update = true; } HiddenField HiddenFieldRotation = (HiddenField)PhotoRepeater.Items[i].FindControl("Rotation"); string Rotation = HiddenFieldRotation.Value; int RotationValue = Int32.Parse(Rotation); HiddenFieldRotation.Value = "0"; if (RotationValue != 0) { Photo.RotateGalleryImage(member, WebPhotoID, ASP.global_asax.DiskUserRoot, RotationValue); } TextBox txtCaption = (TextBox)PhotoRepeater.Items[i].FindControl("txtCaption"); //DropDownList drpCategories = (DropDownList)PhotoRepeater.Items[i].FindControl("drpCategories"); //TextBox txtTags = (TextBox)PhotoRepeater.Items[i].FindControl("txtTags"); ////if (photo.CategoryID.ToString() != drpCategories.SelectedValue) //{ // photo.CategoryID = Int32.Parse(drpCategories.SelectedValue); // Update = true; //} if (photo.Caption != txtCaption.Text) { photo.Caption = txtCaption.Text; Update = true; } if (Update) { photo.Save(); } } } } } } string strPhotoCollectionID = Request.Params["pc"]; // if a photocollectionid has been specified then load the new collection if (strPhotoCollectionID != null) { PhotoCollection photoCollection = PhotoCollection.GetPhotoCollectionByWebPhotoCollectionID(strPhotoCollectionID); DefaultPhotoCollectionID = photoCollection.PhotoCollectionID; } Bind(CurrentPageIndex); }
public void Delete(string WebPhotoID) { Photo photo = Photo.GetPhotoByWebPhotoIDWithJoin(WebPhotoID); photo.Delete(); }
public IActionResult DeleteConfirmed(int id) { Photo.Delete(id); return(RedirectToAction("Index")); }
public HomeModule() { Get["/"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); return(View["index.cshtml", model]); }; Post["/sign-up"] = _ => { bool taken = User.CheckUserName(Request.Form["new-user-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); if (taken) { string message = "The username " + Request.Form["new-user-name"] + " is taken. Please choose another."; model.Add("message", message); return(View["index.cshtml", model]); } if (!taken) { User newUser = new User(Request.Form["new-user-name"], Request.Form["new-user-password"]); newUser.Save(); User.SetCurrentUser(newUser); User currentUser = User.GetCurrentUser(); model.Add("profilePic", null); model.Add("messageList", null); model.Add("message", "Create new profile"); model.Add("user", currentUser); } return(View["edit_profile.cshtml", model]); }; Post["/sign-in"] = _ => { string userName = Request.Form["user-name"]; string userPassword = Request.Form["user-password"]; bool loginStatus = User.CheckLogin(userName, userPassword); Dictionary <string, object> model = new Dictionary <string, object>(); User currentUser = User.FindByUserName(userName); if (loginStatus == true) { User.SetCurrentUser(currentUser); currentUser.Genders = currentUser.ConvertGender(currentUser.Gender); currentUser.SeekGenders = currentUser.ConvertGender(currentUser.SeekGender); List <Message> allUnreadMessages = currentUser.GetAllUnreadMessages(); model.Add("selectedUser", currentUser); model.Add("messageList", allUnreadMessages); model.Add("message", "Welcome!"); model.Add("user", currentUser); model.Add("state", true); model.Add("profilePic", currentUser.GetProfilePhoto().Url); } if (loginStatus == false) { model.Add("message", "Invalid User Name or Password"); return(View["index.cshtml", model]); } return(View["profile.cshtml", model]); }; Get["/user/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); User currentUser = User.GetCurrentUser(); User selectedUser = User.Find(parameters.id); selectedUser.Genders = selectedUser.ConvertGender(selectedUser.Gender); selectedUser.SeekGenders = selectedUser.ConvertGender(selectedUser.SeekGender); model.Add("selectedUser", selectedUser); model.Add("user", currentUser); bool isUsersProfile = false; Photo profilePic = selectedUser.GetProfilePhoto(); List <Message> allUnreadMessages = currentUser.GetAllUnreadMessages(); if (currentUser.Id == parameters.id) { isUsersProfile = true; } model.Add("messageList", allUnreadMessages); model.Add("profilePic", profilePic.Url); model.Add("state", isUsersProfile); return(View["profile.cshtml", model]); }; Get["/user/update"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); User currentUser = User.GetCurrentUser(); model.Add("message", "Edit profile"); model.Add("user", currentUser); return(View["edit_profile.cshtml", model]); }; Patch["/user/update"] = _ => { User currentUser = User.GetCurrentUser(); int seekGender = Request.Form["seek-gender"]; int gender = Request.Form["gender"]; if (seekGender == 0) { seekGender = currentUser.SeekGender; } if (gender == 0) { gender = currentUser.SeekGender; } currentUser.Edit(Request.Form["user-name"], Request.Form["user-password"], Request.Form["first-name"], Request.Form["last-name"], Request.Form["zip-code"], Request.Form["email"], Request.Form["tag-line"], Request.Form["phone-number"], Request.Form["about"], gender, seekGender); Dictionary <string, object> model = new Dictionary <string, object>(); Photo profilePic = new Photo(currentUser.Id, Request.Form["profile-pic"]); currentUser.AddPhoto(profilePic); profilePic.MakeProfile(currentUser.Id); currentUser.Genders = currentUser.ConvertGender(currentUser.Gender); currentUser.SeekGenders = currentUser.ConvertGender(currentUser.SeekGender); List <Message> allUnreadMessages = currentUser.GetAllUnreadMessages(); model.Add("messageList", allUnreadMessages); model.Add("message", "Your profile has been updated"); model.Add("user", currentUser); model.Add("selectedUser", currentUser); model.Add("state", true); model.Add("profilePic", profilePic.Url); return(View["profile.cshtml", model]); }; Delete["/user/delete"] = _ => { User currentUser = User.GetCurrentUser(); currentUser.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("message", "Profile Deleted!"); return(View["index.cshtml", model]); }; Get["/user/delete/cancel"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); User currentUser = User.GetCurrentUser(); model.Add("user", currentUser); return(View["profile.cshtml", model]); }; Get["/users"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); List <User> allUsers = User.GetAll(); User currentUser = User.GetCurrentUser(); model.Add("user", currentUser); model.Add("users", allUsers); return(View["profiles.cshtml", model]); }; Get["/user/messages/"] = _ => { User currentUser = User.GetCurrentUser(); List <Message> allUnreadMessages = currentUser.GetAllUnreadMessages(); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); List <User> allUsers = User.GetAll(); messageDictionary.Add("user", currentUser); messageDictionary.Add("messageList", allUnreadMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["/user/messages/read"] = _ => { User currentUser = User.GetCurrentUser(); List <Message> allReadMessages = currentUser.GetAllReadMessages(); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); List <User> allUsers = User.GetAll(); messageDictionary.Add("user", currentUser); messageDictionary.Add("messageList", allReadMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["/user/{id}/message/send"] = parameters => { User sendingUser = User.GetCurrentUser(); User receivingUser = User.Find(parameters.id); List <Message> allCorrespondence = sendingUser.GetCorrespondenceFromDater(receivingUser); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); messageDictionary.Add("history", allCorrespondence); messageDictionary.Add("sender", sendingUser); messageDictionary.Add("receiver", receivingUser); return(View["create_message.cshtml", messageDictionary]); }; Post["user/message/send"] = _ => { Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); User senderUser = User.Find(Request.Form["sender"]); User receiverUser = User.Find(Request.Form["receiver"]); string messageText = Request.Form["message-text"]; bool viewed = false; Message newMessage = new Message(senderUser.Id, receiverUser.Id, messageText, viewed); newMessage.Save(); List <Message> allUnreadMessages = senderUser.GetAllUnreadMessages(); List <User> allUsers = User.GetAll(); messageDictionary.Add("message", "Message Sent"); messageDictionary.Add("user", senderUser); messageDictionary.Add("messageList", allUnreadMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["/user/messages/sent"] = _ => { User currentUser = User.GetCurrentUser(); List <Message> allSentMessages = currentUser.GetAllSentMessages(); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); List <User> allUsers = User.GetAll(); messageDictionary.Add("user", currentUser); messageDictionary.Add("messageList", allSentMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["/user/messages/all"] = _ => { User currentUser = User.GetCurrentUser(); List <Message> allMessages = currentUser.GetAllReceivedMessages(); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); List <User> allUsers = User.GetAll(); messageDictionary.Add("user", currentUser); messageDictionary.Add("messageList", allMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["user/messages/{id}"] = parameters => { User receivingUser = User.GetCurrentUser(); Message currentMessage = Message.Find(parameters.Id); User senderUser = User.Find(currentMessage.SenderId); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); messageDictionary.Add("user", currentMessage); messageDictionary.Add("sender", senderUser); messageDictionary.Add("receiver", receivingUser); currentMessage.MarkViewed(); return(View["view_message.cshtml", messageDictionary]); }; Get["/user/messages/{id}/reply"] = parameters => { User sendingUser = User.GetCurrentUser(); User receivingUser = User.Find(parameters.id); List <Message> allCorrespondence = sendingUser.GetCorrespondenceFromDater(receivingUser); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); messageDictionary.Add("history", allCorrespondence); messageDictionary.Add("sender", sendingUser); messageDictionary.Add("receiver", receivingUser); return(View["create_message.cshtml", messageDictionary]); }; Delete["/user/message/{id}/delete"] = parameters => { User currentUser = User.GetCurrentUser(); Message currentMessage = Message.Find(parameters.Id); List <Message> allUnreadMessages = currentUser.GetAllUnreadMessages(); List <User> allUsers = User.GetAll(); currentMessage.DeleteMessage(); Dictionary <string, object> messageDictionary = new Dictionary <string, object>(); messageDictionary.Add("message", "Message Deleted!"); messageDictionary.Add("user", currentUser); messageDictionary.Add("messageList", allUnreadMessages); messageDictionary.Add("userList", allUsers); return(View["message_center.cshtml", messageDictionary]); }; Get["/user/{id}/photos"] = parameters => { User currentUser = User.GetCurrentUser(); User selectedUser = User.Find(parameters.id); bool state = false; if (currentUser.Id == selectedUser.Id) { state = true; } List <Photo> usersPhotos = selectedUser.GetPhotos(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", currentUser); model.Add("selectedUser", selectedUser); model.Add("photos", usersPhotos); model.Add("state", state); return(View["photos.cshtml", model]); }; Get["/user/{uid}/photo/{pid}"] = parameters => { User currentUser = User.GetCurrentUser(); User selectedUser = User.Find(parameters.uid); Photo selectedPhoto = Photo.Find(parameters.pid); bool state = false; if (currentUser.Id == selectedUser.Id) { state = true; } Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", selectedUser); model.Add("photo", selectedPhoto); model.Add("state", state); return(View["photo.cshtml", model]); }; Get["/user/{uid}/photo/{pid}/previous"] = parameters => { User currentUser = User.GetCurrentUser(); User selectedUser = User.Find(parameters.uid); Photo selectedPhoto = Photo.Find(parameters.pid); List <Photo> allPhotos = selectedUser.GetPhotos(); int index = allPhotos.IndexOf(selectedPhoto); Photo prevPhoto = null; if (index == 0) { prevPhoto = allPhotos[allPhotos.Count - 1]; } if (index != 0) { prevPhoto = allPhotos[index - 1]; } bool state = false; if (currentUser.Id == selectedUser.Id) { state = true; } Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", selectedUser); model.Add("photo", prevPhoto); model.Add("state", state); return(View["photo.cshtml", model]); }; Get["/user/{uid}/photo/{pid}/next"] = parameters => { User currentUser = User.GetCurrentUser(); User selectedUser = User.Find(parameters.uid); Photo selectedPhoto = Photo.Find(parameters.pid); List <Photo> allPhotos = selectedUser.GetPhotos(); int index = allPhotos.IndexOf(selectedPhoto); Photo nextPhoto = null; if (index == allPhotos.Count - 1) { nextPhoto = allPhotos[0]; } if (index != allPhotos.Count - 1) { nextPhoto = allPhotos[index + 1]; } bool state = false; if (currentUser.Id == selectedUser.Id) { state = true; } Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", selectedUser); model.Add("photo", nextPhoto); model.Add("state", state); return(View["photo.cshtml", model]); }; Post["/photos/add"] = _ => { User currentUser = User.GetCurrentUser(); Photo newPhoto = new Photo(currentUser.Id, Request.Form["new-photo"], false); currentUser.AddPhoto(newPhoto); Dictionary <string, object> model = new Dictionary <string, object>(); string message = "Picture has been added."; model.Add("message", message); model.Add("user", currentUser); model.Add("photos", currentUser.GetPhotos()); model.Add("state", true); return(View["photos.cshtml", model]); }; Delete["/photo/{id}/delete"] = parameters => { User currentUser = User.GetCurrentUser(); User selectedUser = User.GetCurrentUser(); Photo selectedPhoto = Photo.Find(parameters.id); selectedPhoto.Delete(); bool state = false; if (currentUser.Id == selectedUser.Id) { state = true; } List <Photo> usersPhotos = selectedUser.GetPhotos(); Dictionary <string, object> model = new Dictionary <string, object>(); string message = "Picture has been deleted."; model.Add("message", message); model.Add("user", currentUser); model.Add("selectedUser", selectedUser); model.Add("photos", currentUser.GetPhotos()); model.Add("state", state); return(View["photos.cshtml", model]); }; Get["/matches"] = _ => { User currentUser = User.GetCurrentUser(); List <User> matches = currentUser.MatchByGender(currentUser.Gender, currentUser.SeekGender, currentUser.Id); currentUser.Genders = currentUser.ConvertGender(currentUser.Gender); currentUser.SeekGenders = currentUser.ConvertGender(currentUser.SeekGender); Dictionary <string, object> model = new Dictionary <string, object>(); string message = "Showing " + currentUser.SeekGenders + " seeking " + currentUser.Genders; model.Add("message", message); model.Add("user", currentUser); model.Add("matches", matches); return(View["matches.cshtml", model]); }; Get["/match/{id}"] = parameters => { User currentUser = User.GetCurrentUser(); List <User> matches = currentUser.MatchByGender(currentUser.Gender, currentUser.SeekGender, currentUser.Id); User matchUser = currentUser.FindMatch(parameters.id); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", currentUser); model.Add("match", matchUser); return(View["match.cshtml", model]); }; Get["/match/{id}/previous"] = parameters => { User currentUser = User.GetCurrentUser(); List <User> matches = currentUser.MatchByGender(currentUser.Gender, currentUser.SeekGender, currentUser.Id); User matchUser = currentUser.FindMatch(parameters.id); List <int> matchesInts = new List <int> { }; foreach (User match in matches) { matchesInts.Add(match.Id); } int index = matchesInts.IndexOf(matchUser.Id); User prevMatch = null; if (index == 0) { prevMatch = matches[matches.Count - 1]; } if (index != 0) { prevMatch = matches[index - 1]; } Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", currentUser); model.Add("match", prevMatch); return(View["match.cshtml", model]); }; Get["/match/{id}/next"] = parameters => { User currentUser = User.GetCurrentUser(); List <User> matches = currentUser.MatchByGender(currentUser.Gender, currentUser.SeekGender, currentUser.Id); User matchUser = currentUser.FindMatch(parameters.id); List <int> matchesInts = new List <int> { }; foreach (User match in matches) { matchesInts.Add(match.Id); } int index = matchesInts.IndexOf(matchUser.Id); User nextMatch = null; if (index == matches.Count - 1) { nextMatch = matches[0]; } if (index != matches.Count - 1) { nextMatch = matches[index + 1]; } Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("user", currentUser); model.Add("match", nextMatch); return(View["match.cshtml", model]); }; Get["/logout"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); User.DeleteMatches(); User.DeleteState(); return(View["index.cshtml", model]); }; }