public async Task <ActionResult> Update(string Id, CommentsDTO commentsDTO) { commentsDTO.Id = new ObjectId(Id); await commentsBLL.UpdateAsync(commentsDTO); return(Redirect("/Comments/Index")); }
public ActionResult CommentForms(CommentsDTO commentsList, string request) { try { var comment = commentsList.SelectedComment; switch (request) { case ("Create"): storage.CreateComment(comment); break; case ("Edit"): storage.UpdateComment(comment); break; case ("Delete"): storage.DeleteComment(comment); break; default: throw new Exception("Akcja przycisku niezdefiniowana!"); } return(RedirectToAction("Comments", "Games", new { id = commentsList.SelectedComment.CommentedGameRefID })); } catch (Exception ex) { return(RedirectToAction("Comments", "Games", new { id = commentsList.SelectedComment.CommentedGameRefID, errorMessage = ex.Message })); } }
//View All the Comments on an event public List <CommentsDTO> ViewComments(int eventId) { List <Comments> comments = new List <Comments>(); List <CommentsDTO> commentsDTOs = new List <CommentsDTO>(); try { using (BookContext db = new BookContext()) { comments = db.Comments.Where(c => c.EventId == eventId).ToList(); foreach (var temp in comments) { CommentsDTO commentsDTO = new CommentsDTO(); EntityConverter.FillDTOFromEntity(temp, commentsDTO); commentsDTOs.Add(commentsDTO); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } return(commentsDTOs); }
public async Task <ResultDTO> addComment([FromBody] CommentsDTO comment, [FromRoute] string title) { try { if (!ModelState.IsValid) { return(new ResultDTO { Status = 400, Message = "model not valid" }); } var newComment = _mapper.Map <Comments>(comment); newComment.News = _newsService.GetAllNews().FirstOrDefault(x => x.Title == title); newComment.NewsId = _newsService.GetAllNews().FirstOrDefault(x => x.Title == title).Id; _commentService.AddComment(newComment); return(new ResultDTO { Status = 200, Message = "Ok" }); } catch (Exception e) { return(new ResultDTO { Status = 400, Message = e.Message }); } }
//Add new Comment by User public OperationResult <CommentsDTO> AddComment(CommentsDTO commentsDTO) { OperationResult <CommentsDTO> result = null; try { ICommentsDAC commentsDAC = (ICommentsDAC)DACFactory.Instance.Create(DACType.CommentsDAC); CommentsDTO resultDTO = commentsDAC.AddComment(commentsDTO); if (resultDTO != null) { result = OperationResult <CommentsDTO> .CreateSuccessResult(resultDTO); } else { result = OperationResult <CommentsDTO> .CreateFailureResult("User With This email address does not exists"); } } catch (DACException dacEx) { result = OperationResult <CommentsDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace); } catch (Exception e) { result = OperationResult <CommentsDTO> .CreateErrorResult(e.Message, e.StackTrace); } return(result); }
public async Task <ResultDTO> deleteNewsComment([FromBody] CommentsDTO comment) { try { if (!ModelState.IsValid) { return(new ResultDTO { Status = 400, Message = "model not valid" }); } var com = _mapper.Map <Comments>(comment); var sss = _commentService.GetAllComment().FirstOrDefault(x => x.Text == com.Text); //com.News = _newsService.GetAllNews().FirstOrDefault(x => x.Title == "Test2"); _commentService.DeleteComment(sss); return(new ResultDTO { Status = 200, Message = "Ok" }); } catch (Exception e) { return(new ResultDTO { Status = 400, Message = e.Message }); } }
public IHttpActionResult DeleteCommentsByID([FromBody] CommentsParametersDelete commentsParametersDelete) { if (commentsParametersDelete != null && ModelState.IsValid) { CommentsDTO commentsDTO = _gasstationsservice.DeleteCommentsByID(commentsParametersDelete, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { CommentsDeletdID = commentsDTO.ID } })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); } return(BadRequest(ModelState)); }
public static Comments ToDomainModel(this CommentsDTO dto) { Comments model = new Comments(); model.CommentedDate = dto.CommentDate; model.CommentMsg = dto.CommentMsg; model.UserId = dto.UserId; return(model); }
public static CommentsDTO ToDTO(this CommentsVM vm) { CommentsDTO dto = new CommentsDTO(); dto.CommentDate = vm.CommentDate; dto.CommentMsg = vm.CommentMsg; dto.UserId = vm.UserId; return(dto); }
public static CommentsVM ToViewModel(this CommentsDTO dto) { CommentsVM vm = new CommentsVM(); vm.ComId = dto.ComId; vm.CommentDate = dto.CommentDate; vm.CommentMsg = dto.CommentMsg; vm.UserId = dto.UserId; return(vm); }
public static CommentsDTO ToDto(this Comments model) { CommentsDTO dto = new CommentsDTO(); dto.ComId = model.ComId; dto.CommentDate = model.CommentedDate; dto.CommentMsg = model.CommentMsg; dto.UserId = model.UserId; return(dto); }
public async Task <IActionResult> AddComment([FromBody] CommentsDTO commentInfo) { bool added = await _commentsRepository.AddComment(commentInfo); if (!added) { return(BadRequest(new { message = "Failed to save comment" })); } return(Ok(new { message = "Comment saved" })); }
public void AddComment(int PostId, CommentsDTO NewComment) { if (UserLogic.CurrentUser == null || UserLogic.CurrentUser.UserType != DTOs.UserType.Manager) { throw new Exception("Function availible only for managers"); } Post post = UoW.Post.GetAll(x => x.Id == PostId, x => x.Comments).FirstOrDefault(); Comments comments = PostLogicMapper.Map <CommentsDTO, Comments>(NewComment); comments.Post = post; post.Comments.Add(comments); UoW.Post.Modify(post.Id, post); }
public void AddComment(int UserId, int PostId, CommentsDTO comment) { if (CurrentUser == null) { throw new Exception("Login to left a comment"); } Post post = UoW.Post.GetAll(x => x.Id == PostId, x => x.Comments).FirstOrDefault(); Comments comments = UserLogicMapper.Map <CommentsDTO, Comments>(comment); comments.Post = post; post.Comments.Add(comments); UoW.Post.Modify(post.Id, post); }
public ActionResult UpdateComment(string comment, int eventID) { CommentsViewModel commentsViewModel = new CommentsViewModel { Comment = comment, PostDate = DateTime.Now.Date, EventID = eventID }; CommentsDTO commentsDTO = mapCommentsDTO2ViewModel.Map <CommentsDTO>(commentsViewModel); eventBusinessLogic.AddCommentBAL(commentsDTO); return(RedirectToAction(Resource.Details, Resource.Events, new { id = eventID })); }
/// <summary> /// business method to add comments. /// </summary> /// <param name="comment"></param> public CommentsDTO AddCommentBAL(CommentsDTO comment) { try { return(eventDAL.AddCommentDAL(comment)); } catch (DALException dalEx) { throw new Exception(dalEx.Message); } catch (Exception) { throw new Exception(Resource.BALErrorMessage); } }
public async Task <CommentsDTO> saveComments(CommentsDTO comments) { try { comments.Id = Guid.NewGuid(); var comment = mapper.Map <Comments>(comments); context.Add(comment); await context.SaveChangesAsync(); return(mapper.Map <CommentsDTO>(comment)); } catch (Exception ex) { throw new Exception("Error en CommentsDomain", ex); } }
public ActionResult <Post> AddComment(string title, CommentsDTO comment) { User user = _userRepository.GetByEmail(User.Identity.Name); Post postToModify = user.GetPostByTitle(title); if (postToModify == null) { return(NotFound()); } var commentToAdd = new Comments(comment.Text); postToModify.AddComments(commentToAdd); _userRepository.SaveChanges(); return(CreatedAtAction(nameof(GetCommentFromPost), new { userId = user.Id, postId = postToModify.Id, commentId = commentToAdd.Id }, commentToAdd)); }
public void AddCommentToPost(int id, CommentsDTO comment) { try { var client = new MongoClient(connectionString); var db = client.GetDatabase("Social_Network"); var posts = db.GetCollection <PostsDTO>("Posts"); var UpdateFilter = Builders <PostsDTO> .Update.AddToSet("Comments", comment); posts.UpdateOne(g => g.Post_Id == id, UpdateFilter); } catch (Exception exp) { throw exp; } }
/// <summary> /// Add a comment to DataBase /// </summary> /// <param name="comment"></param> public CommentsDTO AddCommentDAL(CommentsDTO comment) { try { using (BookReadingEventContext db = new BookReadingEventContext()) { CommentsEntity commentsEntity = mapCommentDTO2Entity.Map <CommentsEntity>(comment); db.CommentsEntity.Add(commentsEntity); db.SaveChanges(); return(comment); } } catch (Exception) { throw new DALException(Resource.DALErrorMessage); } }
public async Task <ActionResult> saveComments([FromBody] CommentsDTO comments) { if (comments == null) { return(BadRequest()); } if (string.IsNullOrEmpty(comments.Comment)) { return(Problem(statusCode: 422, title: "Invalida data, Comment property cannot be empty!")); } if (string.IsNullOrEmpty(comments.PostId.ToString())) { return(Problem(statusCode: 422, title: "Invalida data, PostId property cannot be empty!")); } return(Ok(await _commentsDomain.saveComments(comments))); }
public async Task <string> Add(CommentsDTO commentsDTO) { try { await commentsBLL.AddAsync(commentsDTO); return(JsonConvert.SerializeObject(new ResponseClassDTO() { State = "success" })); } catch (Exception ex) { return(JsonConvert.SerializeObject(new ResponseClassDTO() { State = "fail", Message = ex.Message })); } }
public async Task <bool> AddComment(CommentsDTO commentInfo) { try { using (SqlConnection connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); await connection.ExecuteAsync(@"insert into Comments (VideoId, Comment, Likes, LikesList, TimeStamp, Edited, Username) values(@videoId, @comment, @likes, @likesList, @timeStamp, 0, @username)", commentInfo); return(true); } } catch { return(false); } }
public ActionResult AddComment(int eventId, string comment) { ICommentsFacade commentsFacade = (ICommentsFacade)FacadeFactory.Instance.Create(FacadeType.CommentsFacade); Comments comments = new Comments(); comments.EventId = eventId; comments.Comment = comment; comments.UserId = (int)Session["UserId"]; CommentsDTO commentsDTO = new CommentsDTO(); ModelConverter.ModelConverter.FillDTOFromModel(comments, commentsDTO); OperationResult <CommentsDTO> result = commentsFacade.AddComment(commentsDTO); if (result.IsValid()) { return(RedirectToAction("EventDetails", new { EventId = eventId })); } return(RedirectToAction("EventsList")); }
// GET: Games/Comments/5 public ActionResult Comments(int?id, string errorMessage) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Game game = storage.GetGames((int)id).First(); if (game == null) { return(HttpNotFound()); } CommentsDTO model = new CommentsDTO { CommentedGame = game, ErrorMessage = errorMessage }; return(View(model)); }
public CommentsDTO CreateComments(CommentsParametersCreate commentsParametersCreate, out ReturnValues returnValues) { #region Parameters Comment comments; CommentsDTO commentsDTO = null; returnValues = new ReturnValues(); #endregion try { comments = new Comment() { GasStaionID = Convert.ToInt32(commentsParametersCreate.GasStationID), RegistrationID = Convert.ToInt32(commentsParametersCreate.RegistrationID), Comment1 = commentsParametersCreate.Comment, CreatedOn = DateTime.Now }; _unitOfWork.CommentRepository.Insert(comments); _unitOfWork.PersistChanges(); commentsDTO = new CommentsDTO { ID = comments.ID.ToString(), GasStaionID = comments.GasStaionID.ToString(), RegistrationID = comments.RegistrationID.ToString(), Comment = comments.Comment1, CreatedOn = comments.CreatedOn.ToString(), }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message + " inner --> " + ex.InnerException); } return(commentsDTO); }
//Add new Comment public CommentsDTO AddComment(CommentsDTO commentsDTO) { Comments comment = new Comments(); try { using (BookContext db = new BookContext()) { EntityConverter.FillEntityFromDTO(commentsDTO, comment); comment.User = db.Users.Where(user => user.UserId == comment.UserId).SingleOrDefault(); comment.UserName = comment.User.Name; db.Comments.Add(comment); db.SaveChanges(); } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } return(commentsDTO); }
public CommentsDTO DeleteCommentsByID(CommentsParametersDelete commentsParametersDelete, out ReturnValues returnValues) { #region Parameters Comment comments; CommentsDTO commentsDTO = null; returnValues = new ReturnValues(); int ID = Convert.ToInt32(commentsParametersDelete.ID); int registration = Convert.ToInt32(commentsParametersDelete.RegistrationID); int gasstation = Convert.ToInt32(commentsParametersDelete.GasStationID); #endregion try { comments = _unitOfWork.CommentRepository.Get(row => row.ID == ID && row.GasStaionID == gasstation && row.RegistrationID == registration); if (comments == null) { returnValues.SetReturnValues(true, ErrorCodes.NotFound, Utils.GetEnumDescription(ErrorCodes.NotFound)); return(commentsDTO); } _unitOfWork.CommentRepository.Delete(comments); _unitOfWork.PersistChanges(); commentsDTO = new CommentsDTO { ID = comments.ID.ToString(), }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message); } return(commentsDTO); }
public OperationResult <CommentsDTO> AddComment(CommentsDTO commentsDTO) { ICommentsBDC commentsBDC = (ICommentsBDC)BDCFactory.Instance.Create(BDCType.CommentsBDC); return(commentsBDC.AddComment(commentsDTO)); }
public void SyncUserStream(ISession session, Guid postId, TimeUuid updatedAtPrev) { // Get follower list var getFollowerList = session.Prepare("Select followers from post_followers where post_id = ? "); var listFollowers = session.Execute(getFollowerList.Bind(postId)); List <Guid> list = new List <Guid>(); foreach (var follower in listFollowers) { list = follower.GetValue <List <Guid> >("followers"); } //Delete post from user stream var deletePost = session.Prepare("DELETE FROM user_stream where user_id =? and last_updated_at = ?"); foreach (var follower in list) { session.Execute(deletePost.Bind(follower, updatedAtPrev)); } //Get data from posts Guid authorId = new Guid(); TimeUuid updatedAt = new TimeUuid(); string content = ""; var getPosts = session.Prepare("Select * from posts where post_id = ? "); var postsList = session.Execute(getPosts.Bind(postId)); foreach (var post in postsList) { authorId = post.GetValue <Guid>("author_id"); updatedAt = post.GetValue <TimeUuid>("updated_at"); content = post.GetValue <string>("content"); } //Get data from comments List <CommentsDTO> comments = new List <CommentsDTO>(); var getComments = session.Prepare("Select * from comments where post_id = ? "); var listComments = session.Execute(getComments.Bind(postId)); foreach (var commentRow in listComments) { CommentsDTO comment = new CommentsDTO() { CommentId = commentRow.GetValue <TimeUuid>("comment_id"), Comment = commentRow.GetValue <string>("comment"), Commentator = commentRow.GetValue <Guid>("user_id") }; comments.Add(comment); } //Insert post in user stream var insertUserStream = session.Prepare("INSERT INTO user_stream (user_id, last_updated_at , post_id , author_id , content, comments) VALUES(?,?,?,?,?,?)"); foreach (var follower in list) { session.Execute(insertUserStream.Bind(follower, updatedAt, postId, authorId, content, comments)); } }