/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(StoExportContract stoexport, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Sto_Export VALUES ({0},{1},{2},{3},{4},convert(datetime,{5},103),{6})", (stoexport.Salestaffid != null? stoexport.Salestaffid.ToString() : "null").ToString(), (stoexport.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(stoexport.Code.ToString()) + "'" : "null").ToString(), (stoexport.Storeid != null? stoexport.Storeid.ToString() : "null").ToString(), (stoexport.Reason.Trim() != String.Empty ? stoexport.Reason.ToString() : "null").ToString(), (stoexport.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(stoexport.Description.ToString()) + "'" : "null").ToString(), (stoexport.Createdate != null? "'" + SQLHelper.RejectInjection(stoexport.Createdate.ToString()) + "'" : "null").ToString(), (stoexport.Ordernum.Trim() != String.Empty ? stoexport.Ordernum.ToString() : "null").ToString()); query += " ; select SCOPE_IDENTITY();"; if (tran == null) { dtResult = DataProvider.ExecuteQuery(query); } else { dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran); } if (dtResult != null && dtResult.Rows.Count > 0) { return(dtResult.Rows[0][0].ToString()); } return(""); }
override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.stoexportContract = (StoExportContract)(instants[0]); } }
public HttpResponseMessage Save(string exportJson, string exportDetailsJson) { string exportId = ""; string errMessage = ""; StoExportContract exportDTO = JsonConvert.DeserializeObject <StoExportContract>(exportJson); StoExportDetailContract[] exportDetailDTOs = JsonConvert.DeserializeObject <StoExportDetailContract[]>(exportDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(exportDTO); if (exportDTO.Id > 0) { exportId = exportDT.Update(exportDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { exportId = exportDT.Insert(exportDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(exportId) > 0) { foreach (StoExportDetailContract exportDetailDTO in exportDetailDTOs) { exportDetailDTO.Exportid = Converter.ToInt32(exportId); exportDetailDT.Insert(exportDetailDTO, tran); errMessage = StoreModel.Export(exportDTO.Storeid.ToString(), exportDTO.Code, Converter.ToInt32(exportDetailDTO.Quantity), exportDetailDTO.Productid.ToString(), tran); if (errMessage != "") { DataProvider.RollbackTrans(tran); return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage)); } } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : exportId)); }
/// <summary> /// Cập nhật thông tin đối tượng /// </summary> /// <param name="menu"></param> /// <param name="tran"></param> /// <returns></returns> public string Update(StoExportContract stoexport, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET SaleStaffID={0},Code={1},StoreID={2},Reason={3},Description={4},CreateDate=convert(datetime,{5},103),OrderNum={6} WHERE ID=" + stoexport.Id.ToString(), (stoexport.Salestaffid != null? stoexport.Salestaffid.ToString() : "null").ToString(), (stoexport.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(stoexport.Code.ToString()) + "'" : "null").ToString(), (stoexport.Storeid != null? stoexport.Storeid.ToString() : "null").ToString(), (stoexport.Reason.Trim() != String.Empty ? stoexport.Reason.ToString() : "null").ToString(), (stoexport.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(stoexport.Description.ToString()) + "'" : "null").ToString(), (stoexport.Createdate != null? "'" + SQLHelper.RejectInjection(stoexport.Createdate.ToString()) + "'" : "null").ToString(), (stoexport.Ordernum.Trim() != String.Empty ? stoexport.Ordernum.ToString() : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(stoexport.Id.ToString()); }
public HttpResponseMessage Save(string stoexportJson) { string errMessage = string.Empty; try { StoExportContract stoexport = JsonConvert.DeserializeObject <StoExportContract>(stoexportJson); businessRule.RegistInstants(stoexport); if (stoexport.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(stoexport))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(stoexport))); } else { return(handleBRFailed(errMessage)); } } } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình.")); } }
public StoExportRule ValidateInstant(StoExportContract dto) { return(this); }