public ictMedia AddNewMediaFile(string title, string desc, ref System.Web.UI.WebControls.FileUpload fu) { using (var context = new AssignmentModelEntities()) { try { var p = new ictMedia(); p.Title = title; p.Description = desc; p.MIMEType = fu.PostedFile.ContentType; p.Size = fu.PostedFile.ContentLength; p.DateCreated = DateTime.Now; p.DateModified = DateTime.Now; p.Content = fu.FileBytes; context.ictMedias.AddObject(p); context.SaveChanges(); return p; } catch (Exception ex) { return new ictMedia(); } } }
protected void Page_Load(object sender, EventArgs e) { // Special situation... if the query string isn't there, // return this page so that the students can see the code if (!Request.QueryString.HasKeys()) { return; } Response.Clear(); // Get the ItemID // For this "version 1", we will quickly check that... // 1) "id" is a query string name // 2) it is the right data type (i.e. it parses to an int) // 3) the requested ItemID exists // Later you can build in better error checking and responses // Parse the item ID, and make sure that it's the right data type // Declare an int int itemID; // Get the query string value for id as a string string idValue = Request.QueryString["id"]; if (Int32.TryParse(idValue, out itemID)) { using (var context = new AssignmentModelEntities()) { // Fetch the matching item ictMedia m = context .ictMedias .FirstOrDefault(i => i.Id == itemID); //DigitalContent dc = context.DigitalContents.FirstOrDefault(i => i.ItemID == itemID); if (m != null) { // Set the content type Response.ContentType = m.MIMEType; // Was a thumbnail requested? if (!String.IsNullOrEmpty(Request.QueryString["thumb"])) { int Length = 0; Response.OutputStream.Write(this.GenerateThumbnail(m.Content, out Length), 0, Length); } else { Response.OutputStream.Write(m.Content, 0, m.Size); } } } } else { // It's not a valid ID; fail gracefully } // Finish Response.End(); }
public bool CreateNewEditablePage(string name, string inFolder) { // This version does not permit overwrites // It could, if the UI had a check box to permit overwrite/replace // Then add a parameter to the method to handle and process it // This method depends upon the following: // editablepage.aspx in the ~/author folder // An entity named ictPage, with the properties referenced below // A "new page creator" web form, which calls this method // The web form that calls this method must have the // correctly-configured <location> block in Web.config // Clean up the arguments which were passed in name = name.Trim().ToLower(); inFolder = inFolder.Trim().ToLower(); // Check whether file "name" already exists "inFolder"... // Create new proposed folder string folder = ""; string newMarkup = ""; string newCsharp =""; //if(_app != null){ folder = string.Format("{0}\\{1}", _app.Server.MapPath("~"), inFolder); // Create new proposed file names newMarkup = Path.Combine(folder, name + ".aspx"); newCsharp = Path.Combine(folder, name + ".aspx.cs"); //} //else{ // folder = string.Format("{0}/{1}", "~/", inFolder); // Create new proposed file names // newMarkup = Path.Combine("~/", name + ".aspx"); //newCsharp = Path.Combine("~/", name + ".aspx.cs"); //} if (File.Exists(newMarkup)) { return false; } else { // Get references to the editablepage.aspx and .cs // Use the technique that you used in your Lab 3 code // to get access to the http context string markup = _app.Server.MapPath("~/author/editablepage.aspx"); string csharp = _app.Server.MapPath("~/author/editablepage.aspx.cs"); // Copy the editable page template files File.Copy(markup, newMarkup, true); File.Copy(csharp, newCsharp, true); // Open the text of the aspx page StreamReader sr = File.OpenText(newMarkup); string markupText = sr.ReadToEnd(); sr.Close(); // Change the CodeFile attribute in the Page directive to the new file name markupText = markupText.Replace("editablepage.aspx", name + ".aspx"); StreamWriter sw = File.CreateText(newMarkup); sw.Write(markupText); sw.Close(); // Create a new ictPage content item ictPage page = null; using (var context = new AssignmentModelEntities()) { page = new ictPage(); page.DateCreated = DateTime.Now; page.DateModified = DateTime.Now; page.Title = "New page - " + name; page.Content = string.Format("<h3>New page - {0}</h3><p>New Page</p>", name); context.ictPages.AddObject(page); context.SaveChanges(); } // Open the text of the C# code file sr = null; sr = File.OpenText(newCsharp); string csharpText = sr.ReadToEnd(); sr.Close(); // Change the placeholder "pageID" value csharpText = csharpText.Replace("pageID = 0", "pageID = " + page.Id.ToString()); sw = null; sw = File.CreateText(newCsharp); sw.Write(csharpText); sw.Close(); return true; } }
public List<ict_Staff> SearchStaff() { using (var context = new AssignmentModelEntities()) { return context.ict_Staff.Where(s => s.lastName == search).ToList(); } }
public void UpdatePageContentByID(int pageID, string Title, string Content) { using (var context = new AssignmentModelEntities()) { ictPage p = context.ictPages.Single(h => h.Id == pageID); p.Title = Title.Trim(); p.Content = Content.Trim(); p.DateCreated = DateTime.Now; p.DateModified = DateTime.Now; context.SaveChanges(); } }
public List<ict_ProgramOverview> GetOverview() { using (var context = new AssignmentModelEntities()) { return context.ict_ProgramOverview.ToList(); } }
public ictPage GetPageByID(int pageID) { using (var context = new AssignmentModelEntities()) { return context.ictPages.FirstOrDefault(od => od.Id == pageID); } }
public List<ict_Graduate> GetGraduatePrograms() { using (var context = new AssignmentModelEntities()) { return context.ict_Graduate.ToList(); } }
public List<ict_Diploma> GetDiplomaPrograms() { using (var context = new AssignmentModelEntities()) { return context.ict_Diploma.ToList(); } }
public List<ict_Degree> GetDegreePrograms() { using (var context = new AssignmentModelEntities()) { return context.ict_Degree.ToList(); } }
public List<ict_Student> GetALLStudents() { using (var context = new AssignmentModelEntities()) { return context.ict_Student.ToList(); } }
public List<ictMedia> GetAllMedia() { using (var context = new AssignmentModelEntities()) { return context.ictMedias.ToList(); } }