Example #1
0
 public ICollection<CustomPost> GetPosts(int chatRoomId)
 {
     try
     {
         var posts = new List<CustomPost>();
         using (var context = new ChatUp_DBEntities())
         {
             posts =
                 context.Post.Where(x => x.ChatRoom.Id == chatRoomId && x.IsActive == true)
                     .Select(y => new CustomPost
                     {
                         ChatRoomId = y.ChatRoomId,
                         Id = y.Id,
                         Comment = y.Comment,
                         Submitter = y.Submitter,
                         TimeSubmitted = y.TimeSubmitted,
                         IsActive = y.IsActive
                     }).ToList();
         }
         return posts;
     }
     catch (Exception ex)
     {
         WriteToExceptionFile(ex);
         throw new FaultException("An error occured, try again later");
     }
 }
Example #2
0
 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");
     }
 }
Example #3
0
 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");
     }
 }