// GET: /Paper/Create
 public ActionResult Create(int? id)
 {
     int conferenceId = id.GetValueOrDefault();
     Paper exist = db.Papers.FirstOrDefault(u => u.ConferenceId == conferenceId);
     if (exist == null)
     {
         var paper = new Paper();
         paper.ConferenceId = conferenceId;
         paper.UserId = (int)Session["sessionLoggedInUserId"];
         paper.AbstractSubmissionDate = DateTime.Now;
         db.Papers.Add(paper);
         db.SaveChanges();
         return View(paper);
     }
     return View(exist);
 }
Пример #2
0
        public ActionResult Create([Bind(Include= "PaperTitle,AuthorList,Affiliation,Presenter,AbstractFile,Abstract,Keywords,TopicId,TotalNumberOfPages")] Paper paper)
        {
            try
            {
                int userId = (int)Session["sessionLoggedInUserId"];
                var submission = new Paper();
                submission.PaperTitle = paper.PaperTitle;
                submission.AuthorList = paper.AuthorList;
                submission.Affiliation = paper.Affiliation;
                submission.Presenter = paper.Presenter;
                submission.Abstract = paper.Abstract;
                submission.Keywords = paper.Keywords;
                submission.TopicId = paper.TopicId;
                submission.UserId = userId;
                submission.AbstractTotalNumberOfPages = paper.AbstractTotalNumberOfPages;
                submission.ConferenceId = (int)Session["ConferenceId"];
                Conference conference = db.Conferences.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
                AbstractFileFormat fileformat = db.AbstractFileFormats.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
                Paper papers = db.Papers.FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
                if(papers == null)
                {
                    submission.Prefix = conference.PaperPrefix + 1;
                }
                else
                {
                    Paper last = db.Papers.OrderByDescending(u => u.PaperId).FirstOrDefault(u => u.ConferenceId == submission.ConferenceId);
                    string[] word = last.Prefix.Split('-');
                    int paperNumber = Int32.Parse(word[1].ToString()) + 1;
                    submission.Prefix = conference.PaperPrefix + paperNumber;
                }
                string filePath = FileUrl(paper.AbstractFile, submission.Prefix);
                string wordFilePath = WordFileUrl(paper.AbstractFile, submission.Prefix);
                if (fileformat != null)
                {
                    Document doc = new Document();
                    doc.LoadFromFile(wordFilePath);
                    submission.AbstractTotalNumberOfPages = doc.PageCount;
                    int count = 0;
                    int styleName = 0;

                    foreach (Section section in doc.Sections)
                    {
                        foreach (Paragraph paragraph in section.Paragraphs)
                        {
                            paragraph.Format.LineSpacing = (float)fileformat.LineSpacing;
                            string text = paragraph.Text.ToLower();
                            if (text.Length > 0 && text.Equals("abstract"))
                            {
                                count = 1;
                            }
                            if (text.Length > 1 && count == 1)
                            {
                                ParagraphStyle style = new ParagraphStyle(doc);
                                paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
                                style.Name = styleName.ToString();
                                style.CharacterFormat.FontName = fileformat.FontName.Name;
                                style.CharacterFormat.FontSize = fileformat.FontSize;
                                doc.Styles.Add(style);
                                paragraph.ApplyStyle(style.Name);
                            }
                            styleName++;
                        }
                        section.PageSetup.Margins.Top = (float)fileformat.Margin_Top;
                        section.PageSetup.Margins.Bottom = (float)fileformat.Margin_Bottom;
                        section.PageSetup.Margins.Left = (float)fileformat.Margin_Left;
                        section.PageSetup.Margins.Right = (float)fileformat.Margin_Right;
                    }
                    doc.SaveToFile(wordFilePath);
                }
                submission.AbstractSubmissionDate = DateTime.Now.ToString();
                submission.AbstractFile = filePath;
                db.Papers.Add(submission);
                db.SaveChanges();
                return RedirectToAction("Index", new { id = submission.UserId });
            }
            catch
            {
                ViewBag.ConferenceId = new SelectList(db.Conferences, "ConferenceId", "Username");
                ViewBag.TopicId = new SelectList(db.Topics, "TopicId", "Name");
                ViewBag.UserId = new SelectList(db.Users, "UserId", "Email");
                return View(paper);
            }
        }