Esempio n. 1
0
 /// <summary>
 /// 添加新的主机信息
 /// </summary>
 /// <param name="cache">当前登录用户的缓存</param>
 /// <param name="belongOrganizeId">当前用户所管理的组织机构ID</param>
 /// <param name="dtos">输入主机信息实体</param>
 /// <returns></returns>
 public OperationResult AddHosts(CacheUser cache, Guid[] belongOrganizeId, params HostInputDto[] dtos) => HostRepository.Insert(dtos,
                                                                                                                                checkAction: m =>
 {
     if (!cache.IsAdministrator)
     {
         if (!belongOrganizeId.Contains(m.Organize_Id))
         {
             throw new Exception($"id:主机{m.FullName}&{m.RegPackage}归属组织机构错误!");
         }
     }
     if (HostRepository.CheckExists(a => a.RegPackage == m.RegPackage))
     {
         throw new Exception($"id:主机{m.RegPackage}已经存在");
     }
 },
                                                                                                                                updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.HostRealTimeDataMany.Add(new HostRealTimeData
     {
         //在主机实时数据表添加数据
         HostOne    = entity,
         UpdateTime = DateTime.Now,
     });
     return(entity);
 });
Esempio n. 2
0
 /// <summary>
 /// 编辑光照计划信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditLightPlans(CacheUser cache, params LightPlanInputDto[] datas) => LightPlanRepository.Update(datas,
                                                                                                                        checkAction: (dto, Entity) => { },
                                                                                                                        updateFunc: (dto, entity) =>
 {
     entity.UpdatedTime = DateTime.Now;
     return(entity);
 });
Esempio n. 3
0
        /// <summary>
        /// 删除黑名单
        /// </summary>
        /// <param name="cache">当前操作用户的缓存</param>
        /// <param name="datas">待删除的数据Id集合</param>
        /// <returns></returns>
        public OperationResult DeleteUserBlackLists(CacheUser cache, params Guid[] Ids)
        {
            int count = 0;

            UserBlackListRepository.UnitOfWork.BeginTransaction();
            foreach (var id in Ids)
            {
                var value = UserBlackListRepository.Entities.FirstOrDefault(m => m.Id == id);
                if (value == null)
                {
                    throw new Exception($"id:待删除的黑名单Id:{id} 不能存在");
                }
                else if (value != null && value.UserLogin_Id != cache.Id && !cache.IsAdministrator)
                {
                    throw new Exception($"id:你的权限不允许删除主键:{id}的黑名单");
                }
                else
                {
                    count += UserBlackListRepository.DeleteDirect(id);
                }
            }
            UserBlackListRepository.UnitOfWork.Commit();
            if (count > 0)
            {
                return(new OperationResult(OperationResultType.Success, $"成功删除{count}条数据"));
            }
            else
            {
                return(new OperationResult());
            }
        }
        public async Task <bool> Handle(LeaveFromRoomCommand request, CancellationToken cancellationToken)
        {
            // Get User from Cache
            CacheUser cacheUser = await _chatCacheModule.GetUserAsync(request.ConnectionId, cancellationToken);

            if (cacheUser == null)
            {
                throw new Exception("User doesnt exist. Please login");
            }

            // Set User's Room
            if (cacheUser.ConnectedRoomId == null)
            {
                throw new Exception("User didnt join any room. Please join to a room");
            }

            var userLeftNotification = new UserLeftNotification()
            {
                NickName = cacheUser.NickName, RoomId = cacheUser.ConnectedRoomId, ConnectionId = request.ConnectionId
            };

            cacheUser.ConnectedRoomId = null;
            await _chatCacheModule.SetUserAsync(cacheUser, cancellationToken);

            // Publish
            await _mediator.Publish(
                userLeftNotification,
                cancellationToken);

            return(await Task.FromResult(true));
        }
        public async Task <bool> Handle(OnDisconnectCommand request, CancellationToken cancellationToken)
        {
            // Get User from Cache
            CacheUser cacheUser = await _chatCacheModule.GetUserAsync(request.ConnectionId, cancellationToken);

            if (cacheUser == null)
            {
                throw new Exception("User doesnt exist");
            }

            // Leave From Previous Room
            if (cacheUser.ConnectedRoomId != null)
            {
                await _mediator.Send(
                    new LeaveFromRoomCommand()
                {
                    ConnectionId = request.ConnectionId, DateTime = request.DateTime
                },
                    cancellationToken);
            }

            // Logout
            await _chatCacheModule.RemoveUserAsync(request.ConnectionId, cancellationToken);

            // Publish
            await _mediator.Publish(
                new UserDisconnectedNotification()
            {
                ConnectionId = request.ConnectionId
            }, cancellationToken);

            return(await Task.FromResult(true));
        }
