コード例 #1
0
ファイル: TeamDAL.cs プロジェクト: jasonyuan1016/YMOA
        /// <summary>
        /// 批量添加成员
        /// </summary>
        /// <param name="listModel"></param>
        /// <returns></returns>
        public int Save(List <TeamEntity> listModel)
        {
            int ret = 0;

            try
            {
                if (listModel != null && listModel.Count > 0)
                {
                    TeamEntity    model   = listModel.FirstOrDefault();
                    var           ps      = model.GetType().GetProperties();
                    List <string> @colms  = new List <string>();
                    List <string> @params = new List <string>();

                    foreach (var p in ps)
                    {
                        @colms.Add(string.Format("[{0}]", p.Name));
                        @params.Add(string.Format("@{0}", p.Name));
                    }
                    var sql = string.Format("INSERT INTO [{0}] ({1}) VALUES({2})", "tbTeam", string.Join(", ", @colms), string.Join(", ", @params));
                    using (var _conn = GetConnection())
                    {
                        _conn.Execute("delete from tbTeam where ProjectId = @ProjectId and TaskId='0'", new { ProjectId = listModel[0].ProjectId });
                        ret = _conn.Execute(sql, listModel);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ret);
        }
コード例 #2
0
ファイル: UserBuilder.cs プロジェクト: wallacediasdasilva/DDD
        public TeamEntity Build()
        {
            var user = new TeamEntity(Name, Cpf, Email, Phone);

            if (Id <= 0)
            {
                return(user);
            }

            var propertyInfo = user.GetType().GetProperty("Id");

            propertyInfo.SetValue(user, Convert.ChangeType(Id, propertyInfo.PropertyType), null);

            return(user);
        }