public JsonResult AddTocart(CartViewModel model) { var userId = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]); if (userId == 0) { return(null); } try { if (ModelState.IsValid) { List <ItemDto> items = _IItem.getAllItem(); var item = items.Where(w => w.Id == model.ItemId).FirstOrDefault(); var result = _IItem.AddTocart(new CartDto { ItemId = model.ItemId, Quantity = model.Quantity, UserId = userId, PricePerItem = Convert.ToInt32(item.Price) }); return(Json(result.Id)); } } catch { throw; } return(null); }