Example #1
0
        public bool UpdateAsync(CourseSystem model)
        {
            using (var conn = DapperFactory.GetConnection())
            {
                List <string> removeFields = new List <string>
                {
                    "Id",
                    "CreateTime",
                    "Status"
                };
                var fields = model.ToFields(removeFields: removeFields);

                if (fields == null || fields.Count == 0)
                {
                    return(false);
                }

                var fieldList = new List <string>();
                foreach (var field in fields)
                {
                    fieldList.Add(string.Format("{0}=@{0}", field));
                }

                model.ModifyTime = DateTime.Now;

                string sql = string.Format("update [CourseSystem] set {0} where Id=@Id;", string.Join(",", fieldList));
                return(conn.Execute(sql, model) > 0);
            }
        }
Example #2
0
        public bool InsertAsync(CourseSystem model)
        {
            using (var conn = DapperFactory.GetConnection())
            {
                var fields = model.ToFields(removeFields: new List <string> {
                    "Id"
                });
                if (fields == null || fields.Count == 0)
                {
                    return(false);
                }

                model.CreateTime = DateTime.Now;
                model.ModifyTime = DateTime.Now;
                model.Status     = 1;

                string sql = string.Format("insert into [CourseSystem] ({0}) values ({1});", string.Join(",", fields), string.Join(",", fields.Select(n => "@" + n)));
                return(conn.Execute(sql, model) > 0);
            }
        }