示例#1
0
        /// <summary>
        ///  Updates a Group
        /// </summary>
        /// <param name="vestorlyAuth">Vestorly Auth Token</param>
        /// <param name="id">id of group to update</param>
        /// <param name="group">Group to update</param>
        /// <returns>Groupresponse</returns>
        public Groupresponse UpdateGroupById(string vestorlyAuth, string id, GroupInput group)
        {
            String myPath = "/groups/{id}";

            if ("vestorlyAuth" == "vestorlyAuth")
            {
                if (("PUT" == "POST" || "PUT" == "PUT") && "GroupsApi" != "SessionsApi")
                {
                    myPath += "?vestorly_auth=" + vestorlyAuth;
                }
            }

            var _request = new RestRequest(myPath, Method.PUT);



            // verify the required parameter 'vestorlyAuth' is set
            if (vestorlyAuth == null)
            {
                throw new ApiException(400, "Missing required parameter 'vestorlyAuth' when calling UpdateGroupById");
            }

            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new ApiException(400, "Missing required parameter 'id' when calling UpdateGroupById");
            }

            // verify the required parameter 'group' is set
            if (group == null)
            {
                throw new ApiException(400, "Missing required parameter 'group' when calling UpdateGroupById");
            }


            // add default header, if any
            foreach (KeyValuePair <string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
            {
                _request.AddHeader(defaultHeader.Key, defaultHeader.Value);
            }

            _request.AddUrlSegment("format", "json");                       // set format to json by default
            _request.AddUrlSegment("id", ApiInvoker.ParameterToString(id)); // path (url segment) parameter

            if (vestorlyAuth != null && ("PUT" == "GET" || "PUT" == "DELETE" || "GroupsApi" == "SessionsApi"))
            {
                _request.AddParameter("vestorly_auth", ApiInvoker.ParameterToString(vestorlyAuth));            // query parameter
            }
            _request.AddParameter("application/json", ApiInvoker.Serialize(group), ParameterType.RequestBody); // http body (model) parameter


            // make the HTTP request
            IRestResponse response = restClient.Execute(_request);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling UpdateGroupById: " + response.Content);
            }
            return((Groupresponse)ApiInvoker.Deserialize(response.Content, typeof(Groupresponse)));
        }
 public GroupAttribute(int index, Device device, int proportion = 12, string title = null)
 {
     Group = new GroupInput
     {
         Index            = index,
         Title            = !string.IsNullOrWhiteSpace(title)? title : string.Empty,
         Device           = device,
         ColumnProportion = proportion
     };
 }
示例#3
0
        /// <summary>
        /// 验证分组名称是否已经被使用
        /// </summary>
        private async Task <bool> ValidateExistsAsync(GroupInput groupInput, ModelStateDictionary modelState)
        {
            var foundGroup = await _manager.GetItemAsync(groupInput.Name);

            if (foundGroup != null && groupInput.GroupId != foundGroup.GroupId)
            {
                modelState.AddModelError("Name", $"分组名称【{groupInput.Name}】已经被使用");
                return(false);
            }
            return(true);
        }
