public ActionResult Topic(TopicElements topicElements)
 {
     db.Texts.Add(topicElements.Text);
     db.Theorems.Add(topicElements.Theorem);
     db.SaveChanges();
     return(Redirect("/Home/Topic/" + topicElements.Text.TopicId));
 }
 public ActionResult Add(TopicElements topicElem, HttpPostedFileBase image)
 {
     if (topicElem.Text != null)
     {
         db.Texts.Add(topicElem.Text);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Theorem != null)
     {
         db.Theorems.Add(topicElem.Theorem);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Axiom != null)
     {
         db.Axioms.Add(topicElem.Axiom);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Lemma != null)
     {
         db.Lemmes.Add(topicElem.Lemma);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Professor != null)
     {
         db.Professors.Add(topicElem.Professor);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Formula != null)
     {
         if (image != null)
         {
             topicElem.Formula.ImageMimeType = image.ContentType;
             topicElem.Formula.ImageData     = new byte[image.ContentLength];
             image.InputStream.Read(topicElem.Formula.ImageData, 0, image.ContentLength);
         }
         db.Formuls.Add(topicElem.Formula);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     if (topicElem.Task != null)
     {
         if (image != null)
         {
             topicElem.Task.ImageMimeType = image.ContentType;
             topicElem.Task.ImageData     = new byte[image.ContentLength];
             image.InputStream.Read(topicElem.Task.ImageData, 0, image.ContentLength);
         }
         db.Tasks.Add(topicElem.Task);
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     return(Redirect("/Home/Topic/" + topicElem.TopicId));
 }
 public ActionResult Edit(TopicElements topicElem, HttpPostedFileBase image)
 {
     if (topicElem.Text != null)
     {
         db.Entry(topicElem.Text).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Text.TopicId));
     }
     if (topicElem.Theorem != null)
     {
         db.Entry(topicElem.Theorem).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Theorem.TopicId));
     }
     if (topicElem.Axiom != null)
     {
         db.Entry(topicElem.Axiom).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Axiom.TopicId));
     }
     if (topicElem.Lemma != null)
     {
         db.Entry(topicElem.Lemma).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Lemma.TopicId));
     }
     if (topicElem.Professor != null)
     {
         db.Entry(topicElem.Professor).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Professor.TopicId));
     }
     if (topicElem.Formula != null)
     {
         if (image != null)
         {
             topicElem.Formula.ImageMimeType = image.ContentType;
             topicElem.Formula.ImageData     = new byte[image.ContentLength];
             image.InputStream.Read(topicElem.Formula.ImageData, 0, image.ContentLength);
         }
         db.Entry(topicElem.Formula).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.Formula.TopicId));
     }
     if (topicElem.Task != null)
     {
         if (image != null)
         {
             topicElem.Task.ImageMimeType = image.ContentType;
             topicElem.Task.ImageData     = new byte[image.ContentLength];
             image.InputStream.Read(topicElem.Task.ImageData, 0, image.ContentLength);
         }
         db.Entry(topicElem.Task).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect("/Home/Topic/" + topicElem.TopicId));
     }
     return(Redirect("/Home/Topic/" + topicElem.TopicId));
 }
        public ActionResult Edit(int?id, string h)
        {
            TopicElements topicElem = new TopicElements();

            ViewBag.Temp = h;
            if (h == "text")
            {
                Text text = db.Texts.Find(id);
                topicElem.Text = text;
                return(View(topicElem));
            }
            if (h == "theor")
            {
                return(View(topicElem));
            }
            if (h == "axiom")
            {
                return(View(topicElem));
            }
            if (h == "lemma")
            {
                return(View(topicElem));
            }
            if (h == "sinc")
            {
                return(View(topicElem));
            }
            if (h == "form")
            {
                return(View(topicElem));
            }
            if (h == "task")
            {
                return(View(topicElem));
            }
            return(HttpNotFound());
        }
        public ActionResult Add(int?id, string h)
        {
            Topic topic = db.Topics.Find(id);

            ViewBag.Url = "/Home/Topic/" + id;
            IQueryable <int> custQuery =
                (from ax in db.Axioms
                 where ax.TopicId == id
                 select ax.Layout)
                .Concat
                    (from ther in db.Theorems
                    where ther.TopicId == id
                    select ther.Layout)
                .Concat
                    (from text in db.Texts
                    where text.TopicId == id
                    select text.Layout)
                .Concat
                    (from form in db.Formuls
                    where form.TopicId == id
                    select form.Layout)
                .Concat
                    (from lemm in db.Lemmes
                    where lemm.TopicId == id
                    select lemm.Layout)
                .Concat
                    (from prof in db.Professors
                    where prof.TopicId == id
                    select prof.Layout);

            if (custQuery.Count() != 0)
            {
                ViewBag.Layout = custQuery.Max() + 1;
            }
            else
            {
                ViewBag.Layout = 0 + 1;
            }
            TopicElements topicElem = new TopicElements();

            ViewBag.Temp    = h;
            topicElem.Topic = topic;
            if (h == "text")
            {
                return(View("Add", topicElem));
            }
            if (h == "theor")
            {
                return(View("Add", topicElem));
            }
            if (h == "axiom")
            {
                return(View("Add", topicElem));
            }
            if (h == "lemma")
            {
                return(View("Add", topicElem));
            }
            if (h == "sinc")
            {
                return(View("Add", topicElem));
            }
            if (h == "form")
            {
                return(View("Add", topicElem));
            }
            if (h == "task")
            {
                return(View("Add", topicElem));
            }
            return(HttpNotFound());
        }