/// <summary> /// This method is used to update an existing item in the queue /// </summary> /// <param name="id">ID of the queue item to be updated</param> /// <param name="request">Request that contains the new queue item information</param> /// <returns>Response which indicates success or failure</returns> public UpdateQueueItemResponse UpdateQueueItem(int id, UpdateQueueItemRequest request) { UpdateQueueItemResponse response = new UpdateQueueItemResponse(); try { response = (UpdateQueueItemResponse)request.CheckValidation(response); if (response.Status == HttpStatusCode.BadRequest) { return(response); } QueueDataLayer dataLayer = new QueueDataLayer(); response.Result = dataLayer.UpdateQueueItem(id, request); response.Status = HttpStatusCode.OK; } catch (NotFoundException ex) { s_logger.Warn(ex, "Unable to update queue item"); response.Status = HttpStatusCode.NotFound; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to update queue item")); } catch (Exception ex) { s_logger.Error(ex, "Unable to update queue item"); response.Status = HttpStatusCode.InternalServerError; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to update queue item")); } return(response); }
/// <summary> /// This method gets all the queue items in a specific helpdesk /// </summary> /// <param name="id">The id of the helpdesk</param> /// <returns>Response which indicates success or failure</returns> public GetQueueItemsByHelpdeskIDResponse GetQueueItemsByHelpdeskID(int id) { s_logger.Info("Getting queue items by helpdesk id..."); GetQueueItemsByHelpdeskIDResponse response = new GetQueueItemsByHelpdeskIDResponse(); try { var dataLayer = new QueueDataLayer(); List <QueueItemDTO> queueItems = dataLayer.GetQueueItemsByHelpdeskID(id); if (queueItems.Count == 0) { throw new NotFoundException("No queue items found under helpdesk " + id); } response.QueueItems = queueItems; response.Status = HttpStatusCode.OK; } catch (NotFoundException ex) { s_logger.Error(ex, "No queue items found!"); response.Status = HttpStatusCode.NotFound; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "No queue items found!")); } catch (Exception ex) { s_logger.Error(ex, "Unable to get queue items!"); response.Status = HttpStatusCode.InternalServerError; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to get queue items!")); } return(response); }
/// <summary> /// This method is used to add an item to a queue /// </summary> /// <param name="request">The information of the queue item</param> /// <returns>Response which indicates success or failure</returns> public AddToQueueResponse AddToQueue(AddToQueueRequest request) { AddToQueueResponse response = new AddToQueueResponse(); try { response = (AddToQueueResponse)request.CheckValidation(response); if (response.Status == HttpStatusCode.BadRequest) { return(response); } StudentFacade studentFacade = new StudentFacade(); if (!request.StudentID.HasValue) { var addResponse = studentFacade.AddStudentNickname(new AddStudentRequest() { Nickname = request.Nickname, SID = request.SID }); if (addResponse.Status != HttpStatusCode.OK) { response.Status = addResponse.Status; response.StatusMessages = addResponse.StatusMessages; return(response); } request.StudentID = addResponse.StudentID; } QueueDataLayer dataLayer = new QueueDataLayer(); int itemId = dataLayer.AddToQueue(request); response.ItemId = itemId; response.Status = HttpStatusCode.OK; } catch (NotFoundException ex) { s_logger.Warn(ex, "Unable to add queue item"); response.Status = HttpStatusCode.NotFound; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to add queue item")); } catch (Exception ex) { s_logger.Error(ex, "Unable to add queue item"); response.Status = HttpStatusCode.InternalServerError; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to add queue item")); } return(response); }
/// <summary> /// This method is used to check a check in item out of the helpdesk system /// </summary> /// <param name="id">Specified CheckInID</param> /// <returns>A response indicating success or failure</returns> public CheckOutResponse CheckOut(CheckOutRequest request, int id) { CheckOutResponse response = new CheckOutResponse(); try { CheckInDataLayer dataLayer = new CheckInDataLayer(); bool result = dataLayer.CheckOut(request, id); if (result == false) { throw new NotFoundException("Unable to find check in item!"); } QueueDataLayer queueDataLayer = new QueueDataLayer(); var queueItems = queueDataLayer.GetQueueItemsByCheckIn(id); UpdateQueueItemStatusRequest removeRequest = new UpdateQueueItemStatusRequest() { TimeRemoved = DateTime.Now }; foreach (var item in queueItems) { queueDataLayer.UpdateQueueItemStatus(item.ItemId, removeRequest); } response.Result = result; response.Status = HttpStatusCode.OK; } catch (NotFoundException ex) { s_logger.Warn(ex, "Unable to find check out item"); response.Status = HttpStatusCode.NotFound; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to find check out item")); } catch (Exception ex) { s_logger.Error(ex, "Unable to check out"); response.Status = HttpStatusCode.InternalServerError; response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to check out")); } return(response); }
/// <summary> /// Used to get a Zip file of all of the database tables as CSVs /// </summary> public DatabaseExportResponse ExportDatabase() { var response = new DatabaseExportResponse(); try { FileProccessing proccessing = new FileProccessing(); DateTime now = DateTime.Now; string exportName = $"databaseexport_{now.ToString("yyyyddMM_HHmmss")}"; string fullZipPath = proccessing.CreateZip(_appSettings.DatabaseBackupDestination, exportName); if (string.IsNullOrEmpty(fullZipPath)) { s_logger.Error("Unable to create empty zip"); response.Status = HttpStatusCode.InternalServerError; return(response); } else { var helpdeskDataLayer = new HelpdeskDataLayer(); var unitDataLayer = new UnitsDataLayer(); var usersDataLayer = new UsersDataLayer(); var topicsDataLayer = new TopicsDataLayer(); var studentDataLayer = new StudentDatalayer(); var queueDataLayer = new QueueDataLayer(); var checkInDataLayer = new CheckInDataLayer(); DataTable helpdesks = helpdeskDataLayer.GetHelpdesksAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "helpdesks", helpdesks); DataTable timespans = helpdeskDataLayer.GetTimeSpansAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "timespans", timespans); DataTable helpdeskUnits = helpdeskDataLayer.GetHelpdeskUnitsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "helpdeskunits", helpdeskUnits); DataTable users = usersDataLayer.GetUsersAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "users", users); DataTable units = unitDataLayer.GetUnitsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "units", units); DataTable topics = topicsDataLayer.GetTopicsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "topics", topics); DataTable students = studentDataLayer.GetStudentsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "students", students); DataTable queuesItems = queueDataLayer.GetQueueItemsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "queueItems", queuesItems); DataTable checkIns = checkInDataLayer.GetCheckInsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "checkInHistory", checkIns); DataTable checkInQueueItems = checkInDataLayer.GetCheckInQueueItemsAsDataTable(); proccessing.SaveToZIPAsCSV(fullZipPath, "checkinqueueitem", checkInQueueItems); response.Path = fullZipPath; response.Status = HttpStatusCode.OK; } } catch (Exception ex) { s_logger.Error(ex, "Unable to generate database export"); response.Status = HttpStatusCode.InternalServerError; } return(response); }