HomeController.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 = CustomPrincipal.Current != null ? CustomPrincipal.Current.IsStudent : false;
  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 MainChangePwd()
  60. {
  61. return View();
  62. }
  63. public ActionResult UploaderSave(FormCollection form)
  64. {
  65. Response.Cache.SetNoStore();
  66. try
  67. {
  68. FileUploadView upfile = new FileUploadView();
  69. var files = Request.Files;
  70. var formID = (!string.IsNullOrEmpty(Request["v"])) ? new Guid(Request["v"]) : (Guid?)null;
  71. string sessionName = FileUploadHelper.GetFileUploadSessionName(formID.Value);
  72. //检查文件扩展名字
  73. var postedFile = files["Filedata"]; //得到要上传文件
  74. if (postedFile.FileName == null)
  75. {
  76. return Json(new FileUploadView(), JsonRequestBehavior.AllowGet);
  77. }
  78. upfile.FileID = Function.NewPKGuid();
  79. string fileUrl = FileUploadHelper.UploadFile(postedFile);
  80. upfile.FileUrl = fileUrl;
  81. upfile.FileName = postedFile.FileName;
  82. upfile.FormID = formID;
  83. if (Session[sessionName] == null)
  84. {
  85. Session[sessionName] = new List<FileUploadView>();
  86. }
  87. ((List<FileUploadView>)Session[sessionName]).Add(upfile);
  88. return Json(upfile, JsonRequestBehavior.AllowGet);
  89. }
  90. catch
  91. {
  92. }
  93. return Json(new FileUploadView(), JsonRequestBehavior.AllowGet);
  94. }
  95. }
  96. }