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));
        }
        public async Task <IActionResult> DeleteAsync(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest());
            }

            DependentDomainModel deleted = null;

            try { deleted = await _domain.DeleteAsync(id).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(Ok(deleted));
        }
        public async Task <IActionResult> CreateAsync([FromBody] DependentDomainModel model)
        {
            if (model == null)
            {
                return(BadRequest("The model that is passed in is empty. Model object is required."));
            }

            DependentDomainModel inserted;

            try { inserted = await _domain.InsertAsync(model).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(CreatedAtRoute("GetDependent", new { id = inserted.DependentId }, inserted));
        }
Exemple #4
0
        /// <summary> <see cref="IDependentDomain.UpdateAsync"/> </summary>
        /// <exception cref="ArgumentNullException"><paramref name="domainModel"/> is <see langword="null"/></exception>
        public async Task <DependentDomainModel> UpdateAsync(DependentDomainModel domainModel)
        {
            if (domainModel == null)
            {
                throw new ArgumentNullException(nameof(domainModel));
            }

            var model = ToModel <Dependent, DependentDomainModel>(domainModel);

            model = await _repository.UpdateAsync(model).ConfigureAwait(false);

            domainModel = ToModel <DependentDomainModel, Dependent>(model);

            return(domainModel);
        }