示例#1
0
        public PaginatedListResult <CompanyModel> Save(CompanyModel model)
        {
            string filePath = string.Empty;

            if (model.CompanyID <= 0)
            {
                filePath = System.IO.Path.Combine(Helper.RootPath, "SQL", "Company", "Insert.sql");
            }
            else
            {
                filePath = System.IO.Path.Combine(Helper.RootPath, "SQL", "Company", "Update.sql");
            }
            string sql = System.IO.File.ReadAllText(filePath);
            List <SqlParameter> sqlParameterCollection = new List <SqlParameter>();

            PropertyInfo[] properties       = model.GetType().GetProperties();
            SqlParameter   sqlp             = null;
            List <String>  ignoreProperties = new List <string>()
            {
                "LastTradingDate", "MarketCapital"
            };

            foreach (var p in properties)
            {
                if (ignoreProperties.Contains(p.Name) == false)
                {
                    sqlp = new SqlParameter();
                    sqlp.ParameterName = p.Name;
                    sqlp.Value         = p.GetValue(model);
                    sqlParameterCollection.Add(sqlp);
                }
            }
            SqlHelper.ExecuteNonQuery(sql, sqlParameterCollection);
            if (model.CompanyID <= 0)
            {
                sql             = "SELECT IDENT_CURRENT ('Company') AS Current_Identity;";
                model.CompanyID = DataTypeHelper.ToInt32(SqlHelper.ExecuteScaler(sql, new List <SqlParameter>()));
            }
            return(this.Get(new SearchModel {
                CompanyID = model.CompanyID, SortName = "CompanyID"
            }));
        }