public ActionResult Read([DataSourceRequest] DataSourceRequest request) { if (asset.View) { var data = new Product_Info_DAO().ReadAll(""); return(Json(data.ToDataSourceResult(request))); } else { return(RedirectToAction("NoAccessRights", "Error")); } }
public ActionResult Upsert(Product_Info item, HttpPostedFileBase file, string type) { if (asset.Create || asset.Update) { string result = ""; try { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var refix = "Product_Info_" + currentUser.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); Helpers.UploadFile.CreateFolder(Server.MapPath("~/Images/Product_Info/")); var path = Path.Combine(Server.MapPath("~/Images/Product_Info/"), refix + Path.GetExtension(fileName)); file.SaveAs(path); item.url = refix + Path.GetExtension(fileName); } List <Product_Info> lstProdInfo = new List <Product_Info>(); lstProdInfo.Add(item); string Type = (item.id == 0) ? "Insert" : "Update"; Type = (type == "Sync") ? "Sync" : Type; result = new Product_Info_DAO().UpSert(lstProdInfo, currentUser.UserName, Type, ""); if (result == "true") { if (item.id == 0)// 0 insert, 1 update { return(Json(new { success = true, type = Type })); } else { return(Json(new { success = true, type = Type })); } } else { return(Json(new { success = false, message = result, type = Type })); } } catch (Exception e) { return(Json(new { success = false, message = "Có lỗi file upload" + e.Message })); } } else { return(Json(new { success = false, message = "Bạn không có quyền." })); } }
public string GetAll(string key) { try { if (AllConstant.KeyAPI == key) { DataTable dt = new Product_Info_DAO().ReadAll(AllConstant.ERPConnectionString); string st = JsonConvert.SerializeObject(dt); return(st); } return(""); } catch (Exception ex) { return(ex.ToString()); } }
public ActionResult Delete(string data) { if (asset.Delete) { string result = ""; string[] st = new string[1]; st[0] = data; result = new Product_Info_DAO().Delete(st, "").ToString(); if (result == "true") { return(Json(new { success = true, message = "Thành công" })); } else { return(Json(new { success = false, message = result })); } } else { return(Json(new { success = false, message = "Bạn không có quyền xóa" })); } }