Пример #1
0
        public async Task <IActionResult> PostOrganizationCategory([FromBody] OrganizationCategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var entity = this.mapper.Map <OrganizationCategory>(model);

            await this.repository.InsertAsync(entity);

            return(this.CreatedAtAction(
                       "GetOrganizationCategory",
                       new
            {
                id = entity.Id
            },
                       model));
        }
Пример #2
0
        public async Task <IActionResult> PutOrganizationCategory(
            [FromRoute] long id,
            [FromBody] OrganizationCategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var entity = await this.repository.FindByIdAsync(id);

            if (entity == null)
            {
                return(this.NotFound());
            }

            this.mapper.Map(model, entity);

            await this.repository.UpdateAsync(entity);

            return(this.NoContent());
        }
Пример #3
0
        /// <summary>
        /// Implementors can modify both the source and destination objects
        /// </summary>
        /// <param name="source">Source object</param>
        /// <param name="destination">Destination object</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Process(OrganizationCategoryViewModel source, OrganizationCategory destination)
        {
            var companyId = source.CompanyId;

            destination.Company = companyId != null?this.repositoryCompanies.FindById(companyId.Value) : null;
        }