override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.buyguaranteeContract = (BuyGuaranteeContract)(instants[0]); } }
/// <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(BuyGuaranteeContract buyguarantee, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET SaleStaffID={0},Code={1},Name={2},CustomerID={3},StoreID={4},ReceiveDate=convert(datetime,{5},103),ExpectReturnDate=convert(datetime,{6},103),ReturnDate=convert(datetime,{7},103),NotifyDates={8},Description={9},GuarStatusID={10},OrderNum={11} WHERE ID=" + buyguarantee.Id.ToString(), (buyguarantee.Salestaffid != null? buyguarantee.Salestaffid.ToString() : "null").ToString(), (buyguarantee.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Code.ToString()) + "'" : "null").ToString(), (buyguarantee.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Name.ToString()) + "'" : "null").ToString(), (buyguarantee.Customerid != null? buyguarantee.Customerid.ToString() : "null").ToString(), (buyguarantee.Storeid != null? buyguarantee.Storeid.ToString() : "null").ToString(), (buyguarantee.Receivedate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Receivedate.ToString()) + "'" : "null").ToString(), (buyguarantee.Expectreturndate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Expectreturndate.ToString()) + "'" : "null").ToString(), (buyguarantee.Returndate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Returndate.ToString()) + "'" : "null").ToString(), (buyguarantee.Notifydates.Trim() != String.Empty ? buyguarantee.Notifydates.ToString() : "null").ToString(), (buyguarantee.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Description.ToString()) + "'" : "null").ToString(), (buyguarantee.Guarstatusid != null? buyguarantee.Guarstatusid.ToString() : "null").ToString(), (buyguarantee.Ordernum.Trim() != String.Empty ? buyguarantee.Ordernum.ToString() : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(buyguarantee.Id.ToString()); }
/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(BuyGuaranteeContract buyguarantee, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Buy_Guarantee VALUES ({0},{1},{2},{3},{4},convert(datetime,{5},103),convert(datetime,{6},103),convert(datetime,{7},103),{8},{9},{10},{11})", (buyguarantee.Salestaffid != null? buyguarantee.Salestaffid.ToString() : "null").ToString(), (buyguarantee.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Code.ToString()) + "'" : "null").ToString(), (buyguarantee.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Name.ToString()) + "'" : "null").ToString(), (buyguarantee.Customerid != null? buyguarantee.Customerid.ToString() : "null").ToString(), (buyguarantee.Storeid != null? buyguarantee.Storeid.ToString() : "null").ToString(), (buyguarantee.Receivedate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Receivedate.ToString()) + "'" : "null").ToString(), (buyguarantee.Expectreturndate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Expectreturndate.ToString()) + "'" : "null").ToString(), (buyguarantee.Returndate != null? "'" + SQLHelper.RejectInjection(buyguarantee.Returndate.ToString()) + "'" : "null").ToString(), (buyguarantee.Notifydates.Trim() != String.Empty ? buyguarantee.Notifydates.ToString() : "null").ToString(), (buyguarantee.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(buyguarantee.Description.ToString()) + "'" : "null").ToString(), (buyguarantee.Guarstatusid != null? buyguarantee.Guarstatusid.ToString() : "null").ToString(), (buyguarantee.Ordernum.Trim() != String.Empty ? buyguarantee.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(""); }
public HttpResponseMessage Save(string guaranteeJson, string guaranteeDetailsJson) { string guaranteeId = ""; string errMessage = ""; BuyGuaranteeContract guaranteeDTO = JsonConvert.DeserializeObject <BuyGuaranteeContract>(guaranteeJson); BuyGuaranteeDetailContract[] guaranteeDetailDTOs = JsonConvert.DeserializeObject <BuyGuaranteeDetailContract[]>(guaranteeDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(guaranteeDTO); if (guaranteeDTO.Id > 0) { guaranteeId = guaranteeDT.Update(guaranteeDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { guaranteeId = guaranteeDT.Insert(guaranteeDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(guaranteeId) > 0) { deleteDetail(guaranteeId, tran); foreach (BuyGuaranteeDetailContract invoiceDetailDTO in guaranteeDetailDTOs) { invoiceDetailDTO.Guaranteeid = Converter.ToInt32(guaranteeId); guaranteeDetailDT.Insert(invoiceDetailDTO, tran); } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : guaranteeId)); }
public HttpResponseMessage Save(string buyguaranteeJson) { string errMessage = string.Empty; try { BuyGuaranteeContract buyguarantee = JsonConvert.DeserializeObject <BuyGuaranteeContract>(buyguaranteeJson); businessRule.RegistInstants(buyguarantee); if (buyguarantee.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(buyguarantee))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(buyguarantee))); } 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 BuyGuaranteeRule ValidateInstant(BuyGuaranteeContract dto) { return(this); }