/// <summary>
        /// This method is used to get all topics of a specific unit
        /// </summary>
        /// <param name="id">ID of the unit to get topics from</param>
        /// <returns>Response which indicates success or failure</returns>
        public GetTopicsByUnitIDResponse GetTopicsByUnitID(int id)
        {
            var response = new GetTopicsByUnitIDResponse();

            try
            {
                var             dataLayer = new TopicsDataLayer();
                List <TopicDTO> topics    = dataLayer.GetTopicsByUnitID(id);

                if (topics.Count == 0)
                {
                    throw new NotFoundException("No topics found under unit " + id);
                }

                response.Topics = topics;
                response.Status = HttpStatusCode.OK;
            }
            catch (NotFoundException ex)
            {
                s_logger.Error(ex, "No unit found found matching id " + id);
                response.Status = HttpStatusCode.NotFound;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "No topics found!"));
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to get topics!");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to get topics!"));
            }
            return(response);
        }
Ejemplo n.º 2
0
        /// <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);
        }