Esempio n. 1
0
        public ActionResult Edit(EditPublicationModel model, int id, HttpPostedFileBase PubDoc)
        {
            var publicatinonCard = Db.PublicationCards.Find(id);

            if (ModelState.IsValid)
            {
                if (publicatinonCard != null)
                {
                    publicatinonCard.Name        = model.Name;
                    publicatinonCard.Author      = model.Author;
                    publicatinonCard.RealeseDate = model.RealeseDate;
                    // Rubric не работает
                    publicatinonCard.Rubric     = Db.Rubrics.FirstOrDefault(x => x.Name == model.Rubric);
                    publicatinonCard.Annotation = model.Annotation;
                }
                Db.SaveChanges();
                // Должно быть по-другому
                if (PubDoc != null && PubDoc.ContentLength > 0)
                {
                    string fileName = "publication(" + publicatinonCard.ID + ").pdf";
                    PubDoc.SaveAs(Server.MapPath("~/Documents/" + fileName));
                }
            }
            else
            {
                return(RedirectToAction("BadRequest", "Error"));
            }
            return(View(publicatinonCard));
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] Publication pub)
        {
            if (pub == null)
            {
                return(BadRequest());
            }

            db.Publications.Add(pub);
            db.SaveChanges();
            return(Ok(pub));
        }
 public void Add(Book t)
 {
     try
     {
         _context.books.Add(t);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         _Logger.LogDebug(e.Message);
     }
 }
 public void Add(Author t)
 {
     try
     {
         _context.authors.Add(t);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         _logger.LogDebug(e.Message);
     }
 }
Esempio n. 5
0
 public ActionResult Create(PostModel model, HttpPostedFileBase PubDoc)
 {
     if (ModelState.IsValid)
     {
         using (PublicationContext db = new PublicationContext())
         {
             var publicationCard = new PublicationCard
             {
                 Name        = model.PostName,
                 Author      = model.PostAuthors,
                 RealeseDate = model.RealeseDate,
                 Rubric      = db.Rubrics.FirstOrDefault(x => x.Name == model.PostTheme),
                 Annotation  = model.Annotation,
                 Creator     = User.Identity.Name
             };
             db.PublicationCards.Add(publicationCard);
             db.SaveChanges();
             if (PubDoc != null && PubDoc.ContentLength > 0)
             {
                 string fileName = "publication(" + publicationCard.ID + ").pdf";
                 PubDoc.SaveAs(Server.MapPath("~/Documents/" + fileName));
             }
         }
     }
     else
     {
         return(RedirectToAction("BadRequest", "Error"));
     }
     return(RedirectToAction("MyPublications", "Manage"));
 }