public async Task <IActionResult> CreateTicketTopic([FromBody] CreateSupportTicketTopicResource createSupportTicketTopicReource) { if (ModelState.IsValid) { if (this.ticketTopicRepository.IsTopicExist(createSupportTicketTopicReource.Name)) { ModelState.AddModelError("", $"Ticket topic with name ({createSupportTicketTopicReource.Name}) is already exist!"); return(new BadRequestObjectResult(new BadRequestResource(ModelState))); } var supportTicketTopic = this.mapper.Map <CreateSupportTicketTopicResource, SupportTicketTopic>(createSupportTicketTopicReource); var loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); this.ticketTopicRepository.CreateTicketTopic(supportTicketTopic); await this.unitOfWork.CompleteAsync(); return(new OkObjectResult(new { message = $"New ticket topic has created with name ({supportTicketTopic.Name})" })); } return(new BadRequestObjectResult(new BadRequestResource(ModelState))); }
public async Task <IActionResult> UpdateTicketTopic([FromRoute] int ticketTopicId, [FromBody] CreateSupportTicketTopicResource createSupportTicketTopicResource) { if (ModelState.IsValid) { var ticketTopic = await this.ticketTopicRepository.FindTicketTopicByIdAsync(ticketTopicId); if (ticketTopic == null) { ModelState.AddModelError("", "Ticket topic not found"); return(new NotFoundObjectResult(new NotFoundResource(ModelState))); } if (this.ticketTopicRepository.IsTopicUpdatedNameExist( createSupportTicketTopicResource.Name, ticketTopicId)) { ModelState.AddModelError("", $"Ticket topic with name ({createSupportTicketTopicResource.Name}) is already exist!"); return(new BadRequestObjectResult(new BadRequestResource(ModelState))); } this.mapper.Map <CreateSupportTicketTopicResource, SupportTicketTopic>(createSupportTicketTopicResource, ticketTopic); var loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); this.ticketTopicRepository.UpdateTicketTopic(ticketTopic); await this.unitOfWork.CompleteAsync(); return(new OkObjectResult(new { message = "Ticket topic has updated" })); } return(new BadRequestObjectResult(new BadRequestResource(ModelState))); }