Esempio n. 6
0
 /// <summary>
 /// 编辑分控信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditSubControls(CacheUser cache, params SubControlInputDto[] datas) => SubControlRepository.Update(datas,
                                                                                                                           checkAction: (dto, entity) =>
 {
     if (dto.SubNum != entity.SubNum)
     {
         if (SubControlRepository.CheckExists(m => m.SubNum == dto.SubNum && m.LigthPoleOne_Id == dto.LigthPoleOne_Id))
         {
             throw new Exception($"id:分控编号{dto.SubNum}已经存在!不能在同一台主机上添加相同的分控编号");
         }
     }
 },
                                                                                                                           updateFunc: (dto, entity) =>
 {
     var aggregation = SubAggregationRepository.Entities.FirstOrDefault(m => m.SubControl_Id == entity.Id);
     if (aggregation.LightPole_Id != entity.LigthPoleOne_Id)
     {
         var poleone = LightPoleRepository.Entities.FirstOrDefault(m => m.Id == entity.LigthPoleOne_Id);
         if (poleone == null)
         {
             throw new Exception("id:分控关联的灯杆不存在");
         }
         aggregation.LightPole_Id = entity.LigthPoleOne_Id;
         aggregation.Host_Id      = poleone.Host_Id;
         aggregation.Organzie_Id  = poleone.HostOne.Organize_Id;
         SubAggregationRepository.Update(aggregation);
     }
     return(entity);
 });
Esempio n. 7
0
        private async Task <CacheUser> CreateExpectedDocumentAsync(ICaches caches, string id = null, DateTime?createdAt = null)
        {
            // Create the document.
            var expectedDocument = new CacheUser
            {
                Id        = id ?? this.global.RandomId(),
                VersionId = this.global.RandomId(),
                Handle    = "testhandle",
                Email     = "*****@*****.**",
                Entity    = "https://entity.quentez.com",
                CreatedAt = createdAt.GetValueOrDefault(DateTime.UtcNow)
            };

            // Create its various cache Ids.
            var cacheIds = new string[]
            {
                $"id/{this.global.EncodeCacheKeyPart(expectedDocument.Id)}",
                $"id-version/{this.global.EncodeCacheKeyPart(expectedDocument.Id)}/{this.global.EncodeCacheKeyPart(expectedDocument.VersionId)}",
                $"entity/{this.global.EncodeCacheKeyPart(expectedDocument.Entity)}",
                $"email/{this.global.EncodeCacheKeyPart(expectedDocument.Email)}"
            };

            // Add it to the cache.
            await caches.Users.SaveAsync(cacheIds, expectedDocument);

            return(expectedDocument);
        }
Esempio n. 8
0
 /// <summary>
 /// 删除灯杆信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待删除的数据Id集合</param>
 /// <returns></returns>
 public OperationResult DeleteLightPoles(CacheUser cache, params Guid[] Ids)
 {
     try
     {
         int count = 0;
         LightPoleRepository.UnitOfWork.BeginTransaction();
         foreach (var i in Ids)
         {
             count += LightPoleRepository.DeleteDirect(i);
         }
         LightPoleRepository.UnitOfWork.Commit();
         if (count > 0)
         {
             return(new OperationResult(OperationResultType.Success, $"删除{count}数据成功"));
         }
         else
         {
             return(new OperationResult());
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"执行出现错误:{ex.Message}");
     }
 }
