public async Task <JsonResult> DeleteStaff([FromBody] UserInternal ub)
        {
            await CheckPermission();

            var ur   = new UserRepository(_logger);
            var pb   = new PlaneBrigadeTrainsRepository(_logger);
            var pk   = new PlanedRouteTrainsRepository(_logger);
            var user = await ur.GetStaffById(ub.UserId);

            if (user == null)
            {
                throw new Exception("user.Id not found");
            }

            var planeBrigades = await pb.ByUserId(user.Id);

            if (planeBrigades.Count > 0)
            {
                throw new Exception("Сотрудник уже назначен на планирование поездов");
            }

            var planedRoutes = await pk.ByUserId(user.Id);

            if (planedRoutes.Count > 0)
            {
                throw new Exception("Сотрудник уже назначен на планирование маршрутов");
            }

            await ur.DeleteStaff(user);

            ur.Dispose();

            return(Json(new { message = "Delete OK" }));
        }
Beispiel #2
0
        public async Task Delete(int id)
        {
            await CheckPermission();

            var sqlR = new PlaneBrigadeTrainsRepository(_logger);
            await sqlR.Delete(id);
        }
Beispiel #3
0
        public async Task <JsonResult> GetAll(int skip, int limit, string filter = null)
        {
            await CheckPermission();

            var sqlR   = new PlaneBrigadeTrainsRepository(_logger);
            var result = await sqlR.GetAll(skip, limit, filter);

            return(Json(result));
        }
        /// <summary>
        /// Обновить Хуету
        /// </summary>
        public async Task <List <PlaneBrigadeTrain> > AddUserToTrain(PlaneBrigadeTrainDto input)
        {
            ////Начинаем блядь квн
            //using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
            //{
            var sqlR = new PlaneBrigadeTrainsRepository(_logger);
            var sqlRPlanedStations = new PlanedStationOnTripsRepository(_logger);

            var result = new List <PlaneBrigadeTrain>();

            foreach (var userId in input.UserIds)
            {
                var data = await sqlR.ByPlanedRouteTrainId(input.PlanedRouteTrainId);

                //Если добавлен на этот плановый рейс уже
                if (data.Any(x => x.UserId == userId))
                {
                    throw new ValidationException(Error.AlreadyAdd);
                }

                var requestPlanedStations =
                    await sqlRPlanedStations.ByPlannedRouteTrainId(input.PlanedRouteTrainId);

                if (requestPlanedStations.Count < 2)
                {
                    throw new ValidationException(Error.MiniTripStations);
                }

                //TODO вынести маппер отдельно
                var entity = new PlaneBrigadeTrain
                {
                    StantionStartId    = input.StantionStartId,
                    StantionEndId      = input.StantionEndId,
                    UserId             = userId,
                    PlanedRouteTrainId = input.PlanedRouteTrainId
                };

                result.Add(await sqlR.Add(entity));
            }

            //transaction.Complete();
            return(result);
            //}
        }
Beispiel #5
0
        /// <summary>
        /// Данные по ебучим юзерам меж станками
        /// </summary>
        private static async Task GetPlanedBrigadesData(int planedRouteTrainId, RouteData result, ILogger logger)
        {
            var sqlRPlanedStations       = new PlanedStationOnTripsRepository(logger);
            var sqlRUsers                = new UserRepository(logger);
            var sqlRStations             = new StantionsRepository(logger);
            var sqlRPlaneBrigadeTrains   = new PlaneBrigadeTrainsRepository(logger);
            var sqlRChangedBrigadeTrains = new ChangePlaneBrigadeTrainsRepository(logger);

            result.PlaneRoute.UserOnStations = new List <PlanedUserOnStations>();
            var planeBrigades = await sqlRPlaneBrigadeTrains.ByPlanedRouteTrainId(planedRouteTrainId);

            foreach (var planeBrigade in planeBrigades)
            {
                var stationStartId = (await sqlRPlanedStations.ById(planeBrigade.StantionStartId)).StantionId;
                var stationEndId   = (await sqlRPlanedStations.ById(planeBrigade.StantionEndId)).StantionId;

                var changedBrigadeData = await sqlRChangedBrigadeTrains.ByPlaneBrigadeTrainId(planeBrigade.Id);

                var toAdd =
                    new PlanedUserOnStations
                {
                    PlaneBrigadeTrainId  = planeBrigade.Id,
                    UserName             = (await sqlRUsers.ById(planeBrigade.UserId)).Name,
                    StationStartName     = (await sqlRStations.ById(stationStartId)).Name,
                    StationEndName       = (await sqlRStations.ById(stationEndId)).Name,
                    ChangeBrigadeTrainId = changedBrigadeData?.Id
                };

                if (changedBrigadeData != null)
                {
                    toAdd.ChangedUserName         = (await sqlRUsers.ById(planeBrigade.UserId)).Name;
                    toAdd.ChangedStationStartName = (await sqlRStations.ById(changedBrigadeData.StantionEndId)).Name;
                    toAdd.ChangedStationEndName   = (await sqlRStations.ById(changedBrigadeData.StantionStartId)).Name;
                }


                result.PlaneRoute.UserOnStations.Add(toAdd);
            }
        }
