Skip to content

Commit

Permalink
Did some work on lessons.
Browse files Browse the repository at this point in the history
  • Loading branch information
gageorsburn committed Apr 11, 2016
1 parent a15b979 commit 2d4f223
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 84 deletions.
4 changes: 3 additions & 1 deletion App_Code/Models/Lesson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Lesson
public string Title { get; set; }
public string Content { get; set; }

public Course Course;
public Course Course { get; set; }

public virtual ICollection<LessonAttachment> LessonAttachments { get; set; }
}
}
19 changes: 19 additions & 0 deletions App_Code/Models/LessonAttachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Enlighten.Models
{
public class LessonAttachment
{
public int Id { get; set; }

public string Title { get; set; }
public string FileType { get; set; }

public byte[] Data { get; set; }

public Lesson Lesson { get; set; }
}
}
1 change: 1 addition & 0 deletions App_Data/File.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is just a simple text file.
144 changes: 95 additions & 49 deletions Course.aspx
Original file line number Diff line number Diff line change
@@ -1,32 +1,77 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Course.aspx.cs" Inherits="Course" %>

<asp:Content ID="Header" ContentPlaceHolderID="HeaderContent" Runat="Server">
<asp:Content ID="Header" ContentPlaceHolderID="HeaderContent" runat="Server">
</asp:Content>

<asp:Content ID="Content" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="Server">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header" runat="server">
<%= course.Title %>
<small>
<asp:Label ID="ActivePanelLabel" runat="server" Text="Label"></asp:Label></small>
</h1>
<ol class="breadcrumb">
<li class="active"><asp:LinkButton ID="HomeHyperLink" runat="server" OnClick="HomeHyperLink_Click">Course Home</asp:LinkButton></li>
<li><asp:LinkButton ID="LessonHyperLink" runat="server" OnClick="LessonHyperLink_Click">Lessons</asp:LinkButton></li>
<li><asp:LinkButton ID="AssignmentHyperLink" runat="server" OnClick="AssignmentHyperLink_Click">Assignments</asp:LinkButton></li>
<li><asp:LinkButton ID="GradeHyperLink" runat="server" OnClick="GradeHyperLink_Click">Grades</asp:LinkButton></li>
<li><asp:LinkButton ID="ClassListHyperLink" runat="server" OnClick="ClassListHyperLink_Click">Class List</asp:LinkButton></li>
</ol>
</div>
<div class="col-lg-12">
<h1 class="page-header" runat="server">
<%= course.Title %>
<small>
<asp:Label ID="ActivePanelLabel" runat="server" Text="Label"></asp:Label></small>
</h1>
<ol class="breadcrumb">
<li class="active">
<asp:LinkButton ID="HomeHyperLink" runat="server" OnClick="HomeHyperLink_Click">Course Home</asp:LinkButton></li>
<li>
<asp:LinkButton ID="LessonHyperLink" runat="server" OnClick="LessonHyperLink_Click">Lessons</asp:LinkButton></li>
<li>
<asp:LinkButton ID="AssignmentHyperLink" runat="server" OnClick="AssignmentHyperLink_Click">Assignments</asp:LinkButton></li>
<li>
<asp:LinkButton ID="GradeHyperLink" runat="server" OnClick="GradeHyperLink_Click">Grades</asp:LinkButton></li>
<li>
<asp:LinkButton ID="ClassListHyperLink" runat="server" OnClick="ClassListHyperLink_Click">Class List</asp:LinkButton></li>
</ol>
</div>
</div>

<asp:Panel ID="HomePanel" runat="server">
Home
</asp:Panel>

<asp:Panel ID="LessonPanel" runat="server">
Lesson
<div class="row">
<div class="col-md-3">
<div class="list-group">
<asp:Repeater ID="LessonRepeater" ItemType="Enlighten.Models.Lesson" SelectMethod="LessonRepeater_GetData" OnItemCommand="LessonRepeater_ItemCommand" runat="server">
<ItemTemplate>
<asp:LinkButton CommandArgument="<%# Item.Id %>" CssClass="list-group-item" runat="server"><%# Item.Title %></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>