Esempio n. 9
0
        public ActionResult Index()
        {
            ICache    iCache    = CacheManager.GetCacher <CacheUser>();
            CacheUser userLogin = iCache.Get("admin".AESEncrypt128()) as CacheUser ?? new CacheUser();

            ViewBag.User = userLogin.UserName;
            return(View());
        }
Esempio n. 10
0
 public void SetUser(CacheUser cacheUser)
 {
     _cacheDatabase.Add(USER_KEY + cacheUser.ConnectionId, cacheUser,
                        new DistributedCacheEntryOptions()
     {
         SlidingExpiration = TimeSpan.FromMinutes(USER_TIMEOUT_IN_MINUTES)
     });
 }
Esempio n. 11
0
 public async Task SetUserAsync(CacheUser cacheUser, CancellationToken cancellationToken)
 {
     await _cacheDatabase.AddAsync(USER_KEY + cacheUser.ConnectionId, cacheUser,
                                   new DistributedCacheEntryOptions()
     {
         SlidingExpiration = TimeSpan.FromMinutes(USER_TIMEOUT_IN_MINUTES)
     },
                                   cancellationToken);
 }
Esempio n. 12
0
        /// <summary>
        /// 添加用户登录信息
        /// </summary>
        /// <param name="inputDtos">要添加的用户登录信息Dtos集合</param>
        /// <param name="cacheUser">当前操作用户的缓存</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> AddUserLogin(CacheUser cacheUser, params UserLoginInputDto[] inputDtos)
        {
            try
            {
                if (inputDtos.Length <= 0)
                {
                    return(new OperationResult(OperationResultType.Error, "添加用户的数组不存在存数!"));
                }
                else
                {
                    List <string> names = new List <string>();
                    UserLoginRepository.UnitOfWork.BeginTransaction();
                    foreach (UserLoginInputDto dto in inputDtos)
                    {
                        if (cacheUser.Level >= dto.Level)
                        {
                            return(new OperationResult(OperationResultType.ValidError, $"用户:{dto.UserName}权限等级参数设置错误"));
                        }
                        UserLogin value = dto.MapTo <UserLogin>();
                        value.SecretKey = new Random().NextLetterString(16);
                        value.Password  = value.Password.AESEncrypt128(key: value.SecretKey);
                        value.UserMany.Add(new User
                        {
                            CreatedTime     = DateTime.Now,
                            CreatorUserId   = cacheUser.UserName,
                            LastUpdatedTime = DateTime.Now,
                            UserLoginOne    = value,
                        });
                        await UserLoginRepository.InsertAsync(value);

                        if (value.Level == 2)
                        {
                            int count = UserOrganizeMapRepository.CheckExists(m => m.Organize_Id == value.Organize_Id && m.UserLogin_Id == value.Id) ? 0 : UserOrganizeMapRepository.Insert(new UserOrganizeMap {
                                Organize_Id = value.Organize_Id, UserLogin_Id = value.Id
                            });
                        }
                        names.Add(value.UserName);
                    }
                    UserLoginRepository.UnitOfWork.Commit();
                    if (names.Count == 0)
                    {
                        return(new OperationResult(OperationResultType.NoChanged, "未能添加任何用户"));
                    }
                    else
                    {
                        return(new OperationResult(OperationResultType.Success, "用户:{0}创建成功".FormatWith(names.ExpandAndToString())));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"id:{ex.InnerException.Message}");
            }
        }
Esempio n. 13
0
 /// <summary>
 /// 编辑黑名单
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待更改的数据集合</param>
 /// <returns></returns>
 public OperationResult EditUserBlackLists(CacheUser cache, params UserBlackListInputDto[] datas) => UserBlackListRepository.Update(datas,
                                                                                                                                    checkAction: (dto, Entity) =>
 {
     if (UserBlackListRepository.CheckExists(m => m.UserLogin_Id == cache.Id && m.DataItemDetail_Id == dto.DataItemDetail_Id && m.Id != dto.Id))
     {
         throw new Exception($"id:请求更新的:{dto.FullName} 的黑名单类型已经存在,每种黑名单类型都是唯一的!");
     }
 },
                                                                                                                                    updateFunc: (dto, entity) =>
 {
     return(entity);
 });
Esempio n. 14
0
        public InviteManager(BatchQueueItem batch)
        {
            _user       = new CacheUser(batch.InvitingUserId, batch.UserSourceHostName);
            _profileUrl = batch.ProfileUrl;
            AuthenticationResult res = null;
            var task = Task.Run(async() => {
                res = await AdalUtil.AuthenticateApp(null, _user);
            });

            task.Wait();
            _accessToken = res.AccessToken;
        }
Esempio n. 15
0
        /// <summary>
        /// 登录用户
        /// </summary>
        /// <param name="usign">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public APIResult Login(string usign, string pwd)
        {
            APIResult rst = new APIResult();

            try
            {
                rst.Code = -1;
                rst.Msg  = "";
                DataTable dtSource = bll.GetSysUser(usign);
                int       nRows    = dtSource.Rows.Count;

                if (nRows == 0)
                {
                    rst.Msg = "没有此用户";
                }
                else if (nRows != 1)
                {
                    rst.Msg = "此用户有多个";
                }
                else
                {
                    int    Uid     = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Uid"]);
                    string UName   = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["UName"]);
                    string dbPwd   = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["UPasswd"]);
                    int    Role_id = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Role_id"]);
                    //登录密码错误
                    if (!pwd.Trim().Equals(dbPwd))
                    {
                        rst.Msg = "密码错误";
                    }
                    else
                    {
                        user         = new CacheUser();
                        user.Ledger  = WebConfig.Ledger;
                        user.Uid     = Uid;
                        user.USign   = usign;
                        user.Role_id = Role_id;
                        //HttpRuntime.Cache.Insert(WebConfig.Ledger + "->" + Uid, user, null, token.ExpireTime, TimeSpan.Zero);
                        HttpContext.Current.Session["CacheUser"] = user;
                        rst.Code = 0;
                        rst.Msg  = "";
                    }
                }
            }
            catch (Exception ex)
            {
                rst.Code = -1;
                rst.Msg  = ex.Message;
                FileLog.WriteLog("登陆API数据错误(Login):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 16
0
        private void GetRealVal(DataTable dt, out decimal pTotal, out decimal eTotal, out DateTime UTime)
        {
            pTotal = 0;
            eTotal = 0;
            UTime  = DateTime.MinValue;
            CacheUser user = WebConfig.GetSession();
            string    key  = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            string ccKey = "";

            foreach (DataRow dr in dt.Rows)
            {
                ccKey = key + CommFunc.ConvertDBNullToString(dr["P_Tag"]);
                int    i   = 0;
                RstVar var = null;
                while (++i <= 2)
                {
                    var = MemcachedMgr.GetVal <RstVar>(ccKey);
                    if (var != null)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(50);
                }
                if (var != null)
                {
                    pTotal += CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                    if (var.lpszdateTime > UTime)
                    {
                        UTime = var.lpszdateTime;
                    }
                }
                //ccKey = key + CommFunc.ConvertDBNullToString(dr["E_Tag"]);
                //i = 0;
                //var = null;
                //while (++i <= 2)
                //{
                //    var = MemcachedMgr.GetVal<RstVar>(ccKey);
                //    if (var != null) break;
                //    System.Threading.Thread.Sleep(50);
                //}
                //if (var != null)
                //{
                //    eTotal += CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                //    if (var.lpszdateTime > UTime) UTime = var.lpszdateTime;
                //}
            }
        }
Esempio n. 17
0
        private CacheUser GetLogOnUser(ITurnContext turnContext)
        {
            CacheUser user = null;

            //string userid = turnContext.Activity.From.Id;
            //string conversationId = turnContext.Activity.Conversation.Id;
            //List<CacheUser> users;

            //if (_cache.TryGetValue("users", out users))
            //{
            //    user = users.Find(u => u.BotClientUserId == userid && u.BotConversationId == conversationId && u.UserName != "");
            //}
            return(user);
        }
Esempio n. 18
0
 /// <summary>
 /// 添加光照计划信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待添加的数据集合</param>
 /// <returns></returns>
 public OperationResult AddLightPlans(CacheUser cache, params LightPlanInputDto[] datas) => LightPlanRepository.Insert(datas,
                                                                                                                       checkAction: dto =>
 {
     if (LightPlanRepository.CheckExists(m => m.Host_Id == dto.Host_Id && m.DataItemDetail_Id == dto.DataItemDetail_Id))
     {
         throw new Exception($"id:主机主键:{dto.Host_Id} 的光照计划信息已经存在");
     }
 },
                                                                                                                       updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.UpdatedTime = DateTime.Now;
     return(entity);
 });
Esempio n. 19
0
 /// <summary>
 /// 添加黑名单
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待添加的数据集合</param>
 /// <returns></returns>
 public OperationResult AddUserBlackLists(CacheUser cache, params UserBlackListInputDto[] datas) => UserBlackListRepository.Insert(datas,
                                                                                                                                   checkAction: dto =>
 {
     if (UserBlackListRepository.CheckExists(m => m.UserLogin_Id == cache.Id && m.DataItemDetail_Id == dto.DataItemDetail_Id))
     {
         throw new Exception($"id:请求添加的:{dto.FullName} 的黑名单类型已经存在,每种黑名单类型都是唯一的!");
     }
 },
                                                                                                                                   updateFunc: (dto, entity) =>
 {
     entity.UserLogin_Id = cache.Id;
     entity.CreatedTime  = DateTime.Now;
     return(entity);
 });
Esempio n. 20
0
 /// <summary>
 /// 添加分组信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待添加的数据集合</param>
 /// <returns></returns>
 public OperationResult AddGroupControls(CacheUser cache, params GroupControlInputDto[] datas) =>
 GroupControlRepository.Insert(datas,
                               checkAction: dto =>
 {
     if (GroupControlRepository.CheckExists(m => m.ObjectId == dto.ObjectId && m.Organzie_Id == dto.Organzie_Id && m.GrounpNum == dto.GrounpNum && m.DataItemDetail_Id == dto.DataItemDetail_Id))
     {
         throw new Exception($"id:该分组已经存在!");
     }
 },
                               updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.UpdateTime  = DateTime.Now;
     return(entity);
 });
