Пример #1
0
        public int RemoveReviewAndRating(ReviewAndRating reviewAndRating)
        {
            reviewAndRating.UpdatedDate = DateTime.UtcNow;
            reviewAndRating.RowStatus   = "D";
            var result = reviewContext.Update(reviewAndRating);

            return(result);
        }
Пример #2
0
        public async Task <int> RemoveReviewAndRatingAsync(ReviewAndRating reviewAndRating)
        {
            reviewAndRating.UpdatedDate = DateTime.UtcNow;
            reviewAndRating.RowStatus   = "D";
            var result = await reviewContext.UpdateAsync(reviewAndRating);

            return(result);
        }
Пример #3
0
        public ReviewAndRating AddReviewAndRating(ReviewAndRating reviewAndRating)
        {
            reviewAndRating.CreatedDate = DateTime.UtcNow;
            reviewAndRating.RowStatus   = "I";
            var result = reviewContext.Insert(reviewAndRating);

            return(result);
        }
Пример #4
0
        public async Task <ReviewAndRating> AddReviewAndRatingAsync(ReviewAndRating reviewAndRating)
        {
            reviewAndRating.CreatedDate = DateTime.UtcNow;
            reviewAndRating.RowStatus   = "I";
            var result = await reviewContext.InsertAsync(reviewAndRating);

            return(result);
        }
        public async Task <IHttpActionResult> PutReviewAndRating(int id, [FromBody] ReviewAndRatingDTO reviewAndRatingDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await reviewServices.FindReviewAndRatingAsync(id) == null)
            {
                return(BadRequest());
            }

            var review = await reviewServices.GetReviewAndRatingAsync(id);

            ReviewAndRating reviewAndRating = new ReviewAndRating
            {
                CreatedDate = review.CreatedDate,
                HelperId    = review.HelperId,
                ReviewId    = review.ReviewId,
                UserId      = review.UserId
            };

            if (reviewAndRatingDTO.Ratings != null)
            {
                reviewAndRating.Rating = (int)reviewAndRatingDTO.Ratings;
            }
            else
            {
                reviewAndRating.Rating = review.Rating;
            }
            if (reviewAndRatingDTO != null)
            {
                reviewAndRating.Review = reviewAndRatingDTO.Reviews;
            }
            else
            {
                reviewAndRating.Review = review.Review;
            }

            try
            {
                await reviewServices.UpdateReviewAndRatingAsync(reviewAndRating);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewAndRatingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetReviewAndRating(int id)
        {
            ReviewAndRating reviewAndRating = await reviewServices.GetReviewAndRatingAsync(id);

            if (reviewAndRating == null)
            {
                return(NotFound());
            }

            return(Ok(reviewAndRating));
        }
        public async Task <IHttpActionResult> DeleteReviewAndRating(int id)
        {
            ReviewAndRating reviewAndRating = await db.ReviewAndRatings.FindAsync(id);

            if (reviewAndRating == null)
            {
                return(NotFound());
            }

            db.ReviewAndRatings.Remove(reviewAndRating);
            await db.SaveChangesAsync();

            return(Ok(reviewAndRating));
        }
        public async Task <IHttpActionResult> PostReviewAndRating([FromBody] ReviewAndRatingDTO reviewAndRatingDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ReviewAndRating reviewAndRating = new ReviewAndRating
            {
                HelperId = reviewAndRatingDTO.HelperId,
                UserId   = reviewAndRatingDTO.UserId,
                Rating   = (int)reviewAndRatingDTO.Ratings,
                Review   = reviewAndRatingDTO.Reviews
            };

            await reviewServices.AddReviewAndRatingAsync(reviewAndRating);

            return(Ok(reviewAndRating.ReviewId));
        }
Пример #9
0
        public HttpResponseMessage SaveReviewAndRating([FromBody] ReviewAndRatingModel ReviewAndRatingModel)
        {
            try
            {
                if (ReviewAndRatingModel.CustomerId == new Guid())
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }

                if (ReviewAndRatingModel.JobRequestId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "JobRequest Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (ReviewAndRatingModel.Rating == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Rating is blank."), Configuration.Formatters.JsonFormatter));
                }
                //if (ReviewAndRatingModel.Rating > 5)
                //{
                //    return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Rating cant be greater than 5."), Configuration.Formatters.JsonFormatter);
                //}



                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == ReviewAndRatingModel.CustomerId && c.IsActive == true).FirstOrDefault();
                if (customer != null)
                {
                    var job = _RequestService.GetRequest(ReviewAndRatingModel.JobRequestId);
                    if (job == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "job not found."), Configuration.Formatters.JsonFormatter));
                    }
                    if (job.JobStatus != EnumValue.GetEnumDescription(EnumValue.JobStatus.Completed))
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "job is not completed yet."), Configuration.Formatters.JsonFormatter));
                    }
                    var jobFound = _ReviewAndRatingService.GetReviewAndRatings().Where(f => f.CustomerId == ReviewAndRatingModel.CustomerId && f.JobRequestId == ReviewAndRatingModel.JobRequestId).FirstOrDefault();
                    if (jobFound == null)
                    {
                        Mapper.CreateMap <ReviewAndRatingModel, ReviewAndRating>();
                        ReviewAndRating reviewAndRating = Mapper.Map <ReviewAndRatingModel, ReviewAndRating>(ReviewAndRatingModel);
                        _ReviewAndRatingService.InsertReviewAndRating(reviewAndRating);

                        var    customerBy  = _CustomerService.GetCustomer(ReviewAndRatingModel.CustomerId);
                        string UserMessage = "You have new reviews.";

                        string NotificationType = "reviews";
                        string Flag             = "NewReviews";

                        //Save notification in Table
                        Notification Notification = new Notification();
                        Notification.NotificationId = 0; //New Case
                        //Notification.ClientId = _Event.ClientID; Save it as NULL
                        Notification.CustomerIdBy = customerBy.CustomerId;
                        //Notification.CustomerIdTo = customerTo.CustomerId;
                        //Notification.EventID = _Event.EventID; Save it as NULL
                        Notification.UserMessage      = UserMessage;
                        Notification.NotificationType = NotificationType;
                        Notification.Flag             = Flag;
                        Notification.DeviceType       = customerBy.DeviceType;
                        _NotificationService.InsertNotification(Notification);
                        //        //End : Save notification in Table
                        string ApplicationId = "";
                        string DeviceType    = "";
                        if (job.CustomerIdBy == customerBy.CustomerId)
                        {
                            ApplicationId = _CustomerService.GetCustomer(job.CustomerIdTo).ApplicationId;
                            DeviceType    = _CustomerService.GetCustomer(job.CustomerIdTo).DeviceType;
                        }
                        else
                        {
                            ApplicationId = _CustomerService.GetCustomer(job.CustomerIdBy).ApplicationId;
                            DeviceType    = _CustomerService.GetCustomer(job.CustomerIdBy).DeviceType;
                        }
                        string Message = "{\"flag\":\"" + Flag + "\",\"JobRequestId\":\"" + ReviewAndRatingModel.JobRequestId + "\",\"UserMessage\":\"" + UserMessage + "\"}";

                        if (ApplicationId != null && ApplicationId != "")
                        {
                            if (DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android))
                            {
                                //Send Notification another Andriod
                                CommonCls.SendFCM_Notifications(ApplicationId, Message, true);
                            }
                            else
                            {
                                string Msg = UserMessage;

                                CommonCls.TestSendFCM_Notifications(ApplicationId, Message, Msg, true);
                            }
                        }

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Reviews saved successfully."), Configuration.Formatters.JsonFormatter));
                    }
                    else
                    {
                        jobFound.Rating = (ReviewAndRatingModel.Rating != 0 ? ReviewAndRatingModel.Rating : jobFound.Rating);
                        jobFound.Review = (ReviewAndRatingModel.Review != null && ReviewAndRatingModel.Review != "") ? ReviewAndRatingModel.Review : jobFound.Review;
                        _ReviewAndRatingService.UpdateReviewAndRating(jobFound);
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Reviews updated successfully."), Configuration.Formatters.JsonFormatter));
                    }
                }

                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }