HomeController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Common.Data;
  7. using EMIS.Web.Controls;
  8. using EMIS.Utility.FormValidate;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.Entities;
  11. using EMIS.Utility;
  12. using EMIS.ViewModel;
  13. using Bowin.Common.Utility;
  14. using EMIS.CommonLogic.Students;
  15. using EMIS.CommonLogic.SystemServices;
  16. namespace EMIS.Web.Controllers
  17. {
  18. [Authorization]
  19. public class HomeController : Controller
  20. {
  21. public IStudentsServices studentsServices { get; set; }
  22. public IAnnouncementServices AnnouncementServices { get; set; }
  23. public ActionResult Index()
  24. {
  25. var IsStudent = EMIS.Utility.FormValidate.CustomPrincipal.Current.IsStudent;
  26. ViewBag.IsStudent = IsStudent;
  27. if (IsStudent)
  28. {
  29. if (!studentsServices.CheckNecessary(EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID))
  30. {
  31. return RedirectToAction("FinishInfomation", "Account");
  32. }
  33. }
  34. return View();
  35. }
  36. public ActionResult SwitchRole(Guid hdnSelectedRole)
  37. {
  38. this.SwitchUserRole(hdnSelectedRole);
  39. return RedirectToAction("Index");
  40. }
  41. public ActionResult About()
  42. {
  43. ViewBag.Message = "你的应用程序说明页。";
  44. return View();
  45. }
  46. public ActionResult Contact()
  47. {
  48. ViewBag.Message = "你的联系方式页。";
  49. return View();
  50. }
  51. public ActionResult Main()
  52. {
  53. var typeList = AnnouncementServices.GetAnnouncementTypeViewHaveSourseList();
  54. var typeIDList = typeList.Select(x => x.AnnouncementTypeID).ToList();
  55. ViewBag.TypeIDList = typeIDList;
  56. ViewBag.TypeList = typeList;
  57. return View();
  58. }
  59. public ActionResult UploaderSave(FormCollection form)
  60. {
  61. Response.Cache.SetNoStore();
  62. try
  63. {
  64. FileUploadView upfile = new FileUploadView();
  65. var files = Request.Files;
  66. var formID = (!string.IsNullOrEmpty(Request["v"])) ? new Guid(Request["v"]) : (Guid?)null;
  67. string sessionName = FileUploadHelper.GetFileUploadSessionName(formID.Value);
  68. //检查文件扩展名字
  69. var postedFile = files["Filedata"]; //得到要上传文件
  70. if (postedFile.FileName == null)
  71. {
  72. return Json(new FileUploadView(), JsonRequestBehavior.AllowGet);
  73. }
  74. upfile.FileID = Function.NewPKGuid();
  75. string fileUrl = FileUploadHelper.UploadFile(postedFile);
  76. upfile.FileUrl = fileUrl;
  77. upfile.FileName = postedFile.FileName;
  78. upfile.FormID = formID;
  79. if (Session[sessionName] == null)
  80. {
  81. Session[sessionName] = new List<FileUploadView>();
  82. }
  83. ((List<FileUploadView>)Session[sessionName]).Add(upfile);
  84. return Json(upfile, JsonRequestBehavior.AllowGet);
  85. }
  86. catch
  87. {
  88. }
  89. return Json(new FileUploadView(), JsonRequestBehavior.AllowGet);
  90. }
  91. }
  92. }