Esempio n. 21
0
 /// <summary>
 /// 编辑分组信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditGroupControls(CacheUser cache, params GroupControlInputDto[] datas) => GroupControlRepository.Update(datas,
                                                                                                                                 checkAction: (dto, entity) =>
 {
     if (dto.DataItemDetail_Id == entity.DataItemDetail_Id && dto.GrounpNum != entity.GrounpNum)
     {
         if (GroupControlRepository.CheckExists(m => m.GrounpNum == dto.GrounpNum && m.ObjectId == dto.ObjectId && m.Organzie_Id == dto.Organzie_Id))
         {
             throw new Exception($"id:更新数据失败,因为已经存在相同的类型数据");
         }
     }
 },
                                                                                                                                 updateFunc: (dto, entity) =>
 {
     return(entity);
 });
Esempio n. 22
0
 /// <summary>
 /// 编辑字典内容
 /// </summary>
 /// <param name="datas">待更新的字典内容集合</param>
 /// <param name="cache">当前操作用户的缓存信息</param>
 /// <returns></returns>
 public OperationResult EditDataItemDetails(CacheUser cache, DataItemDetailInputDto[] datas) => DataItemDetailRepository.Update(datas,
                                                                                                                                checkAction: (edit, updated) =>
 {
     if (updated.IsSystem == true && !cache.IsAdministrator)
     {
         throw new Exception($"id:字典内容:{edit.FullName} 是系统预设内容你的权限不能修改!");
     }
     else if (DataItemDetailRepository.CheckExists(m => m.FullName == edit.FullName && m.Id != edit.Id && m.Organzie_Id == cache.Organize_Id))
     {
         throw new Exception($"id:你已存在字典内容名称 为‘{edit.FullName}’ 的参数!");
     }
 },
                                                                                                                                updateFunc: (edit, updated) =>
 {
     return(updated);
 });
