public IHttpActionResult UpdateComment(int id, AddCommentBindingModel model)
        {
            var comment = this.Data.Comments.Find(id);

            if (comment == null)
            {
                return this.BadRequest(string.Format("There is no comment with Id {0}", id));
            }

            var loggedUserId = this.User.Identity.GetUserId();

            if (comment.AuthorId != loggedUserId)
            {
                return this.Unauthorized();
            }

            if (model == null)
            {
                return this.BadRequest("Model cannot be null (no data in request)");
            }

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            comment.Content = model.Content;

            var notification = new Notification()
            {
                RecieverId = comment.Trip.DriverId,
                Type = NotificationType.Comment
            };

            this.Data.Notifications.Add(notification);
            this.Data.SaveChanges();

            var data = this.Data.Comments
                .All().Where(t => t.Id == comment.Id)
                .Select(CommentViewModel.Create)
                .FirstOrDefault();

            return this.Ok(data);
        }
        public IHttpActionResult PostComment(int id, AddCommentBindingModel model)
        {
            var trip = this.Data.Trips.Find(id);

            if (model == null)
            {
                return this.BadRequest("Model cannot be null (no data in request)");
            }

            if (trip == null)
            {
                return this.BadRequest("Trip does not exist");
            }

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var comment = new Comment()
            {
                AuthorId = this.User.Identity.GetUserId(),
                Content = model.Content,
                PostedOn = DateTime.Now,
                TripId = id
            };

            var notification = new Notification()
            {
                RecieverId = trip.DriverId,
                Type = NotificationType.Comment
            };

            trip.Comments.Add(comment);
            this.Data.Notifications.Add(notification);
            this.Data.SaveChanges();

            var data = this.Data.Comments
                .All().Where(t => t.Id == comment.Id)
                .Select(CommentViewModel.Create)
                .FirstOrDefault();

            return this.Ok(data);
        }
        public IHttpActionResult JoinTrip(int id)
        {
            var trip = this.Data.Trips.Find(id);
            if (trip == null)
            {
                return this.BadRequest("No such trip!");
            }

            if (trip.AvailableSeats == 0)
            {
                return this.BadRequest("Trip is full!");
            }

            var loggedUserId = this.User.Identity.GetUserId();
            var user = this.Data.Users.Find(loggedUserId);

            if (user.JoinedTrips.Any(t => t.Id == trip.Id))
            {
                return this.BadRequest("You have already joined this trip!");
            }

            if (loggedUserId == trip.DriverId)
            {
                return this.BadRequest("You cannot join your own trip!");
            }

            trip.AvailableSeats = --trip.AvailableSeats;
            user.JoinedTrips.Add(trip);

            var notification = new Notification()
            {
                RecieverId = trip.DriverId,
                Type = NotificationType.Join
            };

            this.Data.Notifications.Add(notification);

            this.Data.SaveChanges();
            return this.Ok();
        }