/// <summary>
        /// Справочник Направлений
        /// </summary>
        private static async Task <ReportResponse> GetDirectionsTable(ReportRequest input, ILogger logger)
        {
            var sqlR   = new DirectionsRepository(logger);
            var result = new ReportResponse {
                Rows = new List <Row>()
            };

            var data = await sqlR.GetAll();

            result.Columns = new List <Column>
            {
                new Column("col0", "Название", "string", disableEdit: false),
            };

            foreach (var item in data)
            {
                var row = new Row
                {
                    Id       = new RowId(item.Id, 1),
                    HasItems = false.ToString(),
                    ParentId = null,
                    //Имя
                    Col0 = item.Name,
                };

                result.Rows.Add(row);
            }

            return(result);
        }
示例#2
0
        public async Task <JsonResult> GetAll(int skip, int limit, string filter = null)
        {
            await CheckPermission();

            var result = await _sqlR.GetAll(skip, limit, filter);

            return(Json(result));
        }
        public async Task <DictionaryCrudResponse> DirectionCrud(DictionaryCrudRequest input)
        {
            var data = input.Direction;

            if (data == null && input.IdToDelete == null)
            {
                throw new ValidationException("Не распарсилось");
            }

            var sqlR = new DirectionsRepository(_logger);

            if (input?.IdToDelete != null)
            {
                await sqlR.Delete((int)input.IdToDelete);

                return(new DictionaryCrudResponse {
                    IsDeleted = true, Direction = data
                });
            }

            var all = await sqlR.GetAll();

            if (all.Any(x => x.Name.Equals(input.Direction.Name)))
            {
                throw new ValidationException(Error.AlreadyAddWithThisName);
            }

            if (data?.Id == 0)
            {
                var item = await sqlR.Add(data);

                return(new DictionaryCrudResponse {
                    IsAdd = true, Direction = item
                });
            }
            else
            {
                var item = await sqlR.Update(data);

                return(new DictionaryCrudResponse {
                    IsUpdated = true, Direction = item
                });
            }
        }