コード例 #1
0
        public async Task <CreateTaskResponse> Process(CreateTaskRequest request)
        {
            var task = new CssTask(request.Name);

            task.SetDueDate(request.DueDate);
            task.SetDescription(request.Description);
            task.SetScheduledDate(request.ScheduledDate);

            //we don't allow them to save invalid tasks.
            if (task.IsValid())
            {
                try
                {
                    await _repository.Save(task);

                    return(new CreateTaskResponse(true));
                }
                catch (Exception ex)
                {
                    //Oh crap errors, validations are handled by is valid.
                    _logger.LogError(ex, "Unable to create task.");
                    var errors = new Validations();
                    errors.AddError(ErrorCode.Unexpected, ex.Message);
                    return(new CreateTaskResponse(false, errors));
                }
            }
            return(new CreateTaskResponse(false, task.Errors));
        }
コード例 #2
0
        public async Task <UpdateTaskResponse> Process(UpdateTaskRequest request)
        {
            try
            {
                var user = await _userRepository.GetBySubject(request.Subject);

                var cssTask = _repository.Get(request.Id, user.Identity.Id).GetAwaiter().GetResult();

                cssTask.SetDescription(request.Description);
                cssTask.SetName(request.Name);
                cssTask.SetDueDate(request.DueDate);
                cssTask.SetScheduledDate(request.ScheduledDate);

                if (cssTask.IsValid())
                {
                    await _repository.Save(cssTask);

                    return(new UpdateTaskResponse(true));
                }
                else
                {
                    return(new UpdateTaskResponse(false, cssTask.Errors));
                }
            }
            catch (Exception ex)
            {
                var validations = new Validations();
                validations.AddError(ErrorCode.Unexpected, "Unable to update example model.");
                return(new UpdateTaskResponse(false, validations));
            }
        }
コード例 #3
0
        public UpdateExampleResponse Process(UpdateExampleRequest request)
        {
            try
            {
                var example = _repository.Get(request.Id);

                example.UpdateProperty1(request.Property1);
                if (example.IsValid())
                {
                    _repository.Save(example);
                    return(new UpdateExampleResponse(true));
                }
                else
                {
                    return(new UpdateExampleResponse(false, example.Errors));
                }
            }
            catch (Exception ex)
            {
                var validations = new Validations();
                validations.AddError(ErrorCode.Unexpected, "Unable to update example model.");
                return(new UpdateExampleResponse(false, validations));
            }
        }