Beispiel #1
0
 /// <summary>
 /// 为roleId增加权限,新增权限
 /// </summary>
 /// <param name="roleId"></param>
 /// <param name="permIds"></param>
 public void AddPermIds(long roleId, long[] permIds)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <RoleEntity> roleBs = new Service.BaseService <Entities.RoleEntity>(ctx);
         var role = roleBs.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("角色不存在" + roleId);
         }
         BaseService <PermissionEntity> perm = new Service.BaseService <Entities.PermissionEntity>(ctx);
         var perms = perm.GetAll().ToList().Where(p => permIds.Contains(p.Id));
         foreach (var p in perms)
         {
             role.Permissions.Add(p);
         }
         ctx.SaveChanges();
     }
 }
Beispiel #2
0
        /// <summary>
        /// 抢单
        /// </summary>
        /// <param name="adminUserId"></param>
        /// <param name="houseAppointmentId"></param>
        /// <returns></returns>
        public bool Follow(long adminUserId, long houseAppointmentId)
        {
            using (ZSZDbContext ctx = new Service.ZSZDbContext())
            {
                BaseService <HouseAppointmentEntity> bs = new Service.BaseService <HouseAppointmentEntity>(ctx);
                var app = bs.GetById(houseAppointmentId);
                if (app == null)
                {
                    throw new ArgumentException("不存在的订单Id");
                }
                //FollowAdminUserId不为null,要么已经自己抢过,要么早早被别人抢了
                if (app.FollowAdminUserId != null)
                {
                    return(app.FollowAdminUserId == adminUserId);

                    /* if (app.FollowAdminUserId==adminUserId)
                     * {
                     *   return true;
                     * }
                     * else
                     * {
                     *   return false;
                     * }
                     */
                }
                //如果为null,说明有抢的机会
                app.FollowAdminUserId = adminUserId;
                try
                {
                    ctx.SaveChanges();
                    return(true);
                }
                //如果抛出DbUpdateConcurrencyException这个异常说明抢单失败
                catch (DbUpdateConcurrencyException)
                {
                    return(false);
                }
            }
        }