public string AddUserReview([FromBody] AddUserReviewModel model) { using (var context = new AppContext()) { var userReciever = context.Users.Where(u => u.phoneNumber == model.phoneNumberReciever).ToList(); if (userReciever.Count == 0) { return("Данного пользователя не существует"); } else { var userRecieverPoints = context.UserReviewPoints.First(u => u.phoneNumber == userReciever[0].phoneNumber); var userSenderPoints = context.UserReviewPoints.First(u => u.phoneNumber == model.phoneNumberSender); if (userRecieverPoints.reviewPoints >= userSenderPoints.reviewPoints / 100) { if (model.commend == false) { userRecieverPoints.reviewPoints = userRecieverPoints.reviewPoints - userSenderPoints.reviewPoints / 100; } else { userRecieverPoints.reviewPoints = userRecieverPoints.reviewPoints + userSenderPoints.reviewPoints / 100; } } else { if (model.commend == false) { userRecieverPoints.reviewPoints = 0; } else { userRecieverPoints.reviewPoints = userRecieverPoints.reviewPoints + userSenderPoints.reviewPoints / 100; } } var reviews = context.UserReview.Where(u => u.phoneNumberSender == model.phoneNumberSender & u.phoneNumberReceiver == model.phoneNumberReciever).ToList(); if (reviews.Count == 0) { UserReviewModel review = new UserReviewModel() { phoneNumberSender = model.phoneNumberSender, phoneNumberReceiver = model.phoneNumberReciever, review = model.review, commend = model.commend }; context.UserReview.Add(review); context.SaveChanges(); return("Успешно"); } else { reviews[0].review = model.review; reviews[0].commend = model.commend; context.SaveChanges(); return("Успешно"); } } } }
public JsonResult SubmitUserReview(UserReviewModel model) { var userId = Convert.ToInt64(Session["UserId"]); if (userId != 0) { model.CustomerId = userId; var status = propertyService.SubmitUserReview(model); return(Json(status, JsonRequestBehavior.AllowGet)); } else { return(Json("Session Expired", JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult SubmitUserReview(UserReviewModel model) { if (model == null) { return(this.Ok(new { status = false, message = Resource.fill_required_records, })); } var status = propertyService.SubmitUserReview(model); return(this.Ok(new { status = status, message = propertyService.message, })); }