public JsonResult CreateFoodAjax(HttpPostedFileBase file, string tenmonan, int loaimonanID) { try { MonAnDAO objDAO = new MonAnDAO(); MonAn objMonAn = new MonAn(); objMonAn.MaMonAn = XuLy.NextID(objDAO.getLastID(), "MA"); objMonAn.TenMonAn = tenmonan; int dataLength = (int)file.InputStream.Length; byte[] _byteArr = new byte[dataLength]; file.InputStream.Read(_byteArr, 0, dataLength); objMonAn.HinhAnh = _byteArr; objMonAn.MaLoaiMonAn = loaimonanID.ToString(); int result = objDAO.insertMonAn(objMonAn); if (result == 2) { return(Json(new { iserror = false, isExist = true })); } else { if (result == 1) { return(Json(new { iserror = false, isExist = false })); } } return(Json(new { iserror = true, messageError = "Đã xảy ra lỗi khi thêm mới. Vui lòng kiểm tra lại!" })); } catch (Exception ex) { return(Json(new { iserror = true, messageError = ex.Message })); } }