Example #1
0
        public ActionResult Create([Bind(Include = "Year,Number,Active")] Issue issue)
        {
            if (ModelState.IsValid)
            {
                db.Issues.Add(issue);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(issue));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "Id,Email,RusSurname,RusInitials,RusOrgName,RusSubdivision,RusPosition,EnuSurname,EnuInitials,EnuOrgName,ScienceDegree,Phone,OrganizationKind,Postcode,PostalAddress", Exclude = "Owner")] Author author)
        {
            var userId = User.GetUserId();
            var user   = db.Users.Find(userId);

            author.Owner = user;

            this.Revalidate(author);

            if (ModelState.IsValid)
            {
                db.Authors.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = author.Id }));
            }

            return(View(author));
        }
Example #3
0
 private void SaveChanges(Issue issue)
 {
     try
     {
         _db.SaveChanges();
         Response.Redirect("~/");
     }
     catch (DbUpdateException ex)
     {
         if (!HandleDbUpdateException(ex, ModelState, issue))
         {
             throw ex;
         }
     }
 }
        public ActionResult Create([Bind(Include = "Id,Specialty,IssueYear,IssueNumber,RusArtTitles,ShortArtTitles,RusAbstract,RusKeywords,EnuArtTitles,EnuAbstract,EnuKeywords,AuthorsIds,CurrentMessageText,References,Agreed,Status,ArticleDate")] Article article)
        {
            ViewBag.Create = true;
            var isCreating = article.Id == 0;

            article.FillPrperties(db);

            if (db.Articles.Any(a => a.RusArtTitles.Equals(article.RusArtTitles, StringComparison.CurrentCultureIgnoreCase)))
            {
                var id = db.Articles.Where(a => a.RusArtTitles.Equals(article.RusArtTitles, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault()?.Id;
                ModelState.AddModelError("RusArtTitles", $"Статья (№ {id}) с таким заголовком уже существует! Если вы загружаете измененные файлы, вам надо сделать это в первой заявке.");
                return(ContinueEdit(article));
            }
            if (db.Articles.Any(a => a.ShortArtTitles.Equals(article.ShortArtTitles, StringComparison.CurrentCultureIgnoreCase)))
            {
                var id = db.Articles.Where(a => a.ShortArtTitles.Equals(article.ShortArtTitles, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault()?.Id;
                ModelState.AddModelError("ShortArtTitles", $"Статья (№ {id}) с таким кратким названием уже существует! Если вы загружаете измененные файлы, вам надо сделать это в первой заявке.");
                return(ContinueEdit(article));
            }

            if (string.IsNullOrWhiteSpace(article.AuthorsIds))
            {
                return(ContinueEdit(article));
            }

            if (Request.Files.Count != 4)
            {
                throw new ApplicationException("Invalid uploaded files count!");
            }


            article.Created = article.Modified;
            article.Owner   = User.GetApplicationUser(db);
            article.Issue   = db.Issues.Find(article.IssueYear, article.IssueNumber);

            if (article.Issue == null)
            {
                throw new ApplicationException("Незаполнен список изданий!");
            }

            DbUtils.Revalidate(this, article);
            if (ModelState.IsValid)
            {
                HttpPostedFileBase articleFile        = Request.Files[0];
                HttpPostedFileBase additionalTextFile = Request.Files[1];
                HttpPostedFileBase additionalImg1     = Request.Files[2];
                HttpPostedFileBase additionalImg2     = Request.Files[3];

                if (isCreating && articleFile.ContentLength == 0)
                {
                    ModelState.AddModelError("articleFile", "Необходимо загрузить файл содержащий текст статьи!");
                    return(ContinueEdit(article));
                }

                if (!CheckFiles(additionalImg1, additionalImg2))
                {
                    return(ContinueEdit(article));
                }

                TryAddMessage(article);

                db.Articles.Add(article);
                db.SaveChanges();

                ViewBag.Create = false;

                if (articleFile.ContentLength > 0)
                {
                    article.SeveFile(articleFile, Server.MapPath);
                }

                if (additionalTextFile.ContentLength > 0)
                {
                    article.SeveFile(additionalTextFile, Server.MapPath, Constants.ReviewTextPrefix);
                }

                article.TrySeveFiles(Server.MapPath, additionalImg1, additionalImg2, Constants.ReviewImgPrefix);

                TrySendMessage(article);

                return(RedirectToAction("Details", new { id = article.Id }));
            }

            return(ContinueEdit(article));
        }