// Create public ActionResult Create([FromBody] EvalueteReq req) { if (req.productId < 1 || req.numberStar < 0 || req.numberStar > 5) { return(BadRequest()); } else { // Take info about current user var identity = HttpContext.User.Identity as ClaimsIdentity; IList <Claim> claims = identity.Claims.ToList(); var username = claims[0].Value; // Check user bought var check = _context.Orders.Join( _context.OrderDetails, o => o.OrderId, od => od.OrderId, (o, od) => new { customerId = o.CustomerId, productId = od.ProductId } ).Where(x => x.customerId == username && x.productId == req.productId); if (check.Count() < 1) { return(BadRequest("Bạn không thể đánh giá sản phẩm vì bạn chưa mua sản phẩm này")); } else { Evaluates evaluates = new Evaluates { CustomerId = username, ProductId = req.productId, NumberStar = req.numberStar }; try { var res = _context.Evaluates.Add(evaluates); _context.SaveChanges(); return(Ok()); } catch (Exception) { return(BadRequest()); } } } }
public static Evaluates ToEntity(ViewEvaluates model) { Evaluates item = new Evaluates(); item.Evaluateid = model.Evaluateid; item.CreateDate = model.CreateDate; item.EContent = model.EContent; item.ToUid = model.ToUid; item.FromUid = model.FromUid; item.iZan = model.iZan; item.iShow = model.iShow; item.ParentID = model.ParentID; item.Recommend = model.Recommend; item.Pic = model.Pic; return(item); }
public static ViewEvaluates ToViewModel(Evaluates model) { if (model == null) { return(null); } ViewEvaluates item = new ViewEvaluates(); item.Evaluateid = model.Evaluateid; item.CreateDate = model.CreateDate; item.EContent = model.EContent; item.ToUid = model.ToUid; item.FromUid = model.FromUid; item.iZan = model.iZan; item.iShow = model.iShow; item.ParentID = model.ParentID; item.Recommend = model.Recommend; item.Pic = model.Pic; return(item); }