Esempio n. 1
0
        public ActionResult DLFile(string DlPath)
        {
            var DL = new Models.Download
            {
            Filename = DlPath,
            DownloadDate = System.DateTime.Now,
            IPAddress = HttpContext.Request.UserHostAddress
            };

            var file = new Models.File(DlPath);

            if (ModelState.IsValid)
            {
            DLTrack.Downloads.Add(DL);
            DLTrack.SaveChanges();
            }

            try
            {
            var fileData = FileDownloadInMvc3.Models.ExtensionMethods.GetFileData(file.Name, file.Path);
            return new FileDownloadResult(file.Name, fileData);
            }
            catch (FileNotFoundException)
            {
            throw new HttpException(404, string.Format("The file {0} was not found.", file));
            }
            //return View(DL);
        }
Esempio n. 2
0
        public async Task <IActionResult> PutDownload([FromRoute] int id, [FromBody] Models.Download @download)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != @download.DownloadId)
            {
                return(BadRequest());
            }

            _context.Entry(@download).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DownloadExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PostDownload([FromBody] Models.Download @download)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Downloads.Add(@download);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException ex)
            {
                if (DownloadExists(@download.DownloadId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetDownload", new { id = @download.DownloadId }, @download));
        }
        public async Task <Domain.Maybe <Download> > Add(Models.Download download)
        {
            var dl = await downloadRepository.Add(download.AppId, download.Latitude, download.Longitude, download.DownloadedAt);

            if (dl.HasValue)
            {
                await hubcontext.Clients.All.SendAsync("new-download");
            }
            return(dl);
        }