예제 #1
0
        public JsonResult DuyetPostTin(int id, ProductStatus status)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                    return(Json(allErrors, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var sp = _sanphamService.GetById(id);
                    sp.Status = status;
                    _sanphamService.Update(sp);
                    if (_sanphamService.Save())
                    {
                        return(Json(new { Result = sp, Status = "OK" }, JsonRequestBehavior.AllowGet));
                    }
                }


                return(Json(new { Result = "", Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = ex.Message, Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
 public JsonResult Like(int id)
 {
     try
     {
         if (Session[CommonConstrants.USER_SESSION] != null)
         {
             var     spVm = _sanphamService.GetById(id);
             var     user = _userService.GetUser(UserLoginViewModel.Current.KeyId);
             Sanpham sp   = Mapper.Map <SanphamViewModel, Sanpham>(spVm);
             user.KhachhangNavigation.SanPhamYeuThichs.Add(sp);
             _sanphamService.Save();
             return(Json(new { Result = Notification.LIKE_PRODUCT, Status = "OK" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { Result = Notification.LIKE_NOT_LOGIN, Status = "FAIL" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(Json(new { Result = ex.Message, Status = "FAIL" }, JsonRequestBehavior.AllowGet));
     }
 }