Ejemplo n.º 1
0
        /// <summary>
        /// 创建一个AspNetUsers
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个AspNetUsers</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, LYProjectEntities db, AspNetUsers entity)
        {
            int count = 1;

            foreach (string item in entity.AspNetRoles.Select(x => x.Id))
            {
                AspNetRoles sys = new AspNetRoles {
                    Id = item
                };
                db.AspNetRoles.Attach(sys);
                entity.AspNetRoles.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 编辑一个AspNetUsers
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个AspNetUsers</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, LYProjectEntities db, AspNetUsers entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int         count      = 1;
            AspNetUsers editEntity = repository.Edit(db, entity);

            List <string> addAspNetRolesId    = new List <string>();
            List <string> deleteAspNetRolesId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.AspNetRoles.Select(x => x.Id).ToList(), entity.AspNetRoles.Select(x => x.Id).ToList(), ref addAspNetRolesId, ref deleteAspNetRolesId);
            if (addAspNetRolesId != null && addAspNetRolesId.Count() > 0)
            {
                foreach (var item in addAspNetRolesId)
                {
                    AspNetRoles sys = new AspNetRoles {
                        Id = item
                    };
                    db.AspNetRoles.Attach(sys);
                    editEntity.AspNetRoles.Add(sys);
                    count++;
                }
            }
            if (deleteAspNetRolesId != null && deleteAspNetRolesId.Count() > 0)
            {
                List <AspNetRoles> listEntity = new List <AspNetRoles>();
                foreach (var item in deleteAspNetRolesId)
                {
                    AspNetRoles sys = new AspNetRoles {
                        Id = item
                    };
                    listEntity.Add(sys);
                    db.AspNetRoles.Attach(sys);
                }
                foreach (AspNetRoles item in listEntity)
                {
                    editEntity.AspNetRoles.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑AspNetUsers出错了");
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public AspNetUserClaimsBLL(LYProjectEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public AspNetUserClaimsBLL()
 {
     db = new LYProjectEntities();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public AspNetUserLoginsBLL(LYProjectEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public AspNetUserLoginsBLL()
 {
     db = new LYProjectEntities();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public AspNetRolesBLL(LYProjectEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public AspNetRolesBLL()
 {
     db = new LYProjectEntities();
 }