コード例 #1
0
 public ActionResult Delete(CategoryModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteCategory(model.ID, ref msg);
         if (!result)
         {
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         HttpCookie      _LocationCookie = Request.Cookies["CateCookie"];
         CategoryFactory _facLoc         = new CategoryFactory();
         var             _loc            = _facLoc.GetListCategory().Select(x => new CateSession
         {
             Id   = x.ID,
             Name = x.Name
         }).ToList();
         if (_loc != null && _loc.Any())
         {
             string     myObjectJson = JsonConvert.SerializeObject(_loc); //new JavaScriptSerializer().Serialize(userSession);
             HttpCookie cookie       = new HttpCookie("CateCookie");
             cookie.Expires = DateTime.Now.AddYears(10);
             cookie.Value   = Server.UrlEncode(myObjectJson);
             Response.Cookies.Add(cookie);
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Xóa thể loại: ", ex);
         ModelState.AddModelError("Name", ("Lỗi khi xóa thông tin thể loại!"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }