예제 #1
0
        public void Populate()
        {
            // Inspections
            IEnumerable <Inspection>          inspections  = Repo.GetAll();
            IEnumerable <InspectionViewModel> inspectionVM = inspections
                                                             .Select(i => new InspectionViewModel(i));

            Inspections = new ObservableCollection <InspectionViewModel>(inspectionVM);
        }
        // GET: Inspection
        public ActionResult Index()
        {
            ViewBag.YearList = commonUtility.Years();
            ViewBag.WeekList = commonUtility.Weeks();

            var data = inspectionRepository.GetAll();

            inspectionModel.Inspections = data;

            if (year != null && week != null)
            {
                var filterByYearAndWeek = inspectionUtility.
                                          FilterByYearAndWeek(Convert.ToInt32(year), Convert.ToInt32(week)).Values;
                ViewBag.WeeklyAmount        = filterByYearAndWeek.Sum(w => w.Amount);
                inspectionModel.Inspections = filterByYearAndWeek;
            }
            if (year != null && week == null)
            {
                var filterByYear = inspectionUtility.
                                   FilterByYear(Convert.ToInt32(year)).Values;
                inspectionModel.Inspections = filterByYear;
            }
            if (year == null && week != null)
            {
                TempData["Message"] = "You can not send filter just only use week, please select year also";
                return(RedirectToAction("Messages", "Inspection"));
            }
            if (year == null && week == null)
            {
                year = Convert.ToString(DateTime.Now.Year);
                week = Convert.ToString(commonUtility.GetWeekNumber(DateTime.Now));
                var filterByYearAndWeek = inspectionUtility.
                                          FilterDefault(Convert.ToInt32(year), Convert.ToInt32(week)).Values;
                ViewBag.WeeklyAmount        = filterByYearAndWeek.Sum(w => w.Amount);
                inspectionModel.Inspections = filterByYearAndWeek;
            }

            return(View(inspectionModel));
        }
        public void ShouldRetriveAllInpections()
        {
            using (var context = InitAndGetDbContext())
            {
                //Arrange
                var repositori = new InspectionRepository(context);

                //Act
                IEnumerable <Inspection> result = repositori.GetAll();

                //Assert
                Assert.Equal(3, result.Count());
            }
        }
