public HttpResponseMessage Add(int conferenceId, [FromBody] CommentBase comment)
        {
            switch (comment.Visibility)
            {
            case 0:     // just the authors
                if (!ConferenceModuleContext.Security.IsPresenter(comment.SessionId))
                {
                    return(AccessViolation("You need to be a presenter to submit this comment"));
                }
                break;

            case 1:     // between authors and managers
                if (!(ConferenceModuleContext.Security.IsPresenter(comment.SessionId) | ConferenceModuleContext.Security.CanManage))
                {
                    return(AccessViolation("You need to be a presenter or manager to submit this comment"));
                }
                break;

            default:
                if (UserInfo.UserID <= 0)
                {
                    return(AccessViolation("You need to be logged in to submit a comment"));
                }
                break;
            }
            comment.ConferenceId = conferenceId;
            comment.UserId       = UserInfo.UserID;
            comment.Datime       = System.DateTime.Now;
            CommentRepository.Instance.AddComment(ref comment);
            return(Request.CreateResponse(HttpStatusCode.OK, CommentRepository.Instance.GetComment(conferenceId, comment.CommentId)));
        }
Example #2
0
        public IHttpActionResult addComment(CommentBase data)
        {
            lock (DB)
            {
                RideBase           ride    = DB.RideDb.ToList().Find(p => p.ID == data.ID);
                List <CommentBase> comment = DB.CommentDb.ToList();
                if (!comment.Exists(p => p.RideID == data.ID))
                {
                    if (ride.Status == RideStatus.Canceled)
                    {
                        data.Stars = 0;
                    }
                    DB.CommentDb.Add(new CommentBase()
                    {
                        CommentDate    = DateTime.Now.ToString(),
                        Stars          = data.Stars,
                        Summary        = data.Summary,
                        OriginalPoster = AuthUser.Username,
                        RideID         = ride.ID
                    });
                    ride.CommentID = data.ID;

                    DB.SaveChanges();

                    return(Ok(DB.CommentDb.ToList().Find(p => p.RideID == data.ID)));
                }
                return(NotFound());
            }
        }
 public IHttpActionResult getComment(int id)
 {
     lock (DB)
     {
         CommentBase comment = DB.CommentDb.ToList().Find(p => p.RideID == id);
         return(Ok(comment ?? new CommentBase()));
     }
 }
 public int AddComment(ref CommentBase comment)
 {
     Requires.NotNull(comment);
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <CommentBase>();
         rep.Insert(comment);
     }
     return(comment.CommentId);
 }
 public void UpdateComment(CommentBase comment)
 {
     Requires.NotNull(comment);
     Requires.PropertyNotNegative(comment, "CommentId");
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <CommentBase>();
         rep.Update(comment);
     }
 }
Example #6
0
        public static void CheckAndSendNotifications(CommentBase comment)
        {
            var notifications = new List <Notification>();

            switch (comment.Visibility)
            {
            case 0:     // just the authors
            case 1:     // between authors and managers
                if (comment.SessionId != -1)
                {
                    // General comment
                    var speakers = SessionSpeakerRepository.Instance.GetSessionSpeakersBySession(comment.SessionId)
                                   .Select(ss => ss.SpeakerId);
                    var attendeesToNotify = AttendeeRepository.Instance.GetAttendeesByConference(comment.ConferenceId)
                                            .Where(a => speakers.Contains(a.UserId) &&
                                                   a.UserId != comment.UserId);
                    foreach (var attendee in attendeesToNotify)
                    {
                        notifications.Add(new Notification()
                        {
                            to    = attendee.NotificationToken,
                            title = "Conference comment",
                            body  = comment.Remarks
                        });
                    }
                }
                break;

            case 2:     // management comment
                if (comment.SessionId == -1)
                {
                    // General comment
                    var attendeesWithToken = AttendeeRepository.Instance.GetAttendeesByConference(comment.ConferenceId)
                                             .Where(a => a.HasNotificationToken &&
                                                    a.NotificationToken.StartsWith("ExponentPushToken") &&
                                                    a.UserId != comment.UserId);
                    foreach (var attendee in attendeesWithToken)
                    {
                        notifications.Add(new Notification()
                        {
                            to    = attendee.NotificationToken,
                            title = "Conference comment",
                            body  = comment.Remarks
                        });
                    }
                }
                break;
            }
            if (notifications.Count > 0)
            {
                SendNotifications(notifications);
            }
        }
Example #7
0
 public HttpResponseMessage Add(int id, [FromBody] CommentBase data)
 {
     if (UserInfo.UserID <= 0)
     {
         return(AccessViolation("You need to be logged in to submit a comment"));
     }
     data.FlightId = id;
     data.UserId   = UserInfo.UserID;
     data.Datime   = System.DateTime.Now;
     CommentRepository.Instance.AddComment(ref data);
     return(Request.CreateResponse(HttpStatusCode.OK, CommentRepository.Instance.GetComment(id, data.CommentId)));
 }
Example #8
0
        public HttpResponseMessage Delete(int id, [FromBody] CommentBase data)
        {
            var comment = CommentRepository.Instance.GetComment(id, data.CommentId);

            if (comment != null)
            {
                if (comment.UserId == UserInfo.UserID | BalisesModuleContext.Security.IsAdmin)
                {
                    CommentRepository.Instance.DeleteComment(id, data.CommentId);
                }
                else
                {
                    return(AccessViolation("You're not allowed to delete this comment"));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, ""));
        }
Example #9
0
        public void CreateComment()
        {
            //Login добавить
            CommentBase jsonString = new CommentBase {
                PostId = "121",
                Text   = "Good post"
            };
            RestApiHelper <CommentBase> resultAPI = new RestApiHelper <CommentBase>();
            var client  = resultAPI.FullURL("/api/comments");
            var request = resultAPI.CreatePostRequest(jsonString);
            //request.AddHeader("Authorization", $"Bearer {}");
            var response = resultAPI.GetResponse(client, request);
            var content  = resultAPI.GetContent <CommentBase>(response);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            //Assert.AreEqual("121", result.PostId);
        }
        public IHttpActionResult AddComment(CommentBase data)
        {
            lock (DB)
            {
                RideBase           ride    = DB.RideDb.ToList().Find(x => x.TaxiRiderID == DB.DriverDb.ToList().Find(y => y.Username == AuthUser.Username).ID&& x.ID == currentRideID);
                List <CommentBase> comment = DB.CommentDb.ToList();
                if (!comment.Exists(p => p.RideID == data.ID))
                {
                    DB.CommentDb.Add(new CommentBase()
                    {
                        CommentDate    = DateTime.Now.ToString(),
                        Stars          = data.Stars,
                        Summary        = data.Summary,
                        OriginalPoster = AuthUser.Username,
                        RideID         = currentRideID
                    });
                    ride.CommentID = data.ID;
                    DB.SaveChanges();

                    return(Ok());
                }
                return(NotFound());
            }
        }
Example #11
0
 public void Setup()
 {
     TestSupport.Core.Factory fac = new TestSupport.Core.Factory();
     _el = fac.CreateDummyCommentBase(Guid.NewGuid());
     _asIParentId = _el as IParentId;
     _asISetId = _el;
     _asIIdGetter = _el;
     _asISetParentId = _el as ISetParentId;
 }
Example #12
0
 /// <summary>
 /// Build a minimal row from a class (key fields only)
 /// </summary>
 public static void BuildMinimalRow(ref DataRow row, Comment entity)
 {
     CommentBase.BuildMinimalRow(ref row, entity);
 }