Esempio n. 23
0
        /// <summary>
        /// 删除指定的升级记录
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public OperationResult DeleteUpgradeLog(CacheUser cacheUser, Guid[] Orgids, params Guid[] Ids)
        {
            int count = 0;

            UpgradeLogRepository.UnitOfWork.BeginTransaction();
            for (int n = 0; n < Ids.Length; n++)
            {
                Guid guid = Ids[n];
                if (UpgradeLogRepository.CheckExists(m => m.Id == guid))
                {
                    count += UpgradeLogRepository.Delete(m => m.Id == guid && (Orgids.Contains(m.Organize_Id) || cacheUser.IsAdministrator));
                }
            }
            UpgradeLogRepository.UnitOfWork.Commit();
            return(new OperationResult(OperationResultType.Success, $"删除请求已执行,成功删除{count}条数据", new { count }));
        }
Esempio n. 24
0
        public APIRst GetTest(Tags obj)
        {
            //List<string> tag = new List<string>();
            CacheUser user = WebConfig.GetSession();
            string    key  = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            APIRst rst = new APIRst()
            {
                rst = true, data = new { key = key, tag = JsonHelper.Serialize(obj.list) }
            };

            return(rst);
        }
Esempio n. 25
0
 /// <summary>
 /// 添加分控上的灯具基本信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存信息</param>
 /// <param name="datas">待添加的灯具</param>
 /// <returns></returns>
 public OperationResult AddSubReadTimeDatas(CacheUser cache, params SubRealTimeDataInputDto[] datas) => SubRealTimeDataRepository.Insert(datas,
                                                                                                                                         checkAction: dto =>
 {
     if (!dto.DimmingPort.IsBetween(1, 2))
     {
         throw new Exception("id:灯具端口在1-2之间");
     }
     else if (SubRealTimeDataRepository.CheckExists(m => m.SubControl_Id == dto.SubControl_Id && m.DimmingPort == dto.DimmingPort))
     {
         throw new Exception($"Id:该分控上已经存在端口{dto.DimmingPort}的灯具!");
     }
 },
                                                                                                                                         updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.UpdateTime  = DateTime.Now;
     return(entity);
 });