예제 #4
0
        //30 - Приёмка поезда ПР
        //31 - Выпуск поезда ПР
        //32 - Приёмка поезда ЛБ
        //33 - Сдача поезда ЛБ

        public async Task <JournalPaging> GetJournalInspectionAndTasks(int skip, int limit, string filter)
        {
            var sqlr = new InspectionRepository(_logger);

            var inspdatarep  = new InspectionDataRepository(_logger);
            var sqlTrainR    = new TrainRepository(_logger);
            var sqlUserR     = new UserRepository(_logger);
            var iR           = new InspectionRepository(_logger);
            var mR           = new MeterageRepository(_logger);
            var sqlStatusR   = new TaskStatusRepository(_logger);
            var sqlExecutorR = new ExecutorRepository(_logger);
            var sqlRTask     = new TaskRepository(_logger);
            var sqlRBrigade  = new BrigadeRepository(_logger);
            var sqlRJournal  = new JournalRepository(_logger);

            var listFull = new List <JournalDateItem>();

            var fromSqlsInspections = await sqlr.GetAll();

            foreach (var fromSqlsInspection in fromSqlsInspections)
            {
                var train = (await sqlTrainR.ByIdWithStations(fromSqlsInspection.TrainId));
                var user  = await sqlUserR.ById(fromSqlsInspection.UserId);

                var journalInspection = new JournalInspection
                {
                    Id           = fromSqlsInspection.Id,
                    Type         = "inspection",
                    InspectionId = fromSqlsInspection.Id,
                    StatusId     = (int)fromSqlsInspection.Status,
                    TypeId       = (int)fromSqlsInspection.CheckListType,
                    Date         = fromSqlsInspection.DateStart,
                    TrainName    = train.Name,
                    TrainId      = train.Id,
                    Tabs         = new JournalInspectionTabs(),
                    UserName     = user.Name,
                };

                if (user.BrigadeId != null)
                {
                    journalInspection.OwnerBrigadeType = (await sqlRBrigade.ById((int)user.BrigadeId)).BrigadeType;
                }


                //дескрипшен
                var counters = await iR.GetCounters(fromSqlsInspection.Id);

                journalInspection.Tabs.Description = new JournalInspectionDescription
                {
                    TasksCount = counters.Tasks,
                    DataEnd    = fromSqlsInspection.DateEnd,
                    //Выдает количество уникальных меток
                    AllLabelCount = counters.Labels,
                    TempCount     = counters.Measurements
                };


                //лейблы
                await getInspectionLabels(mR, fromSqlsInspection, journalInspection);

                //измерения
                await getInspectionMeterage(mR, fromSqlsInspection, journalInspection);

                //счетчики
                await GetInspectionCouters(inspdatarep, fromSqlsInspection, journalInspection);

                //говнохак под ебанутые фильтры и вывод. TypeId == 2 - Приемка, 3 - сдача
                changeInspetionTypeForUi(journalInspection);


                //Фильтруем
                var isFiltered = await InspectionFilter(filter, sqlRTask, fromSqlsInspection, journalInspection);

                if (!isFiltered)
                {
                    listFull.Add(new JournalDateItem
                    {
                        Date       = journalInspection.Date,
                        Inspection = journalInspection
                    }
                                 );
                }
            }


            //Таски

            var fromSqlsT = await sqlRJournal.GetAllTaskForJournal();

            foreach (var fromSql in fromSqlsT)
            {
                var journalTask = new JournalTask
                {
                    Type                  = "Task",
                    TaskId                = fromSql.TaskId,
                    TaskType              = fromSql.TaskType,
                    TrainName             = fromSql.TrainName,
                    TrainId               = fromSql.TrainId,
                    UserName              = fromSql.UserName,
                    Date                  = fromSql.CreateDate,
                    CarriageName          = CreateCarriageName(fromSql.TrainName, fromSql.CarriageNumber),
                    CarriageNum           = fromSql.CarriageNumber,
                    CarriageId            = fromSql.CarriageId,
                    EquipmentName         = fromSql.EquipmentName,
                    FaultName             = fromSql.FaultName,
                    InspectionInfo        = _GetInspectionInfo(fromSql.InspectionId, fromSql.InspectionType),
                    CarriagesSerialNumber = fromSql.CarriagesSerialNumber,
                    TaskAttributeId       = fromSql.TaskAttributeId
                };

                var executor = (await sqlExecutorR.GetByTaskId(fromSql.TaskId)).LastOrDefault();
                if (executor != null)
                {
                    journalTask.ExecutorBrigadeType = (int)executor.BrigadeType;
                }


                var taskStatus = sqlStatusR.GetByTrainTaskId(fromSql.TaskId);
                if (taskStatus != null)
                {
                    journalTask.StatusId = (int)sqlStatusR.GetByTrainTaskId(fromSql.TaskId).Status;
                }
                //journalTask.StatusId = fromSql.TaskId;

                var isFiltered = TaskFilter(filter, fromSql, journalTask);
                if (!isFiltered)
                {
                    //response.Add(journalTask.ToJson());
                    listFull.Add(new JournalDateItem
                    {
                        Date = journalTask.Date,
                        Task = journalTask
                    }
                                 );
                }
            }



            //sort by date
            listFull.Sort((x, y) => y.Date.CompareTo(x.Date));

            //пагинация
            List <JournalDateItem> listSkiplimit = paging(skip, ref limit, listFull);

            //Делаем жсон стрингу для вывода
            var pagingList = new List <string>();

            converToJsonString(listSkiplimit, pagingList);

            var result = new JournalPaging
            {
                Data  = pagingList.ToArray(),
                Total = listFull.Count
            };

            return(result);
        }