Пример #1
0
        public IHttpActionResult CommentRideComplete(CommentRideBindingModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

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

            var user = unitOfWork.AppUsers.FirstOrDefault(u => u.Email == User.Identity.Name && u.Deleted == false);

            if (user == null)
            {
                return(BadRequest());
            }

            Ride ride = unitOfWork.Rides.FirstOrDefault(r => r.Id == model.Ride.Id);

            if (ride == null)
            {
                return(BadRequest("No ride found"));
            }

            Comment comment = new Comment()
            {
                Content     = model.UserComment.Content,
                Username    = user.Username,
                Rating      = model.UserComment.Rating,
                AppUser     = user,
                AppUserID   = user.Id,
                Ride        = ride,
                RideID      = ride.Id,
                DateCreated = DateTime.Now,
                Deleted     = false
            };

            try
            {
                unitOfWork.Comments.Add(comment);
            }
            catch (Exception e)
            {
                return(BadRequest("Error while trying to add Comment"));
            }

            unitOfWork.Complete();

            return(Ok());
        }
Пример #2
0
        public IHttpActionResult CancelRideComplete(CommentRideBindingModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

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

            if (model.Ride.Dispatcher != null)
            {
                return(BadRequest("You can not cancel a drive made by dispatcher"));
            }

            var user = unitOfWork.AppUsers.FirstOrDefault(u => u.Email == User.Identity.Name && u.Deleted == false);

            model.Ride.Status  = Status.Cancelled;
            model.Ride.Deleted = true;

            try
            {
                unitOfWork.Rides.Update(model.Ride);
            }
            catch (Exception e)
            {
                return(BadRequest("Error while trying to cancel ride"));
            }

            model.UserComment.AppUser     = user;
            model.UserComment.Username    = user.Username;
            model.UserComment.AppUserID   = user.Id;
            model.UserComment.Ride        = model.Ride;
            model.UserComment.RideID      = model.Ride.Id;
            model.UserComment.DateCreated = DateTime.Now;
            model.UserComment.Deleted     = false;

            try
            {
                unitOfWork.Comments.Add(model.UserComment);
            }
            catch (Exception e)
            {
                return(BadRequest("Error while trying to add Comment"));
            }

            unitOfWork.Complete();

            return(Ok());
        }