Ejemplo n.º 1
0
        private async Task <bool> ValidateCustomer(RepairTicket RepairTicket)
        {
            if (RepairTicket.CustomerId == 0)
            {
                RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Customer), ErrorCode.CustomerEmpty);
            }
            else
            {
                CustomerFilter CustomerFilter = new CustomerFilter
                {
                    Id = new IdFilter {
                        Equal = RepairTicket.CustomerId
                    },
                    StatusId = new IdFilter {
                        Equal = StatusEnum.ACTIVE.Id
                    }
                };

                var count = await UOW.CustomerRepository.Count(CustomerFilter);

                if (count == 0)
                {
                    RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Customer), ErrorCode.CustomerNotExisted);
                }
            }
            return(RepairTicket.IsValidated);
        }
Ejemplo n.º 2
0
 private async Task <bool> ValidateDeviceState(RepairTicket RepairTicket)
 {
     if (string.IsNullOrWhiteSpace(RepairTicket.DeviceState))
     {
         RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.DeviceState), ErrorCode.DeviceStateEmpty);
     }
     else
     {
         if (RepairTicket.DeviceState.Length > 500)
         {
             RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.DeviceState), ErrorCode.DeviceStateOverLength);
         }
     }
     return(RepairTicket.IsValidated);
 }
Ejemplo n.º 3
0
 private async Task <bool> ValidateItem(RepairTicket RepairTicket)
 {
     if (RepairTicket.ItemId == 0)
     {
         RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Item), ErrorCode.ItemEmpty);
     }
     return(RepairTicket.IsValidated);
 }
Ejemplo n.º 4
0
 private async Task <bool> ValidateOrder(RepairTicket RepairTicket)
 {
     if (RepairTicket.OrderId == 0)
     {
         RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.OrderId), ErrorCode.OrderEmpty);
     }
     return(RepairTicket.IsValidated);
 }
Ejemplo n.º 5
0
        private async Task <bool> ValidateOrderCategory(RepairTicket RepairTicket)
        {
            if (RepairTicket.OrderCategoryId == 0)
            {
                RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.OrderCategoryId), ErrorCode.OrderCategoryEmpty);
            }
            else
            {
                var OrderCategoryIds = OrderCategoryEnum.OrderCategoryEnumList.Select(x => x.Id).ToList();
                if (!OrderCategoryIds.Contains(RepairTicket.OrderCategoryId))
                {
                    RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.OrderCategoryId), ErrorCode.OrderCategoryNotExisted);
                }
            }

            return(RepairTicket.IsValidated);
        }
Ejemplo n.º 6
0
        private async Task <bool> ValidateCode(RepairTicket RepairTicket)
        {
            if (string.IsNullOrWhiteSpace(RepairTicket.Code))
            {
                RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeEmpty);
            }
            else
            {
                var Code = RepairTicket.Code;
                if (RepairTicket.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(RepairTicket.Code))
                {
                    RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeHasSpecialCharacter);
                }
                else
                {
                    if (RepairTicket.Code.Length > 255)
                    {
                        RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeOverLength);
                    }
                    else
                    {
                        RepairTicketFilter RepairTicketFilter = new RepairTicketFilter
                        {
                            Skip = 0,
                            Take = 10,
                            Id   = new IdFilter {
                                NotEqual = RepairTicket.Id
                            },
                            Code = new StringFilter {
                                Equal = RepairTicket.Code
                            },
                            Selects = RepairTicketSelect.Code
                        };

                        int count = await UOW.RepairTicketRepository.Count(RepairTicketFilter);

                        if (count != 0)
                        {
                            RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeExisted);
                        }
                    }
                }
            }
            return(RepairTicket.IsValidated);
        }
Ejemplo n.º 7
0
        public async Task <bool> ValidateId(RepairTicket RepairTicket)
        {
            RepairTicketFilter RepairTicketFilter = new RepairTicketFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = RepairTicket.Id
                },
                Selects = RepairTicketSelect.Id
            };

            int count = await UOW.RepairTicketRepository.Count(RepairTicketFilter);

            if (count == 0)
            {
                RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }