Пример #1
0
 public Task<OperationResponse> DeleteUserAsync(Validated<int> id)
 {
     return id.Validate(new IdValidator())
         .IfValidAsync(() => _unitOfWorkFactory.DoAsync(() =>
     {
         _userRepository.Delete(id);
     }));
 }
Пример #2
0
 private void Edit_Validated(object sender, EventArgs e)
 {
     Validated?.Invoke(this, e);
 }
Пример #3
0
 /// <summary>
 /// Called when the object is validated.
 /// </summary>
 protected virtual void OnValidated()
 {
     Validated.SafeInvoke(this);
 }
 private void RaiseValidated(IEnumerable <IValidationResult> validationResults)
 {
     Validated?.Invoke(this, new DataEventArgs <IEnumerable <IValidationResult> >(validationResults));
 }
Пример #5
0
 public CategoryService(IUnitOfWork unitOfWork)
 {
     Validated.NotNull(unitOfWork, nameof(unitOfWork));
     this.unitOfWork = unitOfWork;
 }
 private static void assertInvalid <E, A>(List <E> expected, Validated <E, A> v)
 {
     Assert.False(v.isValid);
     Assert.Equal(expected, v.getInvalid);
 }
Пример #7
0
 public async Task<UserDto> GetByIdAsync(Validated<int> id)
 {
     var user = await _context.Users.FindAsync(id.Value);
     return user.ToDto<UserDto>();
 }
Пример #8
0
 public WebSiteController(IWebsiteService websiteService)
 {
     Validated.NotNull(websiteService, nameof(websiteService));
     this.websiteService = websiteService;
 }
 private void Validate_OnClick(object sender, RoutedEventArgs e)
 => Validated?.Invoke(this, EventArgs.Empty);
Пример #10
0
 public EFRepository(MsSqlDbContext context)
 {
     Validated.NotNull(context, nameof(context));
     this.context = context;
 }
Пример #11
0
 public async Task<HttpResponseMessage> DeleteAsync(Validated<int> id)
 {
     await _userService.DeleteUserAsync(id);
     return Request.CreateResponse(HttpStatusCode.OK);
 }
Пример #12
0
 public static Validated <string, A> invalid <A>(this string e)
 {
     return(Validated <string, A> .invalid(e));
 }
Пример #13
0
 public static Validated <E, A> invalid <E, A>(this E e)
 {
     return(Validated <E, A> .invalid(e));
 }
Пример #14
0
 public static Validated <string, A> valid <A>(this A a)
 {
     return(Validated <string, A> .valid(a));
 }
Пример #15
0
    /// <summary>
    /// Execute a validated command by sending the message to an aggregate. If the command is valid, the command will be processed
    /// by the aggregate. When the command has been handled successfully, and events are returned as a result, the events
    /// are aggregated to create the next state of the viewmodel, by calling the user defined Update function.
    /// Then a notification is sent to signal the state of the viewmodel has changed. This will trigger the component
    /// to rerender, so that it can show the correct state in the user interface. This rerendering triggers the user defined View
    /// function, which signifies how the view should be rendered
    /// </summary>
    /// <param name="target">The aggrgate that will handle the command</param>
    /// <param name="command">The validate command that the aggregate will handle, if it is valid. </param>
    /// <returns>When the command is not valid, it will return Some errors, None otherwise</returns>
    protected async Task <Option <Error[]> > Dispatch(Aggregate <TCommand, TEvent> target, Validated <TCommand> command)
    {
        Result <CommandResult <TEvent>, Error[]> result = await target.Accept(command);

        switch (result)
        {
        case Ok <CommandResult <TEvent>, Error[]>(var commandResult):
            _shouldRender = commandResult.Events.Any();
            ViewModel     = Update(ViewModel, commandResult.Events);
            StateHasChanged();
            return(None <Error[]>());

        case Error <CommandResult <TEvent>, Error[]>(var errors):
            _shouldRender    = true;
            ViewModel.Errors = errors;
            StateHasChanged();
            return(Some(errors));

        default:
            _shouldRender = false;
            throw new ArgumentOutOfRangeException(nameof(result));
        }
    }
Пример #16
0
 public static Validated <TResult> Bind <T, TResult>(this Validated <T> result, Func <T, Validated <TResult> > function) => result switch
 {
 // ReSharper disable UnusedParameter.Local
 private static void assertValid <E, A>(A expected, Validated <E, A> v)
 {
     Assert.True(v.isValid);
     Assert.Equal(expected, v.getValid);
 }
Пример #18
0
 public void Create(TaskList tasklist)
 {
     _db.TaskLists.Add(tasklist);
     Validated.SaveIt(_db);
 }
Пример #19
0
        public async Task <HttpResponseMessage> DeleteAsync(Validated <int> id)
        {
            await _userService.DeleteUserAsync(id);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }