public IHttpActionResult CreateRating([FromBody] Rating request) { string username = Utilities.GetUserNameFromRequest(Request); if (username == null) { return(BadRequest("Access Denied")); } try { User user = userService.GetUsers().FirstOrDefault(u => u.UserName.Equals(username)); if (user == null) { return(Ok()); } request.UserRateId = user.Id; request.DateCreated = DateTime.Now; request.IsDelete = false; ratingService.CreateRating(request); ratingService.SaveRating(); IEnumerable <Rating> list = null; if (request.Type == (int)RateRole.Buyer) { list = ratingService.GetRatings().Where(r => r.UserRatedId.Equals(user.Id) && r.Type == (int)RateRole.Traveller); user.BuyerScore = list.Average(r => r.Point); } else { list = ratingService.GetRatings().Where(r => r.UserRatedId.Equals(user.Id) && r.Type == (int)RateRole.Buyer); user.TravelerScore = list.Average(r => r.Point); } userService.UpdateUser(user); userService.SaveUser(); string con = userService.GetUsers().FirstOrDefault(u => u.Id.Equals(request.UserRatedId))?.SignalConnect; if (con != null) { Order order = orderService.GetOrder(request.OrderId); notificationService.CreateNotification(new Notification { DateCreated = DateTime.UtcNow.AddHours(7), IsRead = false, Message = user.LastName + " đã cho bạn " + request.Point + " sao", Title = "Đơn hàng " + order.Offer.Post.ProductName, UserId = request.UserRatedId }); notificationService.SaveNotification(); HubUtilities.GetHub().Clients.Client(con).completeOrder(user.LastName + " đã cho bạn " + request.Point + " sao", order.Id); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } return(Ok()); }
public async Task <IActionResult> CreateRating([FromBody] RatingForCreate rating) { var createdRating = await _ratingService.CreateRating(rating); return(CreatedAtAction( actionName: nameof(GetRatingById), routeValues: new { ratingId = createdRating.RatingId }, value: createdRating)); }
public async Task <IActionResult> Create([Bind("RatingId,Value")] Rating rating) { if (ModelState.IsValid) { await _ratingService.CreateRating(rating); return(RedirectToAction(nameof(Create))); } return(View(rating)); }
public async Task <IActionResult> Create([Bind("RatingId,RatingTypeName")] Rating rating) { string[] messageString = { "create", rating.RatingTypeName }; if (ModelState.IsValid) { await _ratingService.CreateRating(rating); return(Json(new { controller = "rating", message = messageString, isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAllRating", await _ratingService.GetAllRatingAsync()) })); } return(Json(new { controller = "rating", isValid = false, html = Helper.RenderRazorViewToString(this, "Create", rating) })); }
public async Task <IActionResult> Post([FromBody] RatingViewModel model) { var data = tokenDecode.DecodeJwt(_httpContextAccessor); Guid userId = Guid.Parse(data["idUser"]); Rating _rating = await _ratingService.GetRating(model.FilmId, userId); if (_rating == null) { Rating rating = _mapper.Map <RatingViewModel, Rating>(model); rating.Id = Guid.NewGuid(); rating.UserId = userId; await _ratingService.CreateRating(rating); return(Ok(rating.FilmId)); } return(Ok(model.FilmId)); }
public ActionResult <RatingDTO> CreateRating([FromHeader] string key, [FromBody] RatingCreationDTO type, int userID) { if (!_authService.Authorize(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } try { var created = _ratingService.CreateRating(type, userID); string location = linkGenerator.GetPathByAction("GetRatingID", "Rating", new { ratingID = created.RatingID }); return(Created(location, created)); } catch (Exception ex) { logger.LogError(ex, "Error creating new raiting: " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <IActionResult> PostRating(RatingCreateRequest rateRequest) { var postRating = new ProductRating { ProductId = rateRequest.ProductID, CustomerName = rateRequest.CustomerName, CustomerEmail = rateRequest.CustomerEmail, Title = rateRequest.Title, Content = rateRequest.Content, Rating = rateRequest.Rating }; var isPostSuccessRating = await _ratingService.CreateRating(postRating); if (isPostSuccessRating) { return(NoContent()); } else { return(NotFound()); } }
public ActionResult AddRating(int skillId, int value, int fieldId) { bool isUpdate = _ratingService .GetSkillUserRatings(skillId, _userService.GetUserEntityByLogin(User.Identity.Name).Id) .Any(); if (!isUpdate) { var ratingEntity = new RatingEntity { UserId = _userService.GetUserEntityByLogin(User.Identity.Name).Id, Value = value, SkillId = skillId }; _ratingService.CreateRating(ratingEntity); } else { var ratingEntity = new RatingEntity { Id = _ratingService.GetSkillUserRatings(skillId, _userService.GetUserEntityByLogin(User.Identity.Name).Id).First(r => r.SkillId == skillId).Id, UserId = _userService.GetUserEntityByLogin(User.Identity.Name).Id, Value = value, SkillId = skillId }; _ratingService.UpdateRating(ratingEntity); } if (Request.IsAjaxRequest()) { return(PartialView("_Rated")); } return(RedirectToAction("Field", new { id = fieldId })); }