BillableHoursWebApp.Api.Controllers.CategoriesController.Post C# (CSharp) Method

Post() private method

private Post ( [ model ) : IHttpActionResult
model [
return IHttpActionResult
        public IHttpActionResult Post([FromBody] CategoryRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (this.data.Categories
                .Find(x => x.Name.ToLowerInvariant() == model.Name.ToLowerInvariant()).FirstOrDefault() != null)
            {
                return this.BadRequest("A category with that name exists already!");
            }

            var categoryToAdd = Mapper.Map<Category>(model);

            this.data.Categories.Add(categoryToAdd);
            this.data.SaveChanges();

            return this.Ok(categoryToAdd.Id);
        }