/// <summary> /// Справочник неиправностей /// </summary> private static async Task <ReportResponse> GetFaultsTable(ReportRequest input, ILogger logger) { var sqlR = new FaultsRepository(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 = item.Description }; result.Rows.Add(row); } return(result); }
public async Task <JsonResult> GetByEquipmentId(int id) { await CheckPermission(); var cer = new FaultsRepository(_logger); var result = await cer.GetByEquipmentId(id); return(Json(result)); }
public async Task <JsonResult> Delete([FromBody] Fault equipmentCategory) { await CheckPermission(); var cer = new FaultsRepository(_logger); await cer.Delete(equipmentCategory.Id); return(Json(new { message = "Delete OK" })); }
public async Task <JsonResult> GetByEquipmentModelId(int id) { var sqlREquipmentModel = new EquipmentModelsRepository(_logger); var equipmentModel = await sqlREquipmentModel.ById(id); if (equipmentModel == null) { return(Json(new Fault[0])); } await CheckPermission(); var cer = new FaultsRepository(_logger); var result = await cer.GetByEquipmentId(equipmentModel.EquipmentId); return(Json(result)); }
public async Task <DictionaryCrudResponse> FaultCrud(DictionaryCrudRequest input) { var data = input.Fault; if (data == null && input.IdToDelete == null) { throw new ValidationException("Не распарсилось"); } var sqlR = new FaultsRepository(_logger); if (input?.IdToDelete != null) { await sqlR.Delete((int)input.IdToDelete); return(new DictionaryCrudResponse { IsDeleted = true, Fault = data }); } var all = await sqlR.GetAll(); if (all.Any(x => x.Name.Equals(input.Fault.Name))) { throw new ValidationException(Error.AlreadyAddWithThisName); } if (data?.Id == 0) { var item = await sqlR.Add(data); return(new DictionaryCrudResponse { IsAdd = true, Fault = item }); } else { //Неиспользуемая хуета этот тип фаулта data.FaultType = 0; var item = await sqlR.Update(data); return(new DictionaryCrudResponse { IsUpdated = true, Fault = item }); } }
public async Task <JsonResult> Add([FromBody] Fault input) { await CheckPermission(); var sqlR = new FaultsRepository(_logger); Fault result; if (input.Id != 0) { result = await sqlR.Update(input); } else { result = await sqlR.Add(input); } return(Json(result)); }
public async Task <JsonResult> GetAll(int skip, int limit, string filter) { await CheckPermission(); var cer = new FaultsRepository(_logger); var result = new FaultsRepository.FaultPaging(); if (filter != null) { result = await cer.GetAll(skip, limit, filter); } else { result = await cer.GetAll(skip, limit); } result.Data = result.Data.OrderBy(e => e.Name).ToArray(); return(Json(result)); }
private static async Task <List <Row> > GetTaskData(List <TrainTask> tasks, ILogger logger) { var sqlRUsers = new UserRepository(logger); var sqlRTaskStatus = new TaskStatusRepository(logger); var sqlRTaskExecutors = new ExecutorRepository(logger); var sqlRTaskComment = new CommentRepository(logger); var sqlRCarriages = new CarriageRepository(logger); var sqlREquipmentModel = new EquipmentModelsRepository(logger); var sqlREquipment = new EquipmentRepository(logger); var sqlRTrains = new TrainRepository(logger); var sqlRTrainTaskAttributes = new TrainTaskAttributesRepository(logger); var sqlRFault = new FaultsRepository(logger); var rows = new List <Row>(); foreach (var task in tasks) { var currentTaskStatus = (await sqlRTaskStatus.ByTaskId(task.Id)).Last(); var carriage = await sqlRCarriages.ById(task.CarriageId); var user = GetUserById(sqlRUsers, task.UserId); var taskExecutor = (await sqlRTaskExecutors.GetByTaskId(task.Id)).Last(); var equipmentModel = await sqlREquipmentModel.ById(task.EquipmentModelId); var equipment = await sqlREquipment.ById(equipmentModel.EquipmentId); var taskAttributes = await sqlRTrainTaskAttributes.ByTaskId(task.Id); var lastComment = (await sqlRTaskComment.GetByTaskId(task.Id)).LastOrDefault(); var fault = new Fault(); if (taskAttributes.Count == 1 && taskAttributes.First().FaultId.HasValue) { fault = await sqlRFault.ById(taskAttributes.First().FaultId.Value); } var updateData = GetTaskLastUpdate(lastComment, taskExecutor, currentTaskStatus); var toadd = new Row { Id = new RowId(task.Id, 2), HasItems = false.ToString(), ParentId = null, //Ид Col0 = "И" + task.Id, //Статус Col1 = GetStringTaskStatus(currentTaskStatus.Status), //Тип Col2 = GetStringTaskType(task.TaskType), //Состав Col3 = GetTrainById(sqlRTrains, carriage.TrainId).Name, //Инициатор Col4 = user.Name, //Исполнитель Col5 = GetStringBrigadeType(taskExecutor.BrigadeType), //Дата Col6 = task.CreateDate.ToStringDateTime(), ////Вагон Col7 = carriage.Number.ToString(), //Оборудование Col8 = equipment.Name, ////Типовая Неисправность Col9 = fault?.Name, //Обновлено Col10 = updateData?.Date.ToStringDateTime(), //Обновил Col11 = updateData?.User.Name }; if (taskAttributes.Count > 1) { toadd.HasItems = true.ToString(); } rows.Add(toadd); } return(rows); }