public ActionResult <CategoryDto> CreateCategory([FromBody] CategoryCreateDto categoryCreateDto) { var category = mapper.Map <Category>(categoryCreateDto); repository.Create(category); repository.SaveChanges(); var caregoryDto = mapper.Map <CategoryDto>(category); return(CreatedAtRoute(nameof(GetCategoryById), new { caregoryDto.Id }, caregoryDto)); }
public async Task <ActionResult <Category> > CreateCategory(Category category) { try { if (category != null) { category.CategoryId = Guid.NewGuid().ToString(); var createdCategory = await repo.Create(category); if (createdCategory != null) { return(CreatedAtAction(nameof(GetCategory), new { id = createdCategory.CategoryId }, createdCategory)); } } return(BadRequest()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Error retrieving data from the database. Error message:{e.Message}")); } }
public IHttpActionResult Create(CategoryViewModel category) { var dataCategory = _categoryRepo.Create(category); return(Ok(dataCategory)); }