Esempio n. 26
0
        private async Task <CacheUser> CreateExpectedDocumentAsync(IVersionedTable <CacheUser> userTable, string id = null, DateTime?createdAt = null)
        {
            // Create the document.
            var expectedDocument = new CacheUser
            {
                Id        = id ?? this.global.RandomId(),
                VersionId = this.global.RandomId(),
                Handle    = "testhandle",
                Email     = "*****@*****.**",
                Entity    = "https://entity.quentez.com",
                CreatedAt = createdAt.GetValueOrDefault(DateTime.UtcNow)
            };

            // Add it to the collection.
            await userTable.InsertAsync(expectedDocument);

            return(expectedDocument);
        }
Esempio n. 27
0
 /// <summary>
 /// 删除光照计划信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待删除的数据Id集合</param>
 /// <returns></returns>
 public OperationResult DeleteLightPlans(CacheUser cache, params Guid[] Ids)
 {
     try
     {
         int count = 0;
         LightPlanRepository.UnitOfWork.BeginTransaction();
         foreach (var id in Ids)
         {
             count += LightPlanRepository.DeleteDirect(id);
         }
         LightPlanRepository.UnitOfWork.Commit();
         return(count > 0 ? new OperationResult(OperationResultType.Success, $"成功删除{count}条数据") :
                new OperationResult());
     }
     catch (Exception ex)
     {
         throw new Exception($"id:出现错误:{ex.Message}");
     }
 }
