public ActionResult Delete(int id)
        {
            ContentAssign ctas = db.ContentAssigns.Find(id);
            Content       ct   = db.Contents.Find(id);

            return(View(ct));
        }
        public ActionResult ehee([Bind(Include = "TopicID,CommentA,CTID,MCID,StatusID,CTassignID")] ContentAssign contentAssign, int id)
        {
            contentAssign.CTassignID = contentAssign.CTassignID;
            ViewBag.StatusID         = new SelectList(db.Status, "StatusID", "GiveStatus");

            var tpid = (from tp in db.Topics join t in db.ContentAssigns on tp.TopicID equals t.TopicID where t.CTassignID == id select new { Name = tp.TopicID }).FirstOrDefault();

            contentAssign.TopicID = tpid.Name;

            var cid = (from c in db.Contents join t in db.ContentAssigns on c.CTID equals t.CTID where t.CTassignID == id select new { ID = c.CTID }).FirstOrDefault();

            contentAssign.CTID = cid.ID;

            var m = (from s in db.MarketingCoordinators
                     where s.UserName.Equals(User.Identity.Name)
                     select s).FirstOrDefault();

            contentAssign.MCID = m.MCID;
            if (ModelState.IsValid)
            {
                db.Entry(contentAssign).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contentAssign));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Content       ct   = db.Contents.Find(id);
            ContentAssign ctas = db.ContentAssigns.Find(id);

            db.ContentAssigns.Remove(ctas);
            db.Contents.Remove(ct);
            db.SaveChanges();
            return(RedirectToAction("Uploaded"));
        }
        public ActionResult DeleteConfirmed(int?id)
        {
            ContentAssign contentAssign = db.ContentAssigns.Find(id);
            Content       ct            = db.Contents.Find(id);

            db.Contents.Remove(ct);
            db.ContentAssigns.Remove(contentAssign);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContentAssign contentAssign = db.ContentAssigns.Find(id);
            Content       ct            = db.Contents.Find(id);

            if (contentAssign == null)
            {
                return(HttpNotFound());
            }
            return(View(contentAssign));
        }
        public ActionResult Details(int?id)
        {
            ViewBag.Comments = (from c in db.Comments where c.CTassignID == id select c).ToList();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContentAssign contentAssign = db.ContentAssigns.Find(id);

            if (contentAssign == null)
            {
                return(HttpNotFound());
            }
            return(View(contentAssign));
        }
        public ActionResult ehee(int?id)
        {
            var tpid = (from tp in db.Topics join t in db.ContentAssigns on tp.TopicID equals t.TopicID where t.CTassignID == id select new { Name = tp.TopicName }).FirstOrDefault();

            ViewBag.TName    = tpid.Name;
            ViewBag.StatusID = new SelectList(db.Status, "StatusID", "GiveStatus");

            var cid = (from c in db.Contents join t in db.ContentAssigns on c.CTID equals t.CTID where t.CTassignID == id select new { Name = c.CTName }).FirstOrDefault();

            ViewBag.CName = cid.Name;

            var m = (from s in db.MarketingCoordinators
                     where s.UserName.Equals(User.Identity.Name)
                     select s).FirstOrDefault();

            ViewBag.MCName = m.MCName; //LINQ+ ENtityframework

            ContentAssign contentAssign = db.ContentAssigns.Find(id);

            return(View(contentAssign));
        }
        public ActionResult Create(Content ct, HttpPostedFileBase postedImg, HttpPostedFileBase postedPDF, string id, ContentAssign contentAssign)
        {
            var student = (from s in db.Students
                           where s.UserName.Equals(User.Identity.Name)
                           select s).FirstOrDefault();

            ct.StudentID = student.StudentID; //LINQ+ ENtityframework


            var tpid = (from t in db.Topics
                        where t.TopicID == id
                        select t).FirstOrDefault();

            ct.FacultyID = tpid.FacultyID;

            byte[] bytes;
            byte[] byte2s;
            using (BinaryReader br = new BinaryReader(postedImg.InputStream))
            {
                bytes = br.ReadBytes(postedImg.ContentLength);
            }
            using (BinaryReader br2 = new BinaryReader(postedPDF.InputStream))
            {
                byte2s = br2.ReadBytes(postedPDF.ContentLength);
            }

            if (DateTime.Now < tpid.EndDate)
            {
                db.Contents.Add(new Content
                {
                    Name2         = Path.GetFileName(postedImg.FileName),
                    ContentType2  = postedImg.ContentType,
                    Data2         = bytes,
                    CTName        = ct.CTName,
                    CTDescription = ct.CTDescription,
                    FacultyID     = ct.FacultyID,
                    StudentID     = ct.StudentID,
                    Name          = Path.GetFileName(postedPDF.FileName),
                    ContentType   = postedPDF.ContentType,
                    Data          = byte2s,
                    TopicID       = id
                });

                var mcmail = (from m in db.MarketingCoordinators where m.FacultyID == ct.FacultyID select m.MCEmail).FirstOrDefault();
                var mcid   = (from m in db.MarketingCoordinators where m.FacultyID == ct.FacultyID select m.MCID).FirstOrDefault();
                using (MailMessage mm = new MailMessage("*****@*****.**", mcmail))
                {
                    //ct.To = ViewBag.McMail;
                    mm.Subject    = "Grade content";
                    mm.Body       = "You have a new content from student: " + student.StudentName + "--- Stduent ID: " + student.StudentID;
                    mm.IsBodyHtml = false;
                    using (SmtpClient smtp = new SmtpClient())
                    {
                        smtp.Host      = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "tsuna2000");
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials           = NetworkCred;
                        smtp.Port = 587;
                        smtp.Send(mm);
                        ViewBag.Message = "Email sent.";
                    }


                    db.ContentAssigns.Add(new ContentAssign
                    {
                        CTID    = ct.CTID,
                        TopicID = id,
                        MCID    = mcid
                    });
                }
            }
            else
            {
                TempData["message"] = "this topic is expired, Try another or wait for the next topic  ";
                return(View());
            }
            db.SaveChanges();
            return(RedirectToAction("Uploaded"));
        }