Example #1
0
        public async Task CommentSpecificEvent(EventCommentModel model)
        {
            var query = await(from events in this._dbContext.Events where events.Id == model.EventId select events)
                        .FirstOrDefaultAsync();

            var userInfo = await this._userManager.FindByNameAsync(model.Username);

            var newComment = new EventComments()
            {
                Comment   = model.Comment,
                TimeStamp = DateTime.Now,
                EventId   = query.Id,
                UserId    = userInfo.Id
            };

            try
            {
                this._dbContext.EventComments.Add(newComment);
                await this._dbContext.SaveChangesAsync();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
Example #2
0
        public async Task RemoveCommentFromEvent(EventCommentModel model)
        {
            var comment =
                await(from comments in this._dbContext.EventComments where model.Id == comments.Id select comments)
                .FirstOrDefaultAsync();

            if (comment != null)
            {
                this._dbContext.Remove(comment);
                await this._dbContext.SaveChangesAsync();
            }
        }
        private List <EventCommentModel> ConvertEventComments(List <EventComments> input, int eventId)
        {
            List <EventCommentModel> output = new List <EventCommentModel>();

            foreach (EventComments e in input)
            {
                EventCommentModel m = new EventCommentModel()
                {
                    Comment   = e.Comment,
                    Name      = e.FirstName + " " + e.LastName,
                    CommentId = e.CommentId,
                    EventId   = eventId
                };

                output.Add(m);
            }

            return(output);
        }
Example #4
0
        public async Task <IActionResult> AddNewCommentAsync([FromBody] EventCommentModel model)
        {
            await this._eventsManager.CommentSpecificEvent(model);

            return(Ok());
        }
Example #5
0
        public async Task <IActionResult> DeleteCommentEvent([FromBody] EventCommentModel model)
        {
            await this._eventsManager.RemoveCommentFromEvent(model);

            return(Ok());
        }