public static IList <VendorProductEntity> QueryByVendor(string vendorId) { var list = new List <VendorProductEntity>(); var sql = string.Format(@"SELECT {0} FROM vendor_products WHERE unit_id in (select id from units where root_id = @p_vendor_id)", COLUMN_SQL); var db = DatabaseFactory.CreateDatabase(); var dc = db.GetSqlStringCommand(sql); db.AddInParameter(dc, "p_vendor_id", DbType.String, vendorId); using (var reader = db.ExecuteReader(dc)) { while (reader.Read()) { var entity = new VendorProductEntity(); entity.Init(reader); list.Add(entity); } } return(list); }
private static void Add(VendorProductEntity entity) { var sql = string.Format(@" INSERT INTO vendor_products({0}) VALUES( @p_id, @p_vendor_id, @p_product_id, @p_alias, @p_registration_id, @p_expiration_date, @p_unit_id, @p_is_active, @p_created_id, @p_created_time, @p_updated_id, @p_updated_time)", COLUMN_SQL); entity.Id = Guid.NewGuid().ToString(); var db = DatabaseFactory.CreateDatabase(); var dc = db.GetSqlStringCommand(sql); db.AddInParameter(dc, "p_id", DbType.String, entity.Id); db.AddInParameter(dc, "p_vendor_id", DbType.String, entity.VendorId); db.AddInParameter(dc, "p_product_id", DbType.String, entity.ProductId); db.AddInParameter(dc, "p_alias", DbType.String, entity.Alias); db.AddInParameter(dc, "p_registration_id", DbType.String, entity.RegistrationId); db.AddInParameter(dc, "p_expiration_date", DbType.DateTime, entity.ExpirationDate); db.AddInParameter(dc, "p_unit_id", DbType.String, entity.UnitId); db.AddInParameter(dc, "p_is_active", DbType.Boolean, entity.IsActive); db.AddInParameter(dc, "p_created_id", DbType.String, entity.CreatedId); db.AddInParameter(dc, "p_created_time", DbType.DateTime, entity.CreatedTime); db.AddInParameter(dc, "p_updated_id", DbType.String, entity.UpdatedId); db.AddInParameter(dc, "p_updated_time", DbType.DateTime, entity.UpdatedTime); db.ExecuteNonQuery(dc); }
public static void Save(VendorProductEntity entity) { if (string.IsNullOrEmpty(entity.Id)) { Add(entity); } else { Update(entity); } }
private static void Update(VendorProductEntity entity) { var sql = @" update vendor_products set alias = @p_alias, registration_id = @p_registration_id, expiration_date = @p_expiration_date, is_active = @p_is_active, updated_id = @p_updated_id, updated_time = @p_updated_time where id = @p_id"; var db = DatabaseFactory.CreateDatabase(); var dc = db.GetSqlStringCommand(sql); db.AddInParameter(dc, "p_alias", DbType.String, entity.Alias); db.AddInParameter(dc, "p_registration_id", DbType.String, entity.RegistrationId); db.AddInParameter(dc, "p_expiration_date", DbType.DateTime, entity.ExpirationDate); db.AddInParameter(dc, "p_is_active", DbType.Boolean, entity.IsActive); db.AddInParameter(dc, "p_updated_id", DbType.String, entity.UpdatedId); db.AddInParameter(dc, "p_updated_time", DbType.DateTime, entity.UpdatedTime); db.AddInParameter(dc, "p_id", DbType.String, entity.Id); db.ExecuteNonQuery(dc); }
public JsonNetResult SaveVendorProduct(VendorProductEntity entity) { try { if (string.IsNullOrEmpty(entity.UnitId)) { throw new Exception("The vendor unit is empty."); } if (string.IsNullOrEmpty(entity.ProductId)) { throw new Exception("The product is empty."); } new VendorProductService().Save(entity); return(JsonNet(new ResponseResult(true, entity))); } catch (Exception e) { return(JsonNet(new ResponseResult(e))); } }
public static VendorProductEntity Get(string unitId, string productId) { var sql = string.Format(@"select {0} from vendor_products where unit_id = @p_unit_id and product_id = @p_product_id", COLUMN_SQL); var db = DatabaseFactory.CreateDatabase(); var dc = db.GetSqlStringCommand(sql); db.AddInParameter(dc, "p_unit_id", DbType.String, unitId); db.AddInParameter(dc, "p_product_id", DbType.String, productId); using (var reader = db.ExecuteReader(dc)) { if (reader.Read()) { var entity = new VendorProductEntity(); entity.Init(reader); return(entity); } } return(null); }
public void Save(VendorProductEntity entity) { VendorProductRepository.Save(entity); }