// add customer complaint public async Task <string> AddComlaint(AddComplaintDto complaintDto) { try { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; if (string.IsNullOrEmpty(userId)) { return("Invalid user id"); } Complaint complaint = new Complaint { UserId = userId, ComplaintDetails = complaintDto.ComplaintDetails, ComplaintTime = DateTime.Now, ComplaintType = complaintDto.ComplaintType, IsUrgent = complaintDto.IsUrgent, Status = Status.pending }; await _dbContext.AddAsync(complaint); await _dbContext.SaveChangesAsync(); return("Success"); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult <string> > AddComplaint(AddComplaintDto addComplaintDto) { try { var complaints = await _complaintService.AddComlaint(addComplaintDto); return(Ok(complaints)); } catch (UnauthorizedAccessException ex) { return(Forbid(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }