/// <summary> /// Downloads the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="System.Web.HttpException"> /// Cannot find file /// or /// Cannot find file - can't get remote link. /// </exception> public FileResult Download(int id) { Open.GI.hypermart.Models.File downloadFile = db.Files.Find(id); //write the Installation History.... InstallationHistory IH = new InstallationHistory(); IH.InstallationDate = DateTime.Now; IH.FileID = downloadFile.ID; db.InstallationHistory.Add(IH); db.SaveChanges(); //if (id == null) //{ // throw new HttpException("Cannot find file "); //} if (downloadFile == null) { throw new HttpException("Cannot find file - can't get remote link."); //return new //return new HttpStatusCodeResult(HttpStatusCode.NotFound); } //var item = ItemRepo.GetItemById(id); //string path = Path.Combine(Server.MapPath("~/App_Data/Items"), item.Path); return(File(new FileStream(downloadFile.Link, FileMode.Open), "application/octetstream", downloadFile.FileName)); }
/// <summary> /// Initializes a new instance of the <see cref="FileDTO"/> class. /// </summary> /// <param name="File">The file.</param> public FileDTO(File File ) { ID = File.ID; Link = File.Link; StorageType = File.StorageType; FileName = File.FileName; BLOB = File.BLOB; Product = File.Product; ProductID = File.ProductID; Platforms = File.Platforms; Version = File.Version; }
public FileDTO AddFile(int ProductID, Open.GI.hypermart.Models.File FileToAdd) { var AddedFile = db.Files.Add(FileToAdd); return(new FileDTO() { ID = AddedFile.ID, BLOB = AddedFile.BLOB, FileName = AddedFile.FileName, Link = AddedFile.Link, Platforms = AddedFile.Platforms, Product = AddedFile.Product, ProductID = AddedFile.ProductID, StorageType = AddedFile.StorageType, Version = AddedFile.Version }); }
/// <summary> /// Posts the product file. /// </summary> /// <param name="ProductID">The product identifier.</param> /// <param name="FileToAdd">The file to add.</param> /// <returns></returns> /// <exception cref="System.Web.Http.HttpResponseException"></exception> /// <exception cref="System.Exception">Cannot add a product file</exception> public FileDTO PostProductFile(int ProductID, Open.GI.hypermart.Models.File FileToAdd) { try { Product product = db.Products.Find(ProductID); if (product == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } FileToAdd.Product = product; var AddedFile = db.Files.Add(FileToAdd); db.SaveChanges(); return(new FileDTO(AddedFile)); } catch (Exception ex) { throw new Exception("Cannot add a product file", ex); } }
public IHttpActionResult PostFile(File file) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Files.Add(file); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = file.ID }, file); }
public IHttpActionResult PutFile(int id, File file) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != file.ID) { return BadRequest(); } db.Entry(file).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FileExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }