/// <summary> /// This method is responsible for getting a specific timespan from the helpdesk system /// </summary> /// <param name="id">The SpanId of the specific timespan to be retrieved</param> /// <returns>The response that indicates if the operation was a success, /// and the details of the retrieved timespan if it was</returns> public GetTimeSpanResponse GetTimeSpan(int id) { s_logger.Info("Getting timespan..."); GetTimeSpanResponse response = new GetTimeSpanResponse(); try { var dataLayer = new HelpdeskDataLayer(); TimeSpanDTO timespan = dataLayer.GetTimeSpan(id); response.Timespan = timespan ?? throw new NotFoundException("Unable to find timespan!"); response.Status = HttpStatusCode.OK; } catch (NotFoundException ex) { s_logger.Error(ex, "Unable to find timespan!"); response.Status = HttpStatusCode.NotFound; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to find timespan!")); } catch (Exception ex) { s_logger.Error(ex, "Unable to get timespan!"); response.Status = HttpStatusCode.InternalServerError; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to get timespan!")); } return(response); }
/// <summary> /// Converts the timespan DTO to a DAO to interact with the database /// </summary> /// <param name="timespanDTO">The DTO for the timespan</param> /// <returns>The DAO for the timespan</returns> private Timespans timespanDTO2DAO(TimeSpanDTO timespanDTO) { Timespans timespan = new Timespans { SpanId = timespanDTO.SpanId, HelpdeskId = timespanDTO.HelpdeskId, Name = timespanDTO.Name, StartDate = timespanDTO.StartDate, EndDate = timespanDTO.EndDate }; return(timespan); }
/// <summary> /// Converts the timespan DAO to a DTO to send to the front end /// </summary> /// <param name="timespan">The DAO for the timespan</param> /// <returns>The DTO for the timespan</returns> private TimeSpanDTO timespanDAO2DTO(Timespans timespan) { TimeSpanDTO timespanDTO = new TimeSpanDTO { SpanId = timespan.SpanId, HelpdeskId = timespan.HelpdeskId, Name = timespan.Name, StartDate = timespan.StartDate, EndDate = timespan.EndDate }; return(timespanDTO); }
/// <summary> /// Used to retreve a timespan by its id /// </summary> /// <param name="id">The id of the timespan</param> /// <returns>The timespan DTO</returns> public TimeSpanDTO GetTimeSpan(int id) { TimeSpanDTO timespanDTO = null; using (helpdesksystemContext context = new helpdesksystemContext()) { var timespan = context.Timespans.FirstOrDefault(t => t.SpanId == id); if (timespan != null) { timespanDTO = timespanDAO2DTO(timespan); } } return(timespanDTO); }
/// <summary> /// This method retrieves a list of all the timespans in the database /// </summary> /// <returns>A list of timespans retrieved from the database</returns> public List <TimeSpanDTO> GetTimeSpans() { List <TimeSpanDTO> timespanDTOs = new List <TimeSpanDTO>(); using (helpdesksystemContext context = new helpdesksystemContext()) { var timespans = context.Timespans.ToList(); if (timespans.Count == 0) { throw new NotFoundException("No timespans found!"); } foreach (Timespans timespan in timespans) { if (timespan != null) { TimeSpanDTO timespanDTO = timespanDAO2DTO(timespan); timespanDTOs.Add(timespanDTO); } } } return(timespanDTOs); }