<div class="col-md-9 ">
<% if (LessonTitleLabel.Text != string.Empty)
{ %>
<div class="panel panel-default">
<div class="panel-heading text-center">
<h2>
<asp:Label ID="LessonTitleLabel" runat="server" Text=""></asp:Label>
</h2>
</div>
<div class="panel-body">
<p>
<asp:Label ID="LessonContentLabel" runat="server" Text=""></asp:Label>
</p>
</div>
<div class="panel-footer">
<h4>Attachments</h4>
<asp:Repeater ID="LessonAttachmentRepeater" ItemType="Enlighten.Models.LessonAttachment" SelectMethod="LessonAttachmentRepeater_GetData" OnItemCommand="LessonAttachmentRepeater_ItemCommand" runat="server">
<ItemTemplate>
<i class="fa fa-file"></i> &nbsp;
<asp:LinkButton CommandArgument="<%# Item.Id %>" ID="LinkButton1" runat="server"><%# Item.Title %></asp:LinkButton>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
</div>
</div>
<%} %>
</div>
</div>
</asp:Panel>

<asp:Panel ID="AssignmentPanel" runat="server">
Expand All @@ -39,62 +84,63 @@

<asp:Panel ID="ClassListPanel" runat="server">
<div class="row">
<div class="col-md-offset-3 col-md-3 text-center">
<div class="thumbnail">
<%= GetProfessor().Picture == null ?
<div class="col-md-offset-3 col-md-3 text-center">
<div class="thumbnail">
<%= GetProfessor().Picture == null ?
new HtmlString(@"<span class='fa-stack fa-lg fa-5x'>
<i class='fa fa-square fa-stack-2x'></i>
<i class='fa fa-user fa-stack-1x fa-inverse'></i>
</span>") : new HtmlString("<img style='width:130px;height:140px;padding-top:10px;border-radius: 25px;' src='"+ GetPictureUrl(GetProfessor()) +"' />")%>
<div class="caption">
<h4><%= string.Format("{0} {1}", GetProfessor().FirstName, GetProfessor().LastName) %> <br />
<small><%= GetProfessor().Email %></small>
</h4>
<p>Professor</p>
</div>
<div class="caption">
<h4><%= string.Format("{0} {1}", GetProfessor().FirstName, GetProfessor().LastName) %>
<br />
<small><%= GetProfessor().Email %></small>
</h4>
<p>Professor</p>
</div>
</div>
</div>

<div class="col-md-3 text-center">
<div class="thumbnail">
<%= GetAssistant().Picture == null ?
<div class="col-md-3 text-center">
<div class="thumbnail">
<%= GetAssistant().Picture == null ?
new HtmlString(@"<span class='fa-stack fa-lg fa-5x'>
<i class='fa fa-square fa-stack-2x'></i>
<i class='fa fa-user fa-stack-1x fa-inverse'></i>
</span>") : new HtmlString("<img style='width:130px;height:140px;padding-top:10px;border-radius: 25px;' src='"+ GetPictureUrl(GetAssistant()) +"' />")%>
<div class="caption">
<h4> <%= string.Format("{0} {1}", GetAssistant().FirstName, GetAssistant().LastName) %><br>
<small><%= GetAssistant().Email %></small>
</h4>
<p>Assistant</p>
</div>
<div class="caption">
<h4><%= string.Format("{0} {1}", GetAssistant().FirstName, GetAssistant().LastName) %><br>
<small><%= GetAssistant().Email %></small>
</h4>
<p>Assistant</p>
</div>
</div>
</div>
</div>
<hr />
<div class="row">
<asp:Repeater ID="ClassListRepeater" ItemType="Enlighten.Models.Member" SelectMethod="ClassListRepeater_GetData" runat="server">
<ItemTemplate>
<div class="col-md-3 text-center">
<div class="thumbnail">
<%# Item.Picture == null ?
<asp:Repeater ID="ClassListRepeater" ItemType="Enlighten.Models.Member" SelectMethod="ClassListRepeater_GetData" runat="server">
<ItemTemplate>
<div class="col-md-3 text-center">
<div class="thumbnail">
<%# Item.Picture == null ?
new HtmlString(@"<span class='fa-stack fa-lg fa-5x'>
<i class='fa fa-square fa-stack-2x'></i>
<i class='fa fa-user fa-stack-1x fa-inverse'></i>
</span>") : new HtmlString("<img style='width:130px;height:140px;padding-top:10px;border-radius: 25px;' src='"+ GetPictureUrl(Item) +"' />")%>


<div class="caption">
<h4><%# string.Format("{0} {1}", Item.FirstName, Item.LastName) %><br>
<small><%# Item.Email %></small>
</h4>
<p>Student</p>
<div class="caption">
<h4><%# string.Format("{0} {1}", Item.FirstName, Item.LastName) %><br>
<small><%# Item.Email %></small>
</h4>
<p>Student</p>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:Panel>
</asp:Content>

66 changes: 66 additions & 0 deletions Course.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System.Web.UI;
using System.Web.UI.WebControls;
using Enlighten.Models;
using System.IO;

public partial class Course : System.Web.UI.Page
{
public Enlighten.Models.Course course;
public Enlighten.Models.Lesson currentLesson;

protected void Page_Load(object sender, EventArgs e)
{
Expand All @@ -22,8 +24,14 @@ protected void Page_Load(object sender, EventArgs e)
Response.Redirect("~/Default.aspx");

ApplicationDbContext dbContext = new ApplicationDbContext();

course = dbContext.Courses.Where(c => c.Id == courseId).FirstOrDefault();

Member member = dbContext.Members.Where(m => m.Email == Context.User.Identity.Name).FirstOrDefault();

if (!member.Courses.Contains(course))
Response.Redirect("~/Default.aspx");

ActivePanelLabel.Text = "Course Home";

HomePanel.Visible = true;
Expand Down Expand Up @@ -118,4 +126,62 @@ public string GetPictureUrl(Member member)

return "data:image/jpg;base64," + Convert.ToBase64String(member.Picture, 0, member.Picture.Length);
}

public IEnumerable<Enlighten.Models.Lesson> LessonRepeater_GetData()
{
ApplicationDbContext dbContext = new ApplicationDbContext();

return dbContext.Courses.Where(c => c.Id == course.Id).FirstOrDefault().Lessons.Reverse();
}

protected void LessonRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ApplicationDbContext dbContext = new ApplicationDbContext();

int lessonId = int.Parse(e.CommandArgument.ToString());

Lesson lesson = dbContext.Lessons.Where(l => l.Id == lessonId).FirstOrDefault();

LessonTitleLabel.Text = lesson.Title;
LessonContentLabel.Text = lesson.Content;

currentLesson = lesson;
LessonAttachmentRepeater.DataBind();

HomePanel.Visible = false;
LessonPanel.Visible = true;
}

public IEnumerable<Enlighten.Models.LessonAttachment> LessonAttachmentRepeater_GetData()
{
ApplicationDbContext dbContext = new ApplicationDbContext();

if (currentLesson == null)
return null;

int currentLessonId = currentLesson.Id;
return dbContext.LessonAttachments.Where(l => l.Lesson.Id == currentLessonId);
}

protected void LessonAttachmentRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ApplicationDbContext dbContext = new ApplicationDbContext();

int attachmentId = int.Parse(e.CommandArgument.ToString());

LessonAttachment lessonAttachment = dbContext.LessonAttachments.Where(la => la.Id == attachmentId).FirstOrDefault();

string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + "."+ lessonAttachment.FileType;
FileInfo fileInfo = new FileInfo(fileName);

using (var stream = fileInfo.OpenWrite())
{
stream.Write(lessonAttachment.Data, 0, lessonAttachment.Data.Count());
}

Response.ContentType = lessonAttachment.FileType;
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.{1}", lessonAttachment.Title, lessonAttachment.FileType));
Response.TransmitFile(fileInfo.FullName);
Response.End();
}
}
4 changes: 3 additions & 1 deletion Default.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
&nbsp;</div>
<div class="col-md-5">
<h3><%# Item.Title %></h3>
<h4><%# GetProfessorById(Item.ProfessorId).Email %></h4>
<h4><%# Item.Location %> - <%# Item.Time %></h4>
<h5>Professor: <%# GetProfessorById(Item.ProfessorId).FullName %></h5>
<h6>E-mail: <%# GetProfessorById(Item.ProfessorId).Email %></h6>
<p><%# Item.Description %></p>
<a class="btn btn-primary" href="/Course?Id=<%# Item.Id %>">View Course</i></a>
</div>
Expand Down
Loading

0 comments on commit 2d4f223

Please sign in to comment.