public async Task <OperationResult <List <Profile> > > ListAsync() { try { var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.FromSeconds(30) }; using (var ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions, TransactionScopeAsyncFlowOption.Enabled)) { var result = await _dao.ListAsync(); ts.Complete(); return(new OperationResult <List <Profile> >() { Success = true, Result = result }); } } catch (Exception e) { return(new OperationResult <List <Profile> >() { Success = false, Exception = e }); } }
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 }); } }