Пример #1
0
        public async Task <CheckListEquipmentTableItem> AddChecklist(CheckListEquipmentDto input)
        {
            var res = ValidateChecklistDto(input);

            if (!res.IsValid)
            {
                throw new Exception("обнаружены ошибки: " + string.Join(", ", res.Errors));
            }

            const string sql =
                @"insert into [CheckListEquipments] ([CheckListType],[EquipmentModelId],[FaultType],[NameTask],[Value],[ValueType],[TaskLevel])
                                values(@CheckListType,@EquipmentModelId,@FaultType,@NameTask,@Value,@ValueType,@TaskLevel) select scope_identity()";
            var id = await _db.Connection.QuerySingleAsync <int>(sql, new
            {
                CheckListType    = input.CheckListType,
                EquipmentModelId = input.EquipmentModelId,
                FaultType        = input.FaultType,
                NameTask         = input.NameTask,
                Value            = input.Value,
                ValueType        = input.ValueType,
                TaskLevel        = input.TaskLevel
            });

            //загрузить и вернуть запись по ид? или УИ сам перезапросит всю таблицу?
            var item = await GetById(id);

            return(new CheckListEquipmentTableItem
            {
                Id = item.Id,
                NameTask = item.NameTask,
                FaultType = FaultTypeEnumToString(item.FaultType),
                TaskLevel = TaskLevelEnumToString(item.TaskLevel),
                Value = item.Value.ToString(),
                ValueType = CheckListValueTypeEnumToString(item.ValueType),
                CheckListType = (int)item.CheckListType
            });
        }
Пример #2
0
        private CheckListEquipmentDtoValidationResult ValidateChecklistDto(CheckListEquipmentDto input)
        {
            var ret = new CheckListEquipmentDtoValidationResult();

            if (string.IsNullOrEmpty(input.NameTask))
            {
                ret.IsValid = false;
                ret.Errors.Add("Значение наименования не может быть пустым");
            }

            if (input.ValueType <= 0)
            {
                ret.IsValid = false;
                ret.Errors.Add("Не указан тип проверки");
            }

            if (input.ValueType == CheckListValueType.Bool)
            {
                if (input.Value < 0 || input.Value > 1)
                {
                    ret.IsValid = false;
                    ret.Errors.Add("Недопустимое значение для типа булево");
                }
            }

            if (input.ValueType == CheckListValueType.Int)
            {
                if (input.Value < 0)
                {
                    ret.IsValid = false;
                    ret.Errors.Add("Недопустимое значение для типа число");
                }
            }

            return(ret);
        }