public static Category ToEntity(this CategoryCreationDto dto) { return(new Category { Description = dto.Description, Code = dto.Code }); }
public async Task <ActionResult <CategoryDto> > Add(CategoryCreationDto item) { var na = new Category(ObjectId.Empty, item.name); await categoryController.InsertOneAsync(na); return(CreatedAtRoute(nameof(GetSingleCategory), new { id = na.Id }, new CategoryDto(na.Id.ToString(), na.category))); }
public async Task <IActionResult> CreateCategory([FromBody] CategoryCreationDto category) { var categoryEntity = _mapper.Map <Category>(category); _repository.Category.CreateCategory(categoryEntity); await _repository.SaveAsync(); var createdCategory = _mapper.Map <CategoryDto>(categoryEntity); return(CreatedAtRoute("CategoryById", new { id = createdCategory.categoryId }, createdCategory)); }
public async Task <IActionResult> CreateCategory(CategoryCreationDto dto) { var newCategory = new CategoryCreationDto { Name = dto.Name }; await _categoryRepository.Create(newCategory); return(Ok(dto)); }
public async Task <IActionResult> DeleteCategory(CategoryCreationDto dto) { try { await _categoryRepository.Delete(dto); return(Ok()); } catch (Exception e) { return(NotFound("This Category cannot be delete")); } }
public IActionResult Add([FromBody] CategoryCreationDto request) { try { _service.Add(request.ToEntity()); return(Ok()); } catch (Exception e) { _logger.LogError(-1, e, String.Format(LogErrorText, e.Message)); return(BadRequest(String.Format(BadRequestText, "adding category"))); } }
public async Task <IActionResult> AddCategory(CategoryCreationDto category) { if (!ModelState.IsValid) { return(UnprocessableEntity()); } var creationCategory = _mapper.Map <Category>(category); if (await _repo.AddCategory(creationCategory)) { return(CreatedAtRoute("category", new { CategoryID = creationCategory.CategoryID }, _mapper.Map <CategoryDto>(creationCategory))); } return(BadRequest()); }
public async Task <IActionResult> UpdateCategory(CategoryCreationDto dto) { try { var update = new CategoryCreationDto { Name = dto.Name }; await _categoryRepository.Update(dto); return(Ok(update)); } catch (Exception e) { return(NotFound("This Category cannot be changed")); } }