コード例 #1
0
        public async Task <OperationResult <bool> > CreateAsync(Profile item)
        {
            try
            {
                if (_dao.ListAsync().Result.Any(x => x.VatNumber == item.VatNumber && !x.IsDeleted))
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "Vat number already exists"
                           }
                }
                ;
                if (_dao.ListAsync().Result.Any(x => x.PhoneNumber == item.PhoneNumber && !x.IsDeleted))
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "Phone number already exists"
                           }
                }
                ;
                if (item.VatNumber.ToString().Length != 9)
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "VAT number must be 9 digits long"
                           }
                }
                ;
                if (item.PhoneNumber.ToString().Length != 9)
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "Phone number must be 9 digits long"
                           }
                }
                ;
                if (!(item.PhoneNumber.ToString().StartsWith("91") || item.PhoneNumber.ToString().StartsWith("93") || item.PhoneNumber.ToString().StartsWith("96") || item.PhoneNumber.ToString().StartsWith("92")))
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "Enter a valid phone number"
                           }
                }
                ;
                await _dao.CreateAsync(item);

                return(new OperationResult <bool>()
                {
                    Success = true, Result = true
                });
            }
            catch (Exception e)
            {
                return(new OperationResult <bool>()
                {
                    Success = false, Exception = e
                });
            }
        }
コード例 #2
0
        public async Task <OperationResult> CreateAsync(Profile profile)
        {
            try
            {
                await _dao.CreateAsync(profile);

                return(new OperationResult()
                {
                    Success = true
                });
            }
            catch (Exception e)
            {
                return(new OperationResult()
                {
                    Success = false, Exception = e
                });
            }
        }