Exemplo n.º 1
0
        public async Task <IList <NameAnswer> > GetRolesForRegisterAsync()
        {
            if (_userStore.Any())
            {
                var roles = await _userStore.GetRolesAsync();

                return(roles
                       .Where(role => role.Id != (uint)RoleEnum.Administrator)
                       .Select(role => new NameAnswer
                {
                    Id = role.Id,
                    Name = role.Name
                }).ToList());
            }
            else
            {
                var administrator = new NameAnswer
                {
                    Id   = (uint)RoleEnum.Administrator,
                    Name = nameof(RoleEnum.Administrator)
                };

                var list = new List <NameAnswer> {
                    administrator
                };

                return(list);
            }
        }
Exemplo n.º 2
0
        public async Task <NameAnswer> CreateCategoryAsync(string name)
        {
            var answer   = new NameAnswer {
            };
            var category = await _categoryStore
                           .GetAsync(name);

            if (category != null)
            {
                answer.Error = "Category does not exist!";

                return(answer);
            }

            category = await _categoryStore.CreateAsync(name);

            if (category == null)
            {
                answer.Error = "Failed to create a category!";

                return(answer);
            }

            answer.Id   = category.Id;
            answer.Name = category.Name;

            return(answer);
        }
Exemplo n.º 3
0
        public async Task <NameGroupAnswer> CreateTypeAsync(uint categoryId, string typeName)
        {
            var answer   = new NameGroupAnswer {
            };
            var category = await _categoryStore
                           .GetAsync(categoryId);

            if (category == null)
            {
                answer.Error = "Category does not exist!";

                return(answer);
            }

            var type = await _typeStore.GetAsync(typeName);

            if (type != null)
            {
                answer.Error = "Type name already exists!";

                return(answer);
            }

            type = await _typeStore.CreateAsync(categoryId, typeName);

            if (type == null)
            {
                answer.Error = "Failed to create a type!";

                return(answer);
            }

            var option = new NameAnswer {
            };

            answer.Options = new List <NameAnswer>();

            option.Id   = type.Id;
            option.Name = type.Name;

            answer.Id    = category.Id;
            answer.Label = category.Name;
            answer.Options.Add(option);

            return(answer);
        }
Exemplo n.º 4
0
        public async Task <NameAnswer> UpdateCategoryAsync(uint categoryId, string categoryName)
        {
            var answer   = new NameAnswer {
            };
            var category = await _categoryStore
                           .GetAsync(categoryName);

            if (category != null)
            {
                answer.Error = "This name is not available!";

                return(answer);
            }

            category = await _categoryStore
                       .GetAsync(categoryId);

            if (category == null)
            {
                answer.Error = "Category does not exist!";

                return(answer);
            }

            category.Name = categoryName;
            category      = await _categoryStore.UpdateAsync(category);

            if (category == null)
            {
                answer.Error = "Failed to update category!";

                return(answer);
            }

            answer.Id   = category.Id;
            answer.Name = category.Name;

            return(answer);
        }
Exemplo n.º 5
0
        public async Task <NameAnswer> UpdateTypeAsync(uint typeId, string typeName)
        {
            var answer = new NameAnswer {
            };
            var type   = await _typeStore
                         .GetAsync(typeName);

            if (type != null)
            {
                answer.Error = "This name is not available!";

                return(answer);
            }

            type = await _typeStore
                   .GetAsync(typeId);

            if (type == null)
            {
                answer.Error = "Type does not exist!";

                return(answer);
            }

            type.Name = typeName;
            type      = await _typeStore.UpdateAsync(type);

            if (type == null)
            {
                answer.Error = "Failed to update type!";

                return(answer);
            }

            answer.Id   = type.Id;
            answer.Name = type.Name;

            return(answer);
        }