public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] DependentDomainModel model)
        {
            if (model == null || model.DependentId != id)
            {
                return(BadRequest("The model that is passed in is empty. Model object is required."));
            }

            DependentDomainModel selected;

            try
            {
                selected = await _domain.GetAsync(id).ConfigureAwait(false);

                if (selected == null)
                {
                    return(NotFound("The asset category selected to be updated could not be found."));
                }
            }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            selected.FirstName    = model.FirstName;
            selected.LastName     = model.LastName;
            selected.ModifiedDate = DateTime.UtcNow;

            try { await _domain.UpdateAsync(selected).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(Ok(selected));
        }
Esempio n. 2
0
        public void UpdateAsync_WithNullDependentParameter_ReturnArgumentNullException()
        {
            Func <Task> act = () => _domain.UpdateAsync(null);

            act.Should().Throw <ArgumentNullException>();
        }