示例#4
0
        /// <summary>
        /// SaveAsync
        /// </summary>
        /// <param name="groupInput"></param>
        /// <param name="modelState"></param>
        /// <returns></returns>
        public async Task <bool> SaveAsync(GroupInput groupInput, ModelStateDictionary modelState)
        {
            if (!await ValidateExistsAsync(groupInput, modelState))
            {
                modelState.AddModelError("Name", $"{groupInput.Name} 已经被使用");
                return(false);
            }
            var result = await _manager.SaveAsync(groupInput, modelState);

            if (result)
            {
                CleanupCache();
            }
            return(result);
        }
        public BaseResult PauseGroup([FromBody] GroupInput input)
        {
            var result = new BaseResult();

            try
            {
                _schedulerProvider.Scheduler.PauseJobs(GroupMatcher <JobKey> .GroupEquals(input.Group));
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
示例#6
0
        public async Task <bool> SaveAsync(GroupInput groupInput, ModelStateDictionary modelState)
        {
            if (!await ValidateExistsAsync(groupInput, modelState))
            {
                return(false);
            }

            var result = await _repository.SaveAsync(groupInput, modelState);

            if (result)
            {
                await _cache.RemoveAsync(GroupListCacheKey);
            }
            return(result);
        }
        public BaseResult DeleteGroup([FromBody] GroupInput input)
        {
            var result = new BaseResult();

            try
            {
                var keys = _schedulerProvider.Scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(input.Group));
                _schedulerProvider.Scheduler.DeleteJobs(keys.ToList());
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
示例#8
0
        public async Task <SimpleResult> DeleteGroups(GroupInput input)
        {
            try
            {
                await _userDomain.DeleteGroup(input.GroupsIds);

                return(new SimpleResult
                {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new SimpleResult
                {
                    IsSuccess = false,
                    ErrorMessage = JsonConvert.SerializeObject(ex)
                });
            }
        }
示例#9
0
        public async Task <ApiResult> EditGroup(GroupInput groupInput)
        {
            var result = new ApiResult();

            if (groupInput.GroupId.IsNullOrEmpty())
            {
                result.Code    = 400;
                result.Message = "编辑分组失败:必须提供参数 GroupId";
                return(result);
            }

            if (!await _groupService.SaveAsync(groupInput, ModelState))
            {
                result.Code    = 400;
                result.Message = "编辑分组失败:" + ModelState.FirstErrorMessage();
                return(result);
            }

            result.Code    = 200;
            result.Message = "编辑分组成功";
            return(result);
        }
示例#10
0
        public async Task <ApiResult> AddGroup([FromBody] GroupInput groupInput)
        {
            var result = new ApiResult();

            if (groupInput.GroupId.HasValue)
            {
                // Guid.Empty 也不允许
                result.Code    = 400;
                result.Message = "添加分组失败:无需提供参数 GroupId";
                return(result);
            }
            if (!await _groupService.SaveAsync(groupInput, ModelState))
            {
                result.Code    = 400;
                result.Message = "添加分组失败:" + ModelState.FirstErrorMessage();
                return(result);
            }

            result.Code    = 200;
            result.Message = "添加分组成功";
            return(result);
        }
示例#11
0
 public virtual Group Update(long groupId, GroupInput groupInput)
 {
     return _entityUpdateService.Update(groupId, groupInput);
 }
示例#12
0
 public virtual Group Create(GroupInput groupInput)
 {
     return _entityCreationService.Create(groupInput);
 }
示例#13
0
        public async Task <JsonResult> DeleteGroups([FromBody] GroupInput input)
        {
            var result = await _user.DeleteGroups(input);

            return(await GenerateResult(result, _userSettings));
        }
示例#14
0
        public void ConvertConditionTest()
        {
            var condition1 = new GroupInput
            {
                Logic = ConstantOptions.LogicConstant.And,
                Items = new ItemInput[]
                {
                    new ItemInput {
                        Field = nameof(userinfo_us.name), Value = "wyl", Compare = ConstantOptions.CompareConstant.Contains
                    },
                    new ItemInput {
                        Field = nameof(userinfo_us.age), Value = "18", Compare = ConstantOptions.CompareConstant.Equal
                    },
                    new ItemInput {
                        Field = nameof(userinfo_us.birthday), Value = "2020-10-17", Compare = ConstantOptions.CompareConstant.Greater
                    },
                    new ItemInput {
                        Field = nameof(userinfo_us.birthday), Value = "2020-10-21", Compare = ConstantOptions.CompareConstant.Less
                    },
                }
            };
            var condition2 = new GroupInput
            {
                Logic  = ConstantOptions.LogicConstant.Or,
                Groups = new GroupInput[]
                {
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.And,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.name), Value = "wyl", Compare = ConstantOptions.CompareConstant.Contains
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.age), Value = "18", Compare = ConstantOptions.CompareConstant.Equal
                            },
                        }
                    },
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.And,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-17", Compare = ConstantOptions.CompareConstant.Greater
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-19", Compare = ConstantOptions.CompareConstant.Less
                            },
                        }
                    }
                }
            };
            var condition3 = new GroupInput
            {
                Logic  = ConstantOptions.LogicConstant.And,
                Groups = new GroupInput[]
                {
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.Or,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.name), Value = "wyl", Compare = ConstantOptions.CompareConstant.Contains
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.age), Value = "18", Compare = ConstantOptions.CompareConstant.Equal
                            },
                        }
                    },
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.Or,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-17", Compare = ConstantOptions.CompareConstant.Greater
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-19", Compare = ConstantOptions.CompareConstant.Less
                            },
                        }
                    }
                }
            };
            var condition4 = new GroupInput
            {
                Logic = ConstantOptions.LogicConstant.And,
                Items = new ItemInput[]
                {
                    new ItemInput {
                        Field = nameof(userinfo_us.birthday), Value = "2020-10-17", Compare = ConstantOptions.CompareConstant.Greater
                    },
                    new ItemInput {
                        Field = nameof(userinfo_us.birthday), Value = "2020-10-19", Compare = ConstantOptions.CompareConstant.Less
                    },
                },
                Groups = new GroupInput[]
                {
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.Or,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.name), Value = "wyl", Compare = ConstantOptions.CompareConstant.Contains
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.age), Value = "18", Compare = ConstantOptions.CompareConstant.Equal
                            },
                        }
                    }
                }
            };

            int count  = default;
            var query1 = _data.AsQueryable().QueryByGroupInput(condition1);
            var query2 = _data.AsQueryable().QueryByGroupInput(condition2);
            var query3 = _data.AsQueryable().QueryByGroupInput(condition3);
            var query4 = _data.AsQueryable().QueryByGroupInput(condition4);

            var filter1 = query1.ToList();

            count = _data.Where(x => x.name.Contains("wyl") && x.age == 18 && x.birthday > new DateTime(2020, 10, 17) && x.birthday < new DateTime(2020, 10, 21)).Count();
            Assert.IsTrue(filter1.Count == count);
            query1  = _data.AsQueryable().QueryByGroupInput(condition1);
            filter1 = query1.ToList();
            Assert.IsTrue(filter1.Count == count);

            var filter2 = query2.ToList();

            count = _data.Where(x => (x.name.Contains("wyl") && x.age == 18) || (x.birthday > new DateTime(2020, 10, 17) && x.birthday < new DateTime(2020, 10, 19))).Count();
            Assert.IsTrue(filter2.Count == count);
            query2  = _data.AsQueryable().QueryByGroupInput(condition2);
            filter2 = query2.ToList();
            Assert.IsTrue(filter2.Count == count);

            var filter3 = query3.ToList();

            count = _data.Where(x => (x.name.Contains("wyl") || x.age == 18) && (x.birthday > new DateTime(2020, 10, 17) || x.birthday < new DateTime(2020, 10, 19))).Count();
            Assert.IsTrue(filter3.Count == count);
            query3  = _data.AsQueryable().QueryByGroupInput(condition3);
            filter3 = query3.ToList();
            Assert.IsTrue(filter3.Count == count);

            var filter4 = query4.ToList();

            count = _data.Where(x => x.birthday > new DateTime(2020, 10, 17) && x.birthday < new DateTime(2020, 10, 19) && (x.name.Contains("wyl") || x.age == 18)).Count();
            Assert.IsTrue(filter4.Count == count);
            query4  = _data.AsQueryable().QueryByGroupInput(condition4);
            filter4 = query4.ToList();
            Assert.IsTrue(filter4.Count == count);
        }
