/// <summary>
        /// Справочник станций
        /// </summary>
        private static async Task <ReportResponse> GetStationsTable(ReportRequest input, ILogger logger)
        {
            var sqlR   = new StantionsRepository(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),
                new Column("col1", "Тип", "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,
                    //Тип
                    Col1 = GetStringStationType(item.StantionType)
                };

                result.Rows.Add(row);
            }

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

            var sr     = new StantionsRepository(_logger);
            var result = new StantionsRepository.StantionPaging();

            if (filter != null)
            {
                result = await sr.GetAll(skip, limit, filter);
            }
            else
            {
                result = await sr.GetAll(skip, limit);
            }

            return(Json(result));
        }
        /// <summary>
        /// Справочник Парковок
        /// </summary>
        private static async Task <ReportResponse> GetParkingsTable(ReportRequest input, ILogger logger)
        {
            var sqlR        = new ParkingRepository(logger);
            var sqlRStation = new StantionsRepository(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),
                new Column("col1", "Описание", "string", disableEdit: false),
                new Column("col2", "Станция", "string", disableEdit: false),
            };

            foreach (var item in data)
            {
                var station = await sqlRStation.ById(item.StantionId);

                var stations = await sqlRStation.GetAll();

                stations = stations.Where(x => x.Id != item.StantionId).ToList();
                var avaibleStations = new List <StantionSimple>();
                foreach (var x in stations)
                {
                    avaibleStations.Add(new StantionSimple {
                        StantionName = x.Name, StantionId = x.Id
                    });
                }

                var row = new Row
                {
                    Id       = new RowId(item.Id, 1),
                    HasItems = false.ToString(),
                    ParentId = null,
                    //Имя
                    Col0 = item.Name,
                    //Описание
                    Col1 = item.Description,
                    //Станция
                    Col2 = station.Name,
                    AdditionalProperty = new AdditionalProperty {
                        AvaibleStations = avaibleStations, StationId = item.StantionId
                    }
                };

                result.Rows.Add(row);
            }

            return(result);
        }
        public async Task <DictionaryCrudResponse> StantionCrud(DictionaryCrudRequest input)
        {
            var data = input.Stantion;

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

            var sqlR = new StantionsRepository(_logger);

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

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

            var all = await sqlR.GetAll();

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

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

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

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