public async Task <IActionResult> Post([FromBody] InsertPostCategory model) { var result = await postCategoryServices.Add(model); if (result.Status) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <TypedResult <PostCategoryDTO> > Add(InsertPostCategory postCategory) { try { PostCategory existsRecord = (await postCategoryRepo.GetList(condition: x => x.Title.Equals(postCategory.Title))).FirstOrDefault(); if (existsRecord != null) { throw new InvalidOperationException(ErrorMessages.THIS_RECORD_ALREADY_EXISTS); } PostCategory entity = _mapper.Map <PostCategory>(postCategory); PostCategory result = await postCategoryRepo.Add(entity); return(new TypedResult <PostCategoryDTO>(_mapper.Map <PostCategoryDTO>(result))); } catch (Exception ex) { return(new TypedResult <PostCategoryDTO>(ex)); } }