public List <CustomerProduct> GetCustomerProducts(Customer companyItem) { var contactItem = new NetStock.Contract.CustomerProduct { CustomerCode = companyItem.CustomerCode }; var currentCustomerProducts = new CustomerProductDAL().GetCustomerProductsList(contactItem.CustomerCode).ToList(); return(currentCustomerProducts); }
public bool Save <T>(T item) where T : IContract { var result = 0; var customer = (Customer)(object)item; if (currentTransaction == null) { connection = db.CreateConnection(); connection.Open(); } var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction); try { var savecommand = db.GetStoredProcCommand(DBRoutine.SAVECUSTOMER); db.AddInParameter(savecommand, "CustomerCode", System.Data.DbType.String, customer.CustomerCode); db.AddInParameter(savecommand, "CustomerName", System.Data.DbType.String, customer.CustomerName); db.AddInParameter(savecommand, "NickName", System.Data.DbType.String, customer.NickName); db.AddInParameter(savecommand, "InterState", System.Data.DbType.String, customer.InterState); db.AddInParameter(savecommand, "SalesLead", System.Data.DbType.String, customer.SalesLead); db.AddInParameter(savecommand, "RegistrationNo", System.Data.DbType.String, customer.RegistrationNo == null ? "" : customer.RegistrationNo); db.AddInParameter(savecommand, "PaymentMode", System.Data.DbType.String, customer.PaymentMode == null ? "" : customer.PaymentMode); db.AddInParameter(savecommand, "CustomerType", System.Data.DbType.String, customer.CustomerType); db.AddInParameter(savecommand, "Status", System.Data.DbType.Boolean, customer.Status); db.AddInParameter(savecommand, "Remark", System.Data.DbType.String, customer.Remark == null ? "" : customer.Remark); db.AddInParameter(savecommand, "CreditTerm", System.Data.DbType.String, customer.CreditTerm == null ? "" : customer.CreditTerm); db.AddInParameter(savecommand, "CustomerMode", System.Data.DbType.String, customer.CustomerMode); db.AddInParameter(savecommand, "AddressID", System.Data.DbType.String, customer.AddressID == null ? "" : customer.AddressID); db.AddInParameter(savecommand, "ContactPerson", System.Data.DbType.String, customer.ContactPerson == null ? "" : customer.ContactPerson); db.AddInParameter(savecommand, "ContactPerson2", System.Data.DbType.String, customer.ContactPerson2 == null ? "" : customer.ContactPerson2); db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, customer.CreatedBy); db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, customer.ModifiedBy); db.AddOutParameter(savecommand, "NewCustomerCode", System.Data.DbType.String, 25); result = db.ExecuteNonQuery(savecommand, transaction); if (result > 0) { customer.CustomerCode = savecommand.Parameters["@NewCustomerCode"].Value.ToString(); AddressDAL addressDAL = new AddressDAL(); customer.CustomerAddress.CreatedBy = customer.CreatedBy; customer.CustomerAddress.ModifiedBy = customer.ModifiedBy; customer.CustomerAddress.AddressLinkID = customer.CustomerCode; result = addressDAL.Save(customer.CustomerAddress, transaction) == true ? 1 : 0; if (customer.CustomerProducts != null) { CustomerProductDAL customerProductDAL = new CustomerProductDAL(); customer.CustomerProducts[0].CustomerCode = customer.CustomerCode; result = customerProductDAL.Save(customer.CustomerProducts[0], transaction) == true ? 1 : 0; } } if (result > 0) { if (currentTransaction == null) { transaction.Commit(); } } else { if (currentTransaction == null) { transaction.Rollback(); } } } catch (Exception ex) { if (currentTransaction == null) { transaction.Rollback(); } throw ex; } return(result > 0 ? true : false); }