public IQueryable <Category> GetCategories() { var _db = new CloudData.Models.FileContext(); IQueryable <Category> query = _db.Categories; return(query); }
protected void RemoveFileButton_Click(object sender, EventArgs e) { using (var _db = new CloudData.Models.FileContext()) { Guid fileId = Guid.Parse(Request.QueryString["FileId"]); var myFile = (from c in _db.Files where c.FileID == fileId select c).FirstOrDefault(); if (myFile != null) { string path = HostingEnvironment.MapPath("~/User/Files/" + myFile.OwnerName + "/"); System.IO.File.Delete(path + myFile.FileName); _db.Files.Remove(myFile); _db.SaveChanges(); // Reload the page. string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); Response.Redirect(pageUrl + "?FileAction=remove"); LabelRemoveStatus.Text = "File Removed."; } else { LabelRemoveStatus.Text = "Unable to locate file."; } } }
public IQueryable GetProducts() { var _db = new CloudData.Models.FileContext(); IQueryable query = _db.Files; return(query); }
public IQueryable <File> GetFiles([QueryString("id")] int?categoryId) { var _db = new CloudData.Models.FileContext(); IQueryable <File> query = _db.Files; query = query.Where(p => p.OwnerName == User.Identity.Name); if (categoryId.HasValue && categoryId > 0) { query = query.Where(p => p.CategoryID == categoryId); } return(query); }
public IQueryable <Models.File> GetFile([QueryString("fileID")] Guid?fileId) { var _db = new CloudData.Models.FileContext(); IQueryable <Models.File> query = _db.Files; if (fileId.HasValue) { query = query.Where(p => p.FileID == fileId); } else { query = null; } return(query); }
protected void DownloadFileButton_Click(object sender, EventArgs e) { Guid fileId = Guid.Parse(Request.QueryString["FileId"]); var _db = new CloudData.Models.FileContext(); var myItem = (from c in _db.Files where c.FileID == fileId select c).FirstOrDefault(); string serverFilename = myItem.FileName; string filename = myItem.OriginalFileName; string folder = myItem.OwnerName; string path = HostingEnvironment.MapPath("~/User/Files/" + folder + "/" + serverFilename); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=" + filename); //Response.ContentType = "image/png"; Response.TransmitFile(path); Response.End(); }