Esempio n. 1
0
        public HttpResponseMessage GetExport([FromUri] int id, [FromUri] string delimiter)
        {
            var currentUser = CurrentUser();

            var    exportService = new ExportService(id, currentUser.Id);
            string csv           = exportService.BuildCsv(delimiter);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(csv, System.Text.Encoding.UTF8, "text/csv");
            return(response);
        }
Esempio n. 2
0
        public HttpResponseMessage Export([FromODataUri] int key, [FromODataUri] string Delimiter)
        {
            var commitId    = key;
            var currentUser = CurrentUser();

            var    exportService = new ExportService(commitId, currentUser.Id);
            string csv           = exportService.BuildCsv(Delimiter);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(csv, System.Text.Encoding.UTF8, "text/plain");
            return(response);
        }
Esempio n. 3
0
        public IHttpActionResult GetCsv(
            [FromUri] string Delimiter,
            [FromUri] int?CommitId   = null,
            [FromUri] DateTime?InAt  = null,
            [FromUri] DateTime?OutAt = null)
        {
            var currentUser = CurrentUser();

            if (CommitId.HasValue)
            {
                var commit        = db.Commits.Find(CommitId.Value);
                var exportService = new ExportService(commit.Id, currentUser.Id);

                string csv   = exportService.BuildCsv(Delimiter);
                var    bytes = Encoding.UTF8.GetBytes(csv);
                return(new FileActionResult(bytes, "text/csv",
                                            string.Format(
                                                "Locked Punches {0} thru {1}.csv",
                                                commit.InAt.ToShortDateString(),
                                                commit.OutAt.ToShortDateString()
                                                ),
                                            Request));
            }
            else if (InAt.HasValue && OutAt.HasValue)
            {
                var exportService = new ExportService(InAt.Value, OutAt.Value, currentUser.Id);

                string csv   = exportService.BuildCsv(Delimiter);
                var    bytes = Encoding.UTF8.GetBytes(csv);
                return(new FileActionResult(bytes, "text/csv",
                                            string.Format(
                                                "All Punches {0} thru {1}.csv",
                                                InAt.Value.ToShortDateString(),
                                                OutAt.Value.ToShortDateString()
                                                ),
                                            Request));
            }
            else
            {
                throw new NotAuthorizedException("Must specify a date range or commit id to export punches.");
            }
        }
Esempio n. 4
0
        public IActionResult GetCsv(
            [FromQuery] string Delimiter,
            [FromQuery] int?CommitId   = null,
            [FromQuery] DateTime?InAt  = null,
            [FromQuery] DateTime?OutAt = null)
        {
            var currentUser = CurrentUser();

            if (CommitId.HasValue)
            {
                var commit        = _context.Commits.Find(CommitId.Value);
                var exportService = new ExportService(commit.Id, currentUser.Id, _context);

                string csv   = exportService.BuildCsv(Delimiter);
                var    bytes = Encoding.UTF8.GetBytes(csv);
                return(File(bytes, "text/csv", fileDownloadName: string.Format(
                                "Locked Punches {0} thru {1}.csv",
                                commit.InAt.ToShortDateString(),
                                commit.OutAt.ToShortDateString()
                                )));
            }
            else if (InAt.HasValue && OutAt.HasValue)
            {
                var exportService = new ExportService(InAt.Value, OutAt.Value, currentUser.Id, _context);

                string csv   = exportService.BuildCsv(Delimiter);
                var    bytes = Encoding.UTF8.GetBytes(csv);
                return(File(bytes, "text/csv", fileDownloadName: string.Format(
                                "All Punches {0} thru {1}.csv",
                                InAt.Value.ToShortDateString(),
                                OutAt.Value.ToShortDateString()
                                )));
            }
            else
            {
                return(BadRequest("Must specify a date range or lock id to export punches."));
            }
        }