public ActionResult stepOne(StepOneViewModel model) { if (!ModelState.IsValid) { model.types = initializeTypesForStepOne(); return(View("stepone", model)); } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.Type = model.Type; article.Title = model.Title; article.Abstract = model.Abstract; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { Type = model.Type, Title = model.Title, Abstract = model.Abstract, }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("steptwo")); }
public ActionResult stepOne() { if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); StepOneViewModel model = _mapper.Map <TempArticle, StepOneViewModel>(tempArticle); if (model != null) { model.OpenAccessAgreement = true; model.PlagiarismConfirmation = true; model.DuplicateSubmissionConfirmation = true; model.types = initializeTypesForStepOne(); } return(View(model)); } StepOneViewModel modell = new StepOneViewModel() { types = initializeTypesForStepOne(), }; return(View(modell)); }
public ActionResult stepFour() { // If i change login to creat article id on begin submission then // also need to add login user in if statement as doing in else if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); if (tempArticle.AuthorsEmails == null) { tempArticle.AuthorsEmails = User.Identity.Name + "-;"; } StepFourViewModel model = _mapper.Map <TempArticle, StepFourViewModel>(tempArticle); model.AuthorsEmails = decodeStringToList(tempArticle.AuthorsEmails); model.AuthorsInstitutions = initializeUsersInstitutions(model.AuthorsEmails); return(View(model)); } else { TempArticle article = new TempArticle() { AuthorsEmails = User.Identity.Name + "-;" }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); return(RedirectToAction("stepfour")); } }
public ActionResult stepThree() { if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); StepThreeViewModel model = _mapper.Map <TempArticle, StepThreeViewModel>(tempArticle); model.AllFields = generatingData.populateFields(); model.AllSubjectCategories = generatingData.populateSubjectCategories(); model.FieldsIds = decodeStringToList(tempArticle.FieldsIds); model.SubjectCategoriesIds = decodeStringToList(tempArticle.SubjectCategoriesIds); return(View(model)); } StepThreeViewModel stepThree = new StepThreeViewModel() { AllFields = generatingData.populateFields(), AllSubjectCategories = generatingData.populateSubjectCategories() }; return(View(stepThree)); }
public ActionResult ArticleEdit(int id)//此处id表示ArticleID { HttpCookie cookie = Request.Cookies["Employer"]; if (cookie != null) { string EmployerAccount = cookie.Values["EmployerAccount"]; DataTable temparticle = TempArticle.GetTempArticleByArticleID(id, EmployerAccount); if (temparticle.Rows.Count > 0)//该文章已经被编辑过,存在于TempArticle里面 { //重定向TempArticleEdit return(RedirectToAction("TempArticleEdit", new { id = temparticle.Rows[0]["TempArticleID"] })); } else { ViewBag.flag = true; //文章是否存在的标志 DataTable article = Article.GetArticleByArticleIDAndEditorAccount(id, EmployerAccount); //得到Article表文章 if (article != null && article.Rows.Count > 0) { ViewBag.Article = article; //显示大型招聘会选项 int typeid = Convert.ToInt32(article.Rows[0]["TypeID"]); ViewBag.typename = ArticleType.GetTypeNameByTypeID(typeid); if (typeid == 1)//专场招聘 { //获取时间和地点 ViewBag.PlaceList = Article.GetPlaceListSecondById(Convert.ToInt32(article.Rows[0]["PlaceSecondID"])); ViewBag.PlaceListFirst = Article.GetPlaceListFirst(); } if (typeid == 2)//双选会 { DataTable bigarticleTable2 = Article.SelectArticleFromArticle(2, DateTime.Now); ViewBag.bigarticleTable2 = bigarticleTable2; ViewBag.BigArticleID = Article.GetBigArticleByArticleID(Convert.ToInt32(article.Rows[0]["ArticleID"])); } else if (typeid == 3)//组团招聘 { DataTable bigarticleTable3 = Article.SelectArticleFromArticle(3, DateTime.Now); ViewBag.bigarticleTable3 = bigarticleTable3; ViewBag.BigArticleID = Article.GetBigArticleByArticleID(Convert.ToInt32(article.Rows[0]["ArticleID"])); } //其他类型的文章不用管 //需求部分 ViewBag.DemandInfos = DemandInfo.GetDemandInfoByArticleID(id); } else { ViewBag.flag = false; } //文章不存在 } } else { ViewBag.flag = false; } //cookie不存在 return(View()); }
public ActionResult DeleteConfirmed(int id) { TempArticle temparticle = db.tempArticle.Find(id); db.tempArticle.Remove(temparticle); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult TempArticleDetails(int id) { HttpCookie cookie = Request.Cookies["Employer"]; string EmployerAccount = cookie.Values["EmployerAccount"]; ViewBag.tb_Article = TempArticle.GetTempArticleByTempArticleID(id, EmployerAccount); ViewBag.tb_Demand = TempDemandInfo.GetTempDemandInfoByTempArticleID(id); return(View()); }
public ActionResult Editt([Bind(Include = "ArticleId,Date,ViewNo,Title,Content")] TempArticle tempArticle) { if (ModelState.IsValid) { db.Entry(tempArticle).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tempArticle)); }
// GET: /Temp/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TempArticle temparticle = db.tempArticle.Find(id); if (temparticle == null) { return(HttpNotFound()); } return(View(temparticle)); }
public ActionResult stepSix() { if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); StepSixViewModel model = _mapper.Map <TempArticle, StepSixViewModel>(tempArticle); return(View(model)); } return(View()); }
public ActionResult TempArticleEdit(int id) //此处id表示TempArticleID { ViewBag.flag = true; //文章是否存在的标志 HttpCookie cookie = Request.Cookies["Employer"]; if (cookie != null) { string EmployerAccount = cookie.Values["EmployerAccount"]; DataTable temparticle = TempArticle.GetTempArticleByTempArticleID(id, EmployerAccount);//得到临时表文章 if (temparticle != null && temparticle.Rows.Count > 0) { ViewBag.Article = temparticle; //显示大型招聘会选项 int typeid = Convert.ToInt32(temparticle.Rows[0]["TypeID"]); ViewBag.typename = ArticleType.GetTypeNameByTypeID(typeid); if (typeid == 1)//专场招聘 { ViewBag.PlaceListFirst = Article.GetPlaceListFirst(); } else if (typeid == 2)//双选会 { DataTable bigarticleTable2 = Article.SelectArticleFromArticle(2, DateTime.Now); ViewBag.bigarticleTable2 = bigarticleTable2; } else if (typeid == 3)//组团招聘 { DataTable bigarticleTable3 = Article.SelectArticleFromArticle(3, DateTime.Now); ViewBag.bigarticleTable3 = bigarticleTable3; } //其他类型的文章不用管 //需求部分 ViewBag.DemandInfos = TempDemandInfo.GetTempDemandInfoByTempArticleID(id); } else { ViewBag.flag = false; } //文章不存在 } else { ViewBag.flag = false; } //cookie不存在 return(View()); }
public ActionResult stepSeven(Article model) { ModelState.Clear(); String tempDAtaStr = TempData["article"] as string; ArticleViewModel articleViewModel = JsonConvert.DeserializeObject <ArticleViewModel>(tempDAtaStr); Article article = articleViewModel.Article; int flag = validateArticle(article); if (flag == 1) { TempData["article"] = JsonConvert.SerializeObject(articleViewModel); return(View()); } dbContext.articles.Add(article); dbContext.SaveChanges(); for (int i = 0; i < articleViewModel.Files.Count(); i++) { articleViewModel.Files.ElementAt(i).ArticleId = article.Id; } for (int i = 0; i < articleViewModel.AuthorsAndOpposedReviewers.Count(); i++) { articleViewModel.AuthorsAndOpposedReviewers.ElementAt(i).ArticleId = article.Id; } dbContext.files.AddRange(articleViewModel.Files); dbContext.SaveChanges(); dbContext.authorsAndOpposedReviewers.AddRange(articleViewModel.AuthorsAndOpposedReviewers); dbContext.SaveChanges(); IEnumerable <string> coAuthorsIds = articleViewModel.AuthorsAndOpposedReviewers.Where(a => a.role.Equals("coAuthor")).Select(a => a.UserId); List <string> emails = dbContext.Users.Where(u => coAuthorsIds.Any(ca => ca.Equals(u.Id))).Select(u => u.UserName).ToList(); //sendEmailToAuthors(emails); TempData["notice"] = "Article Added Successfully"; int articleId = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == articleId); dbContext.tempArticles.Remove(tempArticle); dbContext.SaveChanges(); HttpContext.Session.Remove("articleId"); return(RedirectToAction("index")); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here bool flag = TempDemandInfo.Delete(id) && TempArticle.Delete(id); return(Json(flag));//true表示删除成功 //return RedirectToAction("Index"); } catch { return(Json(false)); //return View(); } }
public ActionResult Create([Bind(Include = "ArticleId,Date,ViewNo,Title,Content")] TempArticle temparticle) { if (ModelState.IsValid) { temparticle.AuthorNAme = @Session["Name"].ToString(); temparticle.AuthorRole = @Session["Role"].ToString(); temparticle.ViewNo = 0; temparticle.Date = @DateTime.Now; db.tempArticle.Add(temparticle); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(temparticle)); }
public ActionResult stepTwo() { if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); //// when we come back to step two after uploadin file //// error occur because type of file in TempArticle is String //// but in StepTwoViewModel it's IFormFile StepTwoViewModel model = _mapper.Map <TempArticle, StepTwoViewModel>(tempArticle); return(View(model)); } return(View()); }
// GET: /Temp/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TempArticle temparticle = db.tempArticle.Find(id); temparticle.ViewNo = temparticle.ViewNo + 1; db.SaveChanges(); if (temparticle == null) { return(HttpNotFound()); } return(View(temparticle)); }
public ActionResult stepThree(StepThreeViewModel model) { if (!ModelState.IsValid) { model.AllFields = generatingData.populateFields(); model.AllSubjectCategories = generatingData.populateSubjectCategories(); return(View(model)); } string AllFieldsIds = ""; string AllSubjectCategoriesIds = ""; foreach (var field in model.FieldsIds) { AllFieldsIds += field + "-;"; } foreach (var category in model.SubjectCategoriesIds) { AllSubjectCategoriesIds += category + "-;"; } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.FieldsIds = AllFieldsIds; article.SubjectCategoriesIds = AllSubjectCategoriesIds; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { FieldsIds = AllFieldsIds, SubjectCategoriesIds = AllSubjectCategoriesIds, }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("stepFour")); }
public ActionResult stepFour(StepFourViewModel model) { if (model.AuthorsEmails != null && model.AuthorsEmails.GroupBy(a => a).Any(c => c.Count() > 1)) { ModelState.AddModelError("", "Same User Repeated"); } if (model.AuthorsEmails != null && !model.AuthorsEmails.Contains(User.Identity.Name)) { ModelState.AddModelError("", "Logged in user must be one of author"); model.AuthorsEmails.Insert(0, User.Identity.Name); } if (!ModelState.IsValid) { model.AuthorsInstitutions = initializeUsersInstitutions(model.AuthorsEmails); return(View(model)); } string coAuthorsEmails = ""; foreach (var authorEmail in model.AuthorsEmails) { coAuthorsEmails += authorEmail + "-;"; } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.AuthorsEmails = coAuthorsEmails; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { AuthorsEmails = coAuthorsEmails }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("stepFive")); }
public ActionResult TempArticleList(int id = 1) { int pageindex = id; //当前是第几页,第一页为1 int controlLength = 30; //文章标题显示字数限制,30个字符=15个汉字 int pagesize = 10; //每页显示多少记录 HttpCookie cookie = Request.Cookies["Employer"]; if (cookie != null) { string EmployerAccount = cookie.Values["EmployerAccount"]; int totalnum = TempArticle.GetTempArticleRecordCount(EmployerAccount, 0); //获取总共多少条记录 ViewBag.totalpage = (totalnum % pagesize == 0 && totalnum > pagesize) ? (totalnum / pagesize) : ((totalnum / pagesize) + 1); //获取总页数 ViewBag.pageindex = pageindex; //当前页 ViewBag.Articles = TempArticle.GetArticleListFromTempArticle(EmployerAccount, pageindex, 15, 0); } return(View()); }
public ActionResult stepFive(StepFiveViewModel model) { if (model.OpposedAuthorsEmails != null && model.OpposedAuthorsEmails.GroupBy(a => a).Any(c => c.Count() > 1)) { ModelState.AddModelError("", "Same User Repeated"); } if (!ModelState.IsValid) { model.OpposedAuthorsInstitutions = initializeUsersInstitutions(model.OpposedAuthorsEmails.ToList()); return(View(model)); } string OpposedAuthorsEmails = ""; if (model.OpposedAuthorsEmails != null) { foreach (var authorEmail in model.OpposedAuthorsEmails) { OpposedAuthorsEmails += authorEmail + "-;"; } } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.OpposedAuthorsEmails = OpposedAuthorsEmails; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { OpposedAuthorsEmails = OpposedAuthorsEmails }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("stepSix")); }
public ActionResult stepFive() { if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); StepFiveViewModel model = _mapper.Map <TempArticle, StepFiveViewModel>(tempArticle); model.OpposedAuthorsEmails = decodeStringToList(tempArticle.OpposedAuthorsEmails); model.OpposedAuthorsInstitutions = new List <string>(); foreach (string email in model.OpposedAuthorsEmails) { var result = dbContext.Users.Include(u => u.institution).SingleOrDefault(u => u.Email == email); model.OpposedAuthorsInstitutions.Add(result.institution.Name); } return(View(model)); } return(View()); }
public ActionResult TempArticleEdit(int id, FormCollection collection) //id为TempArticleID { //判断字段是否符合标准 //第一部分:文章 TempArticle temparticle = new TempArticle(); //判断文章类型 temparticle.TempArticleID = id; temparticle.TypeID = TempArticle.GetTypeIDByTempArticleID(id); temparticle.Title = Request["Title"].Trim(); temparticle.Introduction = Request["Introduction"].Trim(); //temparticle.EditTime = DateTime.Now;//提交时间不再改变 HttpCookie cookie = Request.Cookies["Employer"]; if (cookie != null) { string EmployerAccount = cookie.Values["EmployerAccount"]; temparticle.EditorAccount = EmployerAccount;//获取单位的Account } //temparticle.TypeID = Convert.ToInt32(Request["TypeID"].Trim());//得到类型 temparticle.ContactInfo = Request["ContactInfo"].Trim(); temparticle.FileAddr = ""; //下面上传文件时会赋值 temparticle.IsAudit = 1; //待定 temparticle.ArticleDescription = Request["ArticleDescription"].Trim(); int bigarticle = -1;//初始值 //判断文章类型 if (temparticle.TypeID == 1) { temparticle.PlaceFirstID = Convert.ToInt32(Request["PlaceFirstID"]); temparticle.RecruitTime = Convert.ToDateTime(Request["RecruitTime"]); } else if (temparticle.TypeID == 2) { if (Request["bigarticle2"] == null || Request["bigarticle2"] == "") { return(Json(new { message = "必须选择一个要加入的双选会" }));//退出 } bigarticle = Convert.ToInt32(Request["bigarticle2"]); } else if (temparticle.TypeID == 3) { if (Request["bigarticle3"] == null || Request["bigarticle3"] == "") { return(Json(new { message = "必须选择一个要加入的组团招聘" }));//退出 } bigarticle = Convert.ToInt32(Request["bigarticle3"]); } temparticle.BigArticleID = bigarticle;//默认-1是未选择大型招聘会文章的 //第二部分:需求 string[] PositionName = Request.Form.GetValues("PositionName"); string[] EducationalLevel = Request.Form.GetValues("EducationalLevel"); string[] Major = Request.Form.GetValues("Major"); string[] DemandNum = Request.Form.GetValues("DemandNum"); string[] PositionDec = Request.Form.GetValues("PositionDec"); //判断需求是否符合标准 List <TempDemandInfo> tempdemandInfo = new List <TempDemandInfo>(); //判断有几个需求 for (int i = 0; i < PositionName.Count(); ++i) { TempDemandInfo temp = new TempDemandInfo(); //temp.TempArticleID = 1;//得到刚上传的文章ID,在下面的插入后会有赋值 temp.PositionName = PositionName[i].ToString().Trim(); temp.EducationalLevel = EducationalLevel[i].ToString().Trim(); temp.Major = Major[i].ToString().Trim(); temp.DemandNum = Convert.ToInt32(DemandNum[i].ToString().Trim()); temp.PositionDec = PositionDec[i].ToString().Trim(); tempdemandInfo.Add(temp); } if (Request["IsDeleteFile"].ToString().Trim() == "yes") { //处理文件上传 if (Request.Files.Count > 0) { //支持的类型 List <string> FileType = new List <string>(); FileType.Add("jpg"); FileType.Add("gif"); FileType.Add("png"); FileType.Add("bmp"); FileType.Add("jpeg"); FileType.Add("pdf"); FileType.Add("txt"); FileType.Add("xls"); FileType.Add("xlsx"); FileType.Add("doc"); FileType.Add("docx"); FileType.Add("rar"); FileType.Add("zip"); //获取文件 HttpPostedFileBase uploadFile = Request.Files[0]; //判断是否为空文件 if (uploadFile == null)//|| uploadFile.ContentLength == 0) { return(Json(new { message = "fileerror" })); } //截取文件后缀名,判断文件类型是否被支持 if (FileType.Contains(uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf(".") + 1))) { //用jobsky作为分段符号 var fileTime = DateTime.Now.ToFileTime().ToString() + Path.GetFileName(uploadFile.FileName); //新命名的文件名(包含时间的整数形式) var tofileName = Path.Combine(Request.MapPath("~/UploadFiles"), fileTime); //把两个名字连接起来 try { if (Directory.Exists(Server.MapPath("~/UploadFiles")) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath("~/UploadFiles")); } uploadFile.SaveAs(tofileName); temparticle.FileAddr = fileTime;//获得上传后的文件名 } catch { return(Json(new { message = "fileerror" })); } } else { return(Json(new { message = "fileerror" }));//不支持此格式文件上传 } } } else { temparticle.FileAddr = Request["IsDeleteFile"].ToString().Trim();//没有删除,则获得到的就是原来的文件名 } //更新文章到数据库 if (TempArticle.Update(temparticle)) { //删除需求 TempDemandInfo.Delete(temparticle.TempArticleID); //插入需求到数据库 foreach (var t in tempdemandInfo) { t.TempArticleID = temparticle.TempArticleID; if (TempDemandInfo.Insert(t)) { //插入成功 } else { return(Json(new { message = "inserterror1" })); } } } return(Json(new { message = "success" })); }
public ActionResult stepSeven() { //// if (HttpContext.Session.GetInt32("articleId") == null) { return(RedirectToAction("stepOne")); } int articleId = (int)HttpContext.Session.GetInt32("articleId"); TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == articleId); List <string> subjectCategories = decodeStringToList(tempArticle.SubjectCategoriesIds); List <string> reviewersFieldIds = decodeStringToList(tempArticle.FieldsIds); List <string> Files = decodeStringToList(tempArticle.Files); List <string> Designations = decodeStringToList(tempArticle.Designation); List <string> coAuthors = decodeStringToList(tempArticle.AuthorsEmails); List <string> opposedReviewers = decodeStringToList(tempArticle.OpposedAuthorsEmails); Article NewArticle = new Article() { Type = tempArticle.Type, Abstract = tempArticle.Abstract, Title = tempArticle.Title, CoverLetter = tempArticle.CoverLetter, IsFunded = tempArticle.IsThereFundingToReportForThisSubmission, DeosContainSupplementaryMaterial = (tempArticle.DoesContainSupplementaryMaterial), PreviousSubmittedArticleId = tempArticle.PreviouSubmittedArticleId, // done this work down ////articleSubjectCategories = dbContext.subjectCategories.Where(sc => subjectCategories.Contains(sc.Id.ToString())).ToList(), ////ReviewersFields = dbContext.fields.Where(rf => reviewersFieldIds.Contains(rf.Id.ToString())).ToList() }; List <SubjectCategory> subjectCategories1 = dbContext.subjectCategories.Where(sc => subjectCategories.Contains(sc.Id.ToString())).ToList(); List <ArticleSubjectCategories> ArticleSubjectCategories = new List <ArticleSubjectCategories>(); foreach (SubjectCategory subjectCategory in subjectCategories1) { ArticleSubjectCategories articleSubjectCategories = new ArticleSubjectCategories() { ArticleId = NewArticle.Id, SubjectCategoryId = subjectCategory.Id }; ArticleSubjectCategories.Add(articleSubjectCategories); } NewArticle.articleSubjectCategories = ArticleSubjectCategories; List <Field> fields = dbContext.fields.Where(rf => reviewersFieldIds.Contains(rf.Id.ToString())).ToList(); List <ReviewerFields> ReviewerFields = new List <ReviewerFields>(); foreach (Field field in fields) { ReviewerFields reviewerFields = new ReviewerFields() { articleId = NewArticle.Id, fieldId = field.Id }; ReviewerFields.Add(reviewerFields); } NewArticle.reviewerFields = ReviewerFields; // Add Errors To ModelState If Found Any validateArticle(NewArticle); List <Files> f = new List <Files>(); // REMOVE -; FROM every object when decripted for (int i = 0; i < Files.Count(); i++) { Files n = new Files() { File = Files.ElementAt(i), Designation = Designations.ElementAt(i), }; f.Add(n); } List <AuthorsAndOpposedReviewers> authorsAndOpposedReviewers = new List <AuthorsAndOpposedReviewers>(); for (int i = 0; i < coAuthors.Count(); i++) { string email = coAuthors.ElementAt(i); AuthorsAndOpposedReviewers n = new AuthorsAndOpposedReviewers() { UserId = dbContext.Users.SingleOrDefault(u => u.Email.Equals(email)).Id, role = "coAuthor" }; // savechanges is necessary dbContext.SaveChanges(); authorsAndOpposedReviewers.Add(n); } for (int i = 0; i < opposedReviewers.Count(); i++) { string email = opposedReviewers.ElementAt(i); AuthorsAndOpposedReviewers n = new AuthorsAndOpposedReviewers() { UserId = dbContext.Users.SingleOrDefault(u => u.Email.Equals(email)).Id, role = "opposerReviewer" }; dbContext.SaveChanges(); authorsAndOpposedReviewers.Add(n); } ArticleViewModel articleViewModel = new ArticleViewModel() { Article = NewArticle, Files = f, AuthorsAndOpposedReviewers = authorsAndOpposedReviewers }; TempData["article"] = JsonConvert.SerializeObject(articleViewModel); return(View(NewArticle)); }
public ActionResult Edit([Bind(Include = "ID,Date,ViewNo,Title,Content")] Advertise advertise, TempArticle tempArticle) { if (ModelState.IsValid) { db.Entry(advertise).State = EntityState.Modified; db.tempArticle.Add(tempArticle); db.SaveChanges(); db.advertise.Remove(advertise); db.SaveChanges(); return(RedirectToAction("Index", "Temp")); } return(View(tempArticle)); }
public ActionResult stepSix(StepSixViewModel model) { if (model.PreviouslySubmittedRadioButton != null && model.PreviouslySubmittedRadioButton.Equals("Yes") && model.PreviouSubmittedArticleId == null) { ModelState.AddModelError("", "Article Id Is Not Submitted"); } if (model.PreviouslySubmittedRadioButton != null && model.PreviouslySubmittedRadioButton.Equals("No") && model.PreviouSubmittedArticleId != null) { model.PreviouSubmittedArticleId = null; } int?previousArticleId = null; if (model.PreviouSubmittedArticleId != null) { try { previousArticleId = Int32.Parse(model.PreviouSubmittedArticleId.ToString()); Article article = dbContext.articles.SingleOrDefault(a => a.Id == previousArticleId); if (article == null) { ModelState.AddModelError("", "Invalid Previous Article Id"); } } catch (Exception e) { ModelState.AddModelError("", "Invalid Previous Article Id"); } } if (!ModelState.IsValid) { return(View(model)); } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.CoverLetter = model.CoverLetter; article.PreviouSubmittedArticleId = previousArticleId; article.IsThereFundingToReportForThisSubmission = model.IsThereFundingToReportForThisSubmission; article.DoesContainSupplementaryMaterial = model.DoesContainSupplementaryMaterial; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { CoverLetter = model.CoverLetter, PreviouSubmittedArticleId = previousArticleId, IsThereFundingToReportForThisSubmission = model.IsThereFundingToReportForThisSubmission, DoesContainSupplementaryMaterial = model.DoesContainSupplementaryMaterial }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("stepSeven")); }
public ActionResult stepTwo(StepTwoViewModel model) { string[] allowedFileTypes = { ".pdf", ".docx", ".html" }; int index = 0; string AllFiles = ""; string AllDesignation = ""; bool anyFileUploded = false; if (model.Files == null) { return(View(model)); } for (int i = 0; i < model.Files.Count(); i++) { var file = model.Files.ElementAt(i); if (file == null && i == 0) { ModelState.AddModelError("", "First Main File Is A Required File"); continue; } if (file != null) { string a = Path.GetExtension(file.FileName); if (!allowedFileTypes.Contains(Path.GetExtension(file.FileName))) { ModelState.AddModelError("", "File Type Not Allowed"); continue; } var picUniqueName = string.Format("{0}-{1}{2}" , Path.GetFileNameWithoutExtension(file.FileName) , Guid.NewGuid().ToString("N") , Path.GetExtension(file.FileName)); // Creating Destination path string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "files"); string filePath = Path.Combine(uploadsFolder, picUniqueName); file.CopyTo(new FileStream(filePath, FileMode.Create)); AllFiles += picUniqueName + "-;"; AllDesignation += model.Designation.ElementAt(index) + "-;"; index++; } } if (!ModelState.IsValid) { return(View(model)); } if (HttpContext.Session.GetInt32("articleId") != null) { int id = (int)HttpContext.Session.GetInt32("articleId"); TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id); article.Files = AllFiles; article.Designation = AllDesignation; dbContext.SaveChanges(); } else { TempArticle article = new TempArticle() { Files = AllFiles, Designation = AllDesignation, }; dbContext.tempArticles.Add(article); dbContext.SaveChanges(); HttpContext.Session.SetInt32("articleId", article.Id); } return(RedirectToAction("stepThree")); }