public int Create(HistStockTemplate template) { var dbCommand = _dbHelper.GetStoredProcCommand(SP_Create); _dbHelper.AddInParameter(dbCommand, "@TemplateId", System.Data.DbType.Int32, template.TemplateId); _dbHelper.AddInParameter(dbCommand, "@TemplateName", System.Data.DbType.String, template.TemplateName); _dbHelper.AddInParameter(dbCommand, "@Status", System.Data.DbType.Int32, (int)template.EStatus); _dbHelper.AddInParameter(dbCommand, "@WeightType", System.Data.DbType.Int32, (int)template.EWeightType); _dbHelper.AddInParameter(dbCommand, "@ReplaceType", System.Data.DbType.Int32, (int)template.EReplaceType); _dbHelper.AddInParameter(dbCommand, "@FuturesCopies", System.Data.DbType.Int32, template.FutureCopies); _dbHelper.AddInParameter(dbCommand, "@MarketCapOpt", System.Data.DbType.Decimal, template.MarketCapOpt); _dbHelper.AddInParameter(dbCommand, "@BenchmarkId", System.Data.DbType.String, template.Benchmark); _dbHelper.AddInParameter(dbCommand, "@ArchiveDate", System.Data.DbType.DateTime, DateTime.Now); _dbHelper.AddInParameter(dbCommand, "@CreatedDate", System.Data.DbType.DateTime, template.DCreatedDate); _dbHelper.AddInParameter(dbCommand, "@ModifiedDate", System.Data.DbType.DateTime, template.DModifiedDate); _dbHelper.AddInParameter(dbCommand, "@CreatedUserId", System.Data.DbType.Int32, template.CreatedUserId); _dbHelper.AddReturnParameter(dbCommand, "@return", System.Data.DbType.Int32); int ret = _dbHelper.ExecuteNonQuery(dbCommand); int archiveId = -1; if (ret > 0) { archiveId = (int)dbCommand.Parameters["@return"].Value; } return(archiveId); }
public List <HistStockTemplate> Get() { List <HistStockTemplate> stockTemplates = new List <HistStockTemplate>(); var dbCommand = _dbHelper.GetStoredProcCommand(SP_Get); var reader = _dbHelper.ExecuteReader(dbCommand); if (reader.HasRows) { while (reader.Read()) { HistStockTemplate item = new HistStockTemplate(); item.ArchiveId = (int)reader["ArchiveId"]; item.TemplateId = (int)reader["TemplateId"]; item.TemplateName = (string)reader["TemplateName"]; item.FutureCopies = (int)reader["FuturesCopies"]; item.MarketCapOpt = (double)(decimal)reader["MarketCapOpt"]; item.EStatus = (TemplateStatus)reader["Status"]; item.EWeightType = (WeightType)reader["WeightType"]; item.EReplaceType = (ReplaceType)reader["ReplaceType"]; item.Benchmark = (string)reader["BenchmarkId"]; item.CreatedUserId = (int)reader["CreatedUserId"]; if (reader["CreatedDate"] != null && reader["CreatedDate"] != DBNull.Value) { item.DCreatedDate = (DateTime)reader["CreatedDate"]; } if (reader["ModifiedDate"] != null && reader["ModifiedDate"] != DBNull.Value) { item.DModifiedDate = (DateTime)reader["ModifiedDate"]; } if (reader["ArchiveDate"] != null && reader["ArchiveDate"] != DBNull.Value) { item.DArchiveDate = (DateTime)reader["ArchiveDate"]; } stockTemplates.Add(item); } } reader.Close(); _dbHelper.Close(dbCommand); return(stockTemplates); }
public int CreateTemplate(StockTemplate template) { HistStockTemplate hst = new HistStockTemplate(template); hst.DArchiveDate = DateTime.Now; int archiveId = _templatedao.Create(hst); if (archiveId > 0) { //add permission foreach (var perm in hst.Permissions) { _permissionManager.ChangePermission(perm.Token, archiveId, Model.Permission.ResourceType.HistoricalSpotTemplate, perm.Permission, false); } } else { archiveId = -1; } return(archiveId); }