public ActionResult Stream(string cid, string post, List <HttpPostedFileBase> fileUploaded)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Login"));
            }

            List <DB_Project.Models.File> allFiles = null;

            if (fileUploaded[0] != null)
            {
                allFiles = new List <DB_Project.Models.File>();

                string temp1 = Server.MapPath("~/Files/" + cid);
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }
                temp1 = Server.MapPath("~/Files/" + cid + "/posts");
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }

                foreach (HttpPostedFileBase f in fileUploaded)
                {
                    string fileName    = Path.GetFileName(f.FileName);
                    string savePath    = Server.MapPath("~/Files/" + cid + "/posts/");
                    string pathToCheck = savePath + fileName;
                    string temp        = null;
                    int    count       = 1;

                    while (System.IO.File.Exists(pathToCheck))
                    {
                        temp        = count.ToString() + fileName;
                        pathToCheck = savePath + temp;
                        count++;
                    }

                    f.SaveAs(pathToCheck);

                    DB_Project.Models.File f1 = new DB_Project.Models.File();
                    f1.filePath = pathToCheck;
                    f1.fileName = fileName;
                    allFiles.Add(f1);
                }
            }

            CRUD.addPost(Int32.Parse(cid), (int)Session["id"], post, allFiles);

            return(RedirectToAction("Stream", new { class1 = Int32.Parse(cid) }));
        }
        public ActionResult AssignSub(string class1, string aid, List <HttpPostedFileBase> files)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Login"));
            }

            if (CRUD.checkStudent(Int32.Parse(class1), (int)Session["id"]) == 0)
            {
                return(RedirectToAction("ClassSelect"));
            }

            List <DB_Project.Models.File> allFiles = null;

            if (files[0] != null)
            {
                allFiles = new List <DB_Project.Models.File>();

                string temp1 = Server.MapPath("~/Files/" + class1);
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }
                temp1 = Server.MapPath("~/Files/" + class1 + "/assignmentsSub");
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }
                temp1 = Server.MapPath("~/Files/" + class1 + "/assignmentsSub" + "/" + aid);
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }
                temp1 = Server.MapPath("~/Files/" + class1 + "/assignmentsSub" + "/" + aid + "/" + Session["id"].ToString());
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }

                foreach (HttpPostedFileBase f in files)
                {
                    string fileName    = Path.GetFileName(f.FileName);
                    string savePath    = Server.MapPath("~/Files/" + class1 + "/assignmentsSub" + "/" + aid + "/" + Session["id"].ToString() + "/");
                    string pathToCheck = savePath + fileName;
                    string temp        = null;
                    int    count       = 1;

                    while (System.IO.File.Exists(pathToCheck))
                    {
                        temp        = count.ToString() + fileName;
                        pathToCheck = savePath + temp;
                        count++;
                    }

                    f.SaveAs(pathToCheck);

                    DB_Project.Models.File f1 = new DB_Project.Models.File();
                    f1.filePath = pathToCheck;
                    f1.fileName = fileName;
                    allFiles.Add(f1);
                }
            }

            CRUD.submitAssignment(Int32.Parse(aid), (int)Session["id"], allFiles);

            return(RedirectToAction("AssignSub", new { class1 = class1, aid = aid }));
        }
        public ActionResult AddLecture(string id, string title, string note, List <HttpPostedFileBase> files)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Login"));
            }

            if (CRUD.checkTeacher(Int32.Parse(id), Int32.Parse(Session["id"].ToString())) != 1)
            {
                return(RedirectToAction("Classwork", new { class1 = id }));
            }

            List <DB_Project.Models.File> allFiles = null;

            if (files[0] != null)
            {
                allFiles = new List <DB_Project.Models.File>();

                string temp1 = Server.MapPath("~/Files/" + id);
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }
                temp1 = Server.MapPath("~/Files/" + id + "/lectures");
                if (System.IO.File.Exists(temp1) == false)
                {
                    Directory.CreateDirectory(temp1);
                }

                foreach (HttpPostedFileBase f in files)
                {
                    string fileName    = Path.GetFileName(f.FileName);
                    string savePath    = Server.MapPath("~/Files/" + id + "/lectures/");
                    string pathToCheck = savePath + fileName;
                    string temp        = null;
                    int    count       = 1;

                    while (System.IO.File.Exists(pathToCheck))
                    {
                        temp        = count.ToString() + fileName;
                        pathToCheck = savePath + temp;
                        count++;
                    }

                    f.SaveAs(pathToCheck);

                    DB_Project.Models.File f1 = new DB_Project.Models.File();
                    f1.filePath = pathToCheck;
                    f1.fileName = fileName;
                    allFiles.Add(f1);
                }
            }

            Assignment l = new Assignment();

            l.files = allFiles;
            l.title = title;
            l.notes = note;

            CRUD.addLecture(Int32.Parse(id), l);

            return(RedirectToAction("Classwork", new { class1 = id }));
        }