/// <summary> /// Adds a complaint to an existing feed /// </summary> /// <param name="feedId"></param> /// <param name="complaint"></param> /// <returns></returns> public async Task <Response <ComplaintResponseDTO> > AddComplaint(string feedId, AddComplaintDTO complaint) { var response = new Response <ComplaintResponseDTO>(); var feed = await _feedRepo.GetById(feedId); //ends the process if the feed cannot be found if (feed == null) { response.Message = "Feed not found"; response.Success = false; return(response); } //map values of the DTO to the actual object var newComplaint = ComplaintMapper.FromAddComplaintDTO(complaint); //updates the feedId in the categoryId property newComplaint.CategoryId = feedId; var result = await _complaintsRepo.Add(newComplaint); response.Success = result; response.Message = !response.Success ? "Error occured while updating your entry" : "Updated successfully"; response.Data = ComplaintMapper.ToComplaintResponseDTO(newComplaint); //returns the complaint added and the related field return(response); }
public HttpResponseMessage Delete(int feedId) { try { var item = _repository.GetById(feedId); _repository.Delete(item); return(Request.CreateResponse(System.Net.HttpStatusCode.NoContent)); } catch (System.Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <Response <ReturnedFeedDTO> > RetrieveFeedById(string id) { var response = new Response <ReturnedFeedDTO>(); var feed = await _feedRepo.GetById(id); if (feed is null) { response.Message = "Invalid feed id provided"; return(response); } var data = FeedMapper.ToFeedDTO(feed); if (data is null) { response.Message = "Problem loading feed"; return(response); } response.Success = true; response.Message = "Feed details by id provided"; response.Data = data; return(response); }