Exemplo n.º 1
0
 public OperationResult <List <Profile> > List()
 {
     try
     {
         var transactionOptions = new TransactionOptions
         {
             IsolationLevel = IsolationLevel.ReadCommitted,
             Timeout        = TimeSpan.FromSeconds(30)
         };
         using (var ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions, TransactionScopeAsyncFlowOption.Enabled))
         {
             var result = _dao.List();
             ts.Complete();
             return(new OperationResult <List <Profile> >()
             {
                 Success = true, Result = result
             });
         }
     }
     catch (Exception e)
     {
         return(new OperationResult <List <Profile> >()
         {
             Success = false, Exception = e
         });
     }
 }
 public OperationResult <bool> Create(Profile item)
 {
     try
     {
         if (_dao.List().Any(x => x.VatNumber == item.VatNumber && !x.IsDeleted))
         {
             return new OperationResult <bool>()
                    {
                        Success = true, Result = false, Message = "Vat number already exists"
                    }
         }
         ;
         if (_dao.List().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"
                    }
         }
         ;
         _dao.Create(item);
         return(new OperationResult <bool>()
         {
             Success = true, Result = true
         });
     }
     catch (Exception e)
     {
         return(new OperationResult <bool>()
         {
             Success = false, Exception = e
         });
     }
 }