public void SubmitPost(CustomPost post) { try { if (post == null) throw new Exception(); using (var context = new ChatUp_DBEntities()) { var chatRooms = context.ChatRoom.Select(x => x.Id).ToList(); if (!chatRooms.Contains(post.ChatRoomId)) { throw new FaultException("Chat Room not found"); } var newPost = new Post { Submitter = post.Submitter, ChatRoomId = post.ChatRoomId, Comment = post.Comment, TimeSubmitted = post.TimeSubmitted, IsActive = post.IsActive }; context.Post.Add(newPost); context.SaveChanges(); } } catch (Exception ex) { WriteToExceptionFile(ex); throw new FaultException("An error occured, try again later"); } }
public void RemovePost(int postId) { try { using (var context = new ChatUp_DBEntities()) { var query = (from p in context.Post where p.Id == postId select p).FirstOrDefault(); if (query == null) { throw new FaultException("Post not found"); } query.IsActive = false; context.SaveChanges(); } } catch (Exception exception) { WriteToExceptionFile(exception); throw new FaultException("An error occured, try again later"); } }