Esempio n. 28
0
 /// <summary>
 /// 删除用户登录信息
 /// </summary>
 /// <param name="ids">要删除的登录信息</param>
 /// <param name="cache">当前操作的缓存用户</param>
 /// <returns>业务操作结果</returns>
 public async Task <OperationResult> DeleteUserLogin(CacheUser cache, params Guid[] ids)
 {
     try
     {
         OperationResult result = UserLoginRepository.Delete(ids,
                                                             checkAction: entity => {
             if (cache.IsAdministrator)
             {
                 return;
             }
             if (!cache.Level.IsBetween(1, 2))
             {
                 throw new Exception($"id:你没有权限进行该功能操作!");
             }
             var listId = from a in UserOrganizeMapRepository.Entities
                          join b in UserLoginRepository.Entities on
                          a.Organize_Id equals b.Organize_Id
                          where a.UserLogin_Id == cache.Id
                          select b.Id;
             foreach (var i in ids)
             {
                 if (!listId.Contains(i))
                 {
                     throw new Exception($"id:主键:{i}的用户信息不存在你的操作范围!,");
                 }
             }
         },
                                                             deleteFunc: entity =>
         {
             if (entity == null)
             {
                 throw new Exception("id:准备删除的目标不存在");
             }
             HostPolicyLogRepository.Delete(m => m.UserLogin_Id == entity.Id);
             return(entity);
         });
         return(await Task.FromResult(result));
     }
     catch (Exception ex)
     {
         throw new Exception($"id:{ex.InnerException.Message}");
     }
 }
Esempio n. 29
0
 /// <summary>
 /// 添加主机策略
 /// </summary>
 /// <param name="cache">当前缓存的操作用户信息</param>
 /// <param name="dtos">输入实体</param>
 /// <returns></returns>
 public OperationResult AddHostPolicys(CacheUser cache, params HostPolicyInputDto[] dtos) => HostPolicyRepository.Insert(dtos,
                                                                                                                         checkAction: dto =>
 {
     if (!cache.Level.IsBetween(1, 2))
     {
         throw new Exception($"id:你的操作权限等级过低");
     }
     if (HostPolicyRepository.Entities.FirstOrDefault(m => m.Host_Id == dto.Host_Id && m.Number == dto.Number) != null)
     {
         throw new Exception("id:准备添加的策略信息已经存在");
     }
 },
                                                                                                                         updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.Organzie_Id = cache.Organize_Id;
     entity.UpdateTime  = DateTime.Now;
     return(entity);
 });
Esempio n. 30
0
 /// <summary>
 /// 编辑灯杆信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditLightPoles(CacheUser cache, params LightPoleInputDto[] datas)
 {
     return(LightPoleRepository.Update(datas,
                                       checkAction: (dto, entity) =>
     {
     },
                                       updateFunc: (dto, entity) =>
     {
         //var v1 = SubAggregationRepository.Entities.FirstOrDefault(m => m.LightPole_Id == dto.Id);
         //if (v1.Host_Id != dto.Host_Id)
         //{
         //    var host = HostRepository.Entities.FirstOrDefault(m => m.Id == dto.Host_Id);
         //    if (host == null) { throw new Exception("id:更改数据关联的主机主键不存在"); }
         //    v1.Host_Id = host.Id;
         //    v1.Organzie_Id = host.Organize_Id;
         //    SubAggregationRepository.Update(v1);
         //}
         return entity;
     }));
 }