Example #1
0
        public Task <MethodResult> CreateAsync(PersonViewModel personViewModel) =>
        TryExtensions.TryAsync(async() => {
            var validationResult = await ValidatePersonViewModel(personViewModel);
            if (!validationResult.IsSuccess)
            {
                return(validationResult);
            }

            var standardPhoneResult = PhoneUtility.GetPhone(personViewModel.Phone);
            if (!standardPhoneResult.IsSuccess)
            {
                return(MethodResult.Fail(standardPhoneResult.Detail));
            }

            personViewModel.Phone            = standardPhoneResult.Value;
            personViewModel.RegisterDateTime = DateTime.UtcNow;
            var mainPersonModel = MapToMainModel(personViewModel);

            if (personViewModel.ProfilePhotoFile != null)
            {
                var processResult = await ProcessFile(personViewModel.ProfilePhotoFile, personViewModel.Id);
                if (!processResult.IsSuccess)
                {
                    return(MethodResult.Fail(processResult.Detail));
                }

                mainPersonModel.ProfileImageName = processResult.Value;
            }

            await _context.Person.AddAsync(mainPersonModel);
            await _context.SaveChangesAsync();
            return(MethodResult.Ok());
        }, 1);
Example #2
0
        private void IndexWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            InitialiseFields();

            var canAccessFile = false;

            TryExtensions.Try(() => canAccessFile = FileName.CanAccessFile()).Times(10);
            if (!canAccessFile)
            {
                return;
            }

            ShowFile();
        }
 public static void Main() =>
 TryExtensions.Try(Crawler.Start)
 .Tee(methodResult =>
      Console.WriteLine(methodResult.IsSuccess ? "Success" : methodResult.Detail.ToString()));
Example #4
0
 public static Try <A> Try <A>(Func <A> f) =>
 TryExtensions.Memo <A>(() => f());
Example #5
0
 public Task <MethodResult <List <string> > > DetectFileTypeAsync(
     string fileName, int maximumReadBytes = MaximumReadBytes) =>
 TryExtensions.TryAsync(() => ReadBytesAsync(fileName, maximumReadBytes))
 .OnSuccessAsync(bytes => _fileSignatureValidation.FindSignature(ConvertBytesToHexString(bytes)));