示例#15
0
        public void ConvertToQueryableTest()
        {
            var condition = new GroupInput
            {
                Logic  = ConstantOptions.LogicConstant.Or,
                Groups = new GroupInput[]
                {
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.And,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.name), Value = "wyl", Compare = ConstantOptions.CompareConstant.Contains
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.age), Value = "18", Compare = ConstantOptions.CompareConstant.Equal
                            },
                        }
                    },
                    new GroupInput
                    {
                        Logic = ConstantOptions.LogicConstant.And,
                        Items = new ItemInput[]
                        {
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-17 00:00:01", Compare = ConstantOptions.CompareConstant.Greater
                            },
                            new ItemInput {
                                Field = nameof(userinfo_us.birthday), Value = "2020-10-19", Compare = ConstantOptions.CompareConstant.Less
                            },
                        }
                    }
                }
            };
            var page = new PageInput
            {
                Index = 1,
                Size  = 2,
                Sort  =
                    new SortInput[]
                {
                    new SortInput
                    {
                        Desc    = true,
                        OrderBy = nameof(userinfo_us.age),
                    },
                    new SortInput
                    {
                        Desc    = false,
                        OrderBy = nameof(userinfo_us.name),
                    }
                }
            };

            var list = _data.AsQueryable().QueryByGroupInput(condition).QueryByPageInput(page).ToList();

            Assert.IsTrue(list.Count == 2);
            Assert.AreEqual(list[0], _data[5]);

            list = _data.AsQueryable().QueryByGroupInput(new GroupInput()).QueryByPageInput(new PageInput()).ToList();
            Assert.IsTrue(list.Count == 6);
        }