Beispiel #6
0
        //В эксельку кто когда сваливает с депо
        public async Task <ReportResponse> EscapeFromDepoReport(ExcelDataRequest input)
        {
            var sqlRPlaneTrain   = new PlanedRouteTrainsRepository(_logger);
            var sqlRRoute        = new RoutesRepository(_logger);
            var sqlRTrain        = new TrainRepository(_logger);
            var sqlRTrip         = new TripsRepository(_logger);
            var sqlRUser         = new UserRepository(_logger);
            var sqlRPlaneStation = new PlanedStationOnTripsRepository(_logger);
            var sqlRPlaneBrigade = new PlaneBrigadeTrainsRepository(_logger);

            if (input.Date == null)
            {
                throw new ValidationException("Не задан StartDate");
            }

            var result = new ReportResponse {
                Rows = new List <Row>()
            };

            result.Columns = new List <Column>
            {
                new Column("col0", "Маршрут", "string"),
                //№ поезда(Походу рейс https://alcodevelop.atlassian.net/browse/CPPK-4)
                new Column("col1", "№ поезда", "string"),
                new Column("col2", "Машинист", "string"),
                new Column("col3", "Состав", "string"),
                new Column("col4", "КП", "string"),
            };

            //Бля ну получим все поезда наверно
            var planeTrains = await sqlRPlaneTrain.GetAll();

            //За указанные сутки
            planeTrains = planeTrains.Where(x => x.Date.Date == input.Date.Date).ToList();
            foreach (var planeTrain in planeTrains)
            {
                var route = await sqlRRoute.ById(planeTrain.RouteId);

                var train = await sqlRTrain.ById(planeTrain.TrainId);

                //Берем все станки маршрута
                var planeStations = await sqlRPlaneStation.ByPlannedRouteTrainId(planeTrain.Id);

                var startStation = planeStations.OrderBy(x => x.OutTime).FirstOrDefault();

                var trip = new Trip();
                if (startStation != null)
                {
                    trip = await sqlRTrip.ById(startStation.TripId);
                }
                var planeBrigades = await sqlRPlaneBrigade.ByPlanedRouteTrainId(planeTrain.Id);

                //TODO брать 1-го юзера и делать машинистом, както неправильно) хДД
                User motorman = null;
                if (planeBrigades.Count != 0)
                {
                    motorman = await sqlRUser.ById(planeBrigades.First().UserId);
                }

                var toadd = new Row
                {
                    Id       = new RowId(DateTime.Now.Ticks.GetHashCode(), 2),
                    HasItems = false.ToString(),
                    ParentId = null,
                    //Маршрут
                    Col0 = route.Name,
                    //№ поезда(Походу рейс https://alcodevelop.atlassian.net/browse/CPPK-4)
                    Col1 = trip.Name,
                    //Машинист
                    Col2 = motorman?.Name,
                    //Состав
                    Col3 = train.Name,
                    //КП
                    Col4 = startStation?.OutTime.ToStringTimeOnly()
                };

                result.Rows.Add(toadd);
            }


            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Бригады таблица
        /// </summary>
        private static async Task <ChangeTimeRangeBrigadeDto> GetBrigadeData(GetRouteInformationTableRequest input, ILogger logger)
        {
            var sqlRPlanedRouteTrains    = new PlanedRouteTrainsRepository(logger);
            var sqlRTrips                = new TripsRepository(logger);
            var sqlRPlanedStations       = new PlanedStationOnTripsRepository(logger);
            var sqlRUsers                = new UserRepository(logger);
            var sqlRStations             = new StantionsRepository(logger);
            var sqlRPlaneBrigadeTrains   = new PlaneBrigadeTrainsRepository(logger);
            var sqlRChangedBrigadeTrains = new ChangePlaneBrigadeTrainsRepository(logger);

            //var result = new ReportResponse { Rows = new List<Row>() };
            var stationsSimple = new List <StantionSimple>();

            //Берем всех юзерков
            var users = await sqlRUsers.GetAll();


            //Получим все станки с маршрута
            var planeStations = await sqlRPlanedStations.ByPlannedRouteTrainId(input.PlanedRouteTrainId);

            planeStations.OrderBy(x => x.InTime);

            var currentTripId = 0;

            for (var index = 0; index < planeStations.Count; index++)
            {
                var planeStation = planeStations[index];
                var trip         = await sqlRTrips.ById(planeStation.TripId);

                var station = await sqlRStations.ById(planeStation.StantionId);

                var qqStart = planeStation.InTime.ToStringTimeOnly();
                var qqEnd   = planeStation.OutTime.ToStringTimeOnly();

                if (currentTripId == 0 || planeStation.TripId != currentTripId)
                {
                    qqStart = "н/д";
                }
                if (index != planeStations.Count - 1)
                {
                    if (planeStations[index + 1].TripId != planeStation.TripId && currentTripId != 0)
                    {
                        qqEnd = "н/д";
                    }
                }
                else
                {
                    qqEnd = "н/д";
                }
                var qq1 = $"{station.Name} {qqStart}-{qqEnd} ({trip.Name})";
                stationsSimple.Add(new StantionSimple
                {
                    StantionId = planeStation.Id, StantionName = qq1, TripName = trip.Name, InTime = planeStation.InTime
                });
                currentTripId = planeStation.TripId;
            }

            var planeBrigades = await sqlRPlaneBrigadeTrains.ByPlanedRouteTrainId(input.PlanedRouteTrainId);

            planeBrigades = planeBrigades.Where(x => x.StantionStartId == input.EntityId).ToList();


            var result = new ChangeTimeRangeBrigadeDto
            {
                Users      = new List <ChangeTimeRangeUserDto>(),
                DataSource = new DataSource
                {
                    Stantions = stationsSimple
                                .OrderBy(x => x.TripName).ThenBy(y => y.InTime)
                                .Select(x => new DataSourceDto {
                        Value = x.StantionId, Text = x.StantionName
                    })
                                .ToList(),

                    Users = users
                            .OrderBy(x => x.Name)
                            .Select(x => new DataSourceDto {
                        Value = x.Id, Text = x.Name
                    })
                            .ToList()
                }
            };

            foreach (var planeBrigade in planeBrigades)
            {
                var changeBrigade = await sqlRChangedBrigadeTrains.ByPlaneBrigadeTrainId(planeBrigade.Id) ?? new ChangePlaneBrigadeTrain
                {
                    StantionEndId = 0, StantionStartId = 0, Droped = false, UserId = 0
                };

                var planeStartStation = await sqlRPlanedStations.ById(planeBrigade.StantionStartId);

                var planeEndStation = await sqlRPlanedStations.ById(planeBrigade.StantionEndId);

                var realStartStation = await sqlRStations.ById(planeStartStation.StantionId);

                var realEndStation = await sqlRStations.ById(planeEndStation.StantionId);

                var planedUser = await sqlRUsers.ById(planeBrigade.UserId);

                var toAdd = new ChangeTimeRangeUserDto
                {
                    StartId             = planeStartStation.Id,
                    EndId               = planeEndStation.Id,
                    UserId              = planedUser.Id,
                    User                = planedUser.Name,
                    Start               = realStartStation.Name,
                    End                 = realEndStation.Name,
                    PlaneBrigadeTrainId = planeBrigade.Id,
                    Canseled            = changeBrigade.Droped
                };

                if (changeBrigade.UserId != 0)
                {
                    toAdd.UserId = changeBrigade.UserId;
                }
                if (changeBrigade.StantionEndId != 0)
                {
                    toAdd.EndId = changeBrigade.StantionEndId;
                }
                if (changeBrigade.StantionStartId != 0)
                {
                    toAdd.StartId = changeBrigade.StantionStartId;
                }


                result.Users.Add(toAdd);
            }
            return(result);
        }
        public async Task DeleteFromPlanedRouteTrains(int planedRouteTrainsId)
        {
            using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
            {
                var sqlRPlanedInspectionOnRoutes = new PlanedInspectionRoutesRepository(_logger);
                var sqlRPlaneStations            = new PlanedStationOnTripsRepository(_logger);
                var sqlRPlaneBrigades            = new PlaneBrigadeTrainsRepository(_logger);
                var sqlRPlanedRouteTrains        = new PlanedRouteTrainsRepository(_logger);

                var sqlRChangedInspections = new ChangedPlanedInspectionRoutesRepository(_logger);
                var sqlRChangedBrigades    = new ChangePlaneBrigadeTrainsRepository(_logger);
                var sqlRChangedStations    = new ChangePlaneStantionOnTripsRepository(_logger);

                //ебаем нахуй инспекции
                var planedInspections = await sqlRPlanedInspectionOnRoutes.ByPlanedRouteTrainId(planedRouteTrainsId);

                foreach (var planedInspection in planedInspections)
                {
                    //Блядь чистим изменненые к хуям.
                    var changed = await sqlRChangedInspections.ByPlanedInspectionRouteId(planedInspection.Id);

                    if (changed != null)
                    {
                        await sqlRChangedInspections.Delete(changed.Id);
                    }
                    await sqlRPlanedInspectionOnRoutes.Delete(planedInspection.Id);
                }

                //Ебаем юзеров к хуям
                var planeBrigades = await sqlRPlaneBrigades.ByPlanedRouteTrainId(planedRouteTrainsId);

                foreach (var planeBrigade in planeBrigades)
                {
                    //Блядь чистим изменненые к хуям.
                    var changed = await sqlRChangedBrigades.ByPlaneBrigadeTrainId(planeBrigade.Id);

                    if (changed != null)
                    {
                        await sqlRChangedBrigades.Delete(changed.Id);
                    }
                    await sqlRPlaneBrigades.Delete(planeBrigade.Id);
                }

                //ебаем станки
                var planeStations = await sqlRPlaneStations.ByPlannedRouteTrainId(planedRouteTrainsId);

                foreach (var planeStation in planeStations)
                {
                    //Блядь чистим изменненые к хуям.
                    var changed = await sqlRChangedStations.ByPlaneStantionOnTripId(planeStation.Id);

                    if (changed != null)
                    {
                        await sqlRChangedStations.Delete(changed.Id);
                    }
                    await sqlRPlaneStations.Delete(planeStation.Id);
                }


                //Ну и главную хуету нахуй
                await sqlRPlanedRouteTrains.Delete(planedRouteTrainsId);

                transaction.Complete();
            }
        }
        public async Task <List <PlanedRouteTrainDto> > PlanedRouteTrainsTable(DateTime startTime, DateTime EndTime)
        {
            var sqlRPlanedRouteTrains    = new PlanedRouteTrainsRepository(_logger);
            var sqlRRoutes               = new RoutesRepository(_logger);
            var sqlRTrains               = new TrainRepository(_logger);
            var sqlRUsers                = new UserRepository(_logger);
            var sqlRDayOfROutes          = new DayOfRoutesRepoisitory(_logger);
            var sqlRStations             = new StantionsRepository(_logger);
            var sqlRPlaneStationsOnTrips = new PlanedStationOnTripsRepository(_logger);
            var sqlRPlaneBrigadeTrains   = new PlaneBrigadeTrainsRepository(_logger);
            var planedRouteTrains        = await sqlRPlanedRouteTrains.GetAll();

            planedRouteTrains = planedRouteTrains.Where(x => x.Date >= startTime && x.Date < EndTime).ToList();
            //var result = new List<PlanedRouteTrainDto>();

            var dictionary = new Dictionary <int, PlanedRouteTrainDto>();
            //var routeDictionary = planedRouteTrains.ToDictionary(e => e.RouteId);

            //Собственно надо набить словарик доступными роутами
            var routes = await sqlRRoutes.GetAll(0, Int32.MaxValue, null);

            routes.Data = routes.Data.Where(x => x.TurnoverId != null).ToList();

            foreach (var route in routes.Data)
            {
                var planedRouteTrainDto = new PlanedRouteTrainDto
                {
                    Route     = route,
                    RouteDays = new List <DayOfWeek>(),
                    DaysData  = new List <DayData>()
                };


                if (route.TurnoverId != null)
                {
                    var daysOfRoutes = await sqlRDayOfROutes.DaysByTurnoverId((int)route.TurnoverId);

                    var days = daysOfRoutes.Select(x => x.Day);
                    planedRouteTrainDto.RouteDays.AddRange(days);
                    var proccesDate = startTime;

                    while (proccesDate <= EndTime)
                    {
                        var currentDay = proccesDate.DayOfWeek;
                        if (days.Contains(currentDay))
                        {
                            planedRouteTrainDto.DaysData.Add(new DayData
                            {
                                Date = proccesDate.Date, DateString = proccesDate.Date.ToString()
                            });
                        }
                        proccesDate = proccesDate.AddDays(1);
                    }
                }

                if (dictionary.ContainsKey(route.Id))
                {
                    dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                }
                else
                {
                    dictionary.Add(route.Id, planedRouteTrainDto);
                }
            }

            foreach (var planedRouteTrain in planedRouteTrains)
            {
                //достаем роут
                var route = await sqlRRoutes.ById(planedRouteTrain.RouteId);

                //var currentRouteItems = planedRouteTrains.Where(e => e.RouteId == route.Id);
                var planedRouteTrainDto = new PlanedRouteTrainDto
                {
                    Route    = route,
                    DaysData = new List <DayData>()
                };

                var toAdd = new DayData
                {
                    Train = await sqlRTrains.ById(planedRouteTrain.TrainId),
                    PlanedRouteTrainId = planedRouteTrain.Id,
                    Date = planedRouteTrain.Date
                };
                toAdd.DateString = toAdd.Date.ToString("yyyy-MM-ddTHH:mm:ssZ");
                var planeBrigadeTrains = await sqlRPlaneBrigadeTrains.ByPlanedRouteTrainId(planedRouteTrain.Id);

                toAdd.Users = new List <DaysUser>();
                foreach (var planeBrigadeTrain in planeBrigadeTrains)
                {
                    var user = await sqlRUsers.ById(planeBrigadeTrain.UserId);

                    var userToAdd = new DaysUser
                    {
                        UserId = user.Id, Name = user.Name, PlaneBrigadeTrainsId = planeBrigadeTrain.Id
                    };
                    userToAdd.UserStations = new UserStations();
                    var planedStationInput = await sqlRPlaneStationsOnTrips.ById(planeBrigadeTrain.StantionStartId);

                    userToAdd.UserStations.InputTime = planedStationInput.OutTime;
                    userToAdd.UserStations.InputName = (await sqlRStations.ById(planedStationInput.StantionId)).Name;

                    var planedStationOutput = await sqlRPlaneStationsOnTrips.ById(planeBrigadeTrain.StantionEndId);

                    userToAdd.UserStations.OutputTime = planedStationOutput.InTime;
                    userToAdd.UserStations.OutputName = (await sqlRStations.ById(planedStationOutput.StantionId)).Name;
                    //userToAdd.UserStations.InputName = (await sqlRStations.ById(planeBrigadeTrain.StantionStartId)).Name;
                    //userToAdd.UserStations.OutputName = (await sqlRStations.ById(planeBrigadeTrain.StantionEndId)).Name;
                    toAdd.Users.Add(userToAdd);
                }

                planedRouteTrainDto.DaysData.Add(toAdd);


                if (dictionary.ContainsKey(route.Id))
                {
                    //надо взять текущие деньки роута и проверить что такого еще нет. кстати если его нет надо нахуй послать, а если есть заменить.
                    var currentDays = dictionary[route.Id].DaysData;
                    var day         = currentDays.FirstOrDefault(x =>
                                                                 x.Date.Date.Equals(planedRouteTrainDto.DaysData.First().Date.Date));
                    if (day == null)
                    {
                        dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                        continue;
                    }

                    //throw new ValidationException("На этот день нельзя добавить поезд");
                    var index = dictionary[route.Id].DaysData.IndexOf(day);
                    dictionary[route.Id].DaysData[index] = planedRouteTrainDto.DaysData.First();
                    //dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                }
                else
                {
                    dictionary.Add(route.Id, planedRouteTrainDto);
                }
            }


            //var train = await sqlRTrains.ByIdWithStations(planedRouteTrain.TrainId);

            var result = new List <PlanedRouteTrainDto>();

            result.AddRange(dictionary.Values);

            return(result);
        }