public HttpResponseMessage UpdateRating(RatingAPIViewModel rating) { HttpResponseMessage responseMessage = new HttpResponseMessage(); BaseResponse <RatingAPIViewModel> response = new BaseResponse <RatingAPIViewModel>(); try { var domain = new RatingDomain(); response = domain.UpdateRatingProduct(rating); } catch (ApiException e) { // catch ApiException responseMessage.StatusCode = e.StatusCode; response = BaseResponse <RatingAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <RatingAPIViewModel> .Get(false, ex.ToString(), null, ResultEnum.InternalError); } //return responseMessage.Content = new JsonContent(response); return(responseMessage); throw new NotImplementedException(); }
public ResponseObject <bool> CreateRatingForHero(RatingAPIViewModel rate) { var ticketService = this.Service <ITicketService>(); var rs = ticketService.CreateRatingForHero(rate); return(rs); }
public RatingAPIViewModel CreateRatingProduct(RatingAPIViewModel rating) { var RatingProductE = rating.ToEntity(); RatingProductE.UserId = null; this.Create(RatingProductE); return(new RatingAPIViewModel(RatingProductE)); }
public RatingAPIViewModel UpdateRatingProduct(RatingAPIViewModel rating) { var ratingE = Repository.FirstOrDefault(c => c.Id == rating.Id); if (ratingE != null) { var ratingET = rating.ToEntity(); Repository.Edit(ratingET); Repository.Save(); rating = new RatingAPIViewModel(ratingET); return(rating); } return(null); }
public ResponseObject <bool> CreateRatingForHero(RatingAPIViewModel rate) { try { var requestRepo = DependencyUtils.Resolve <IRequestRepository>(); var itSupporterlRepo = DependencyUtils.Resolve <IITSupporterRepository>(); var request = requestRepo.GetActive(p => p.RequestId == rate.RequestId && p.RequestStatus == (int)RequestStatusEnum.Done).SingleOrDefault(); if (request != null) { var itupporter = itSupporterlRepo.Get(request.CurrentITSupporter_Id); if (request != null && itupporter != null) { request.Rating = rate.Rating; request.Feedback = rate.Description; request.UpdateDate = DateTime.UtcNow.AddHours(7); requestRepo.Edit(request); requestRepo.Save(); var requestRating = requestRepo.GetActive(p => p.CurrentITSupporter_Id == itupporter.ITSupporterId && p.Rating != null).ToList(); //itupporter.RatingAVG = itupporter.RatingAVG != null && itupporter.RatingAVG != 0 ? (itupporter.RatingAVG + rate.Rating) / 2 : rate.Rating; var sumRating = (double)requestRating.Sum(r => r.Rating); int countRating = requestRating.Count(); itupporter.RatingAVG = Math.Round((sumRating / countRating), 1); itupporter.UpdateDate = DateTime.UtcNow.AddHours(7); itSupporterlRepo.Edit(itupporter); itSupporterlRepo.Save(); return(new ResponseObject <bool> { IsError = false, ObjReturn = true, SuccessMessage = "Đánh giá thành công" }); } } return(new ResponseObject <bool> { IsError = true, ObjReturn = false, SuccessMessage = "Đánh giá thất bại" }); } catch (Exception e) { return(new ResponseObject <bool> { IsError = true, ObjReturn = false, SuccessMessage = "Đánh giá thất bại", ErrorMessage = e.ToString() }); } }
public BaseResponse <RatingAPIViewModel> UpdateRatingProduct(RatingAPIViewModel rating) { var service = this.Service <IRatingService>(); var list = service.GetRatingByProductId(rating.Id); if (list == null) { throw ApiException.Get(false, ConstantManager.MES_RATINGPRODUCT_NOTEXIST, ResultEnum.RatingProductNotExist, HttpStatusCode.BadRequest); } var service2 = this.Service <IProductService>(); var list2 = service2.GetProductById(rating.ProductId.Value); if (list2 == null) { throw ApiException.Get(false, ConstantManager.MES_PRODUCT_NOTEXIST, ResultEnum.ProductNotExist, HttpStatusCode.BadRequest); } var rt = service.UpdateRatingProduct(rating); return(BaseResponse <RatingAPIViewModel> .Get(true, ConstantManager.MES_RATINGPRODUCT_UPDATE_SUCCESS, rt, ResultEnum.Success)); }
public HttpResponseMessage CreateSubRating(RatingAPIViewModel rating) { HttpResponseMessage responseMessage = new HttpResponseMessage(); BaseResponse <RatingAPIViewModel> response = new BaseResponse <RatingAPIViewModel>(); try { var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; // get Id from Token Claims var customerId = claimPrincipal.Claims.Where(c => c.Type == "CustomerId").Select(c => c.Value).SingleOrDefault(); int customerID = 0; Int32.TryParse(customerId, out customerID); DateTime time = DataService.Models.Utils.GetCurrentDateTime(); var domain = new RatingDomain(); rating.CreateTime = time; rating.Active = true; rating.CustomerId = customerID; response = domain.CreateSubRating(rating); } catch (ApiException e) { // catch ApiException responseMessage.StatusCode = e.StatusCode; response = BaseResponse <RatingAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <RatingAPIViewModel> .Get(false, ex.ToString(), null, ResultEnum.InternalError); } //return responseMessage.Content = new JsonContent(response); return(responseMessage); }
public HttpResponseMessage CreateRatingForHero(RatingAPIViewModel rate) { var result = _ticketDomain.CreateRatingForHero(rate); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public BaseResponse <RatingAPIViewModel> CreateRatingProduct(RatingAPIViewModel rating) { var service = this.Service <IRatingService>(); var productService = this.Service <IProductService>(); var customerService = this.Service <ICustomerService>(); var orderService = this.Service <IOrderService>(); try { if (rating.CustomerId == 0) { throw ApiException.Get(false, ConstantManager.MES_CUSTOMER_NOTFOUND, ResultEnum.CustomerIdInTokenWrong, HttpStatusCode.BadRequest); } var customer = customerService.GetCustomerById(rating.CustomerId.Value); if (customer == null) { throw ApiException.Get(false, ConstantManager.MES_CUSTOMER_NOTFOUND, ResultEnum.CustomerNotFound, HttpStatusCode.BadRequest); } else { if (rating.ProductId != null && rating.OrderId != null) { throw ApiException.Get(false, ConstantManager.MES_RATE_VALID, ResultEnum.RateValid, HttpStatusCode.BadRequest); } else { rating.ReviewEmail = customer.Email; rating.ReviewName = customer.Name; rating.Verified = false; if (rating.ProductId != null) { var check = productService.GetProductById(rating.ProductId.Value); if (check == null) { throw ApiException.Get(false, ConstantManager.MES_PRODUCT_NOTEXIST, ResultEnum.ProductNotExist, HttpStatusCode.BadRequest); } } if (rating.OrderId != null) { var check = orderService.GetOrderById(rating.OrderId.Value); if (check == null) { throw ApiException.Get(false, ConstantManager.MES_ORDER_NOT_FOUND, ResultEnum.OrderNotFound, HttpStatusCode.BadRequest); } if (check.CustomerID != rating.CustomerId) { throw ApiException.Get(false, ConstantManager.MES_REQUEST_DENY, ResultEnum.CustomerIdNotMatch, HttpStatusCode.BadRequest); } } var rt = service.CreateRatingProduct(rating); return(BaseResponse <RatingAPIViewModel> .Get(true, ConstantManager.MES_RATING_CREATE_SUCCESS, rt, ResultEnum.Success)); } } } catch (Exception ex) { if (ex is ApiException) { throw ex; } else { throw ApiException.Get(false, ConstantManager.MES_RATING_CREATE_FAIL, ResultEnum.CreateFail, HttpStatusCode.InternalServerError); } } }