StudentRecordController.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.Students;
  7. using EMIS.ViewModel.Cultureplan;
  8. using EMIS.CommonLogic.SystemSetting;
  9. using EMIS.ViewModel.Students;
  10. using EMIS.ViewModel;
  11. using EMIS.Utility;
  12. using EMIS.Web.Controls;
  13. using System.IO;
  14. namespace EMIS.Web.Controllers.StudentSystem.StudentRecord
  15. {
  16. [Authorization]
  17. public class StudentRecordController : Controller
  18. {
  19. public IStudentsServices StudentsServices { get; set; }
  20. public IStudentRecordServices StudentRecordService { get; set; }
  21. public Lazy<IDictionaryServices> DictionaryServices { get; set; }
  22. /// <summary>
  23. /// 我的信息(学生平台,列表形式-暂时无效,有误)
  24. /// </summary>
  25. /// <returns></returns>
  26. public ActionResult List()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 我的信息
  32. /// </summary>
  33. /// <returns></returns>
  34. public ActionResult Record()
  35. {
  36. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  37. var Student = StudentRecordService.GetStudentByStudentNo(user.UserID);
  38. return View(Student);
  39. }
  40. [HttpPost]
  41. public ActionResult Record(StudentRecordView studentRecordView)
  42. {
  43. try
  44. {
  45. var accepts = new List<string> { ".jpg" };
  46. var postedFile = Request.Files["PhotoUrl"];
  47. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
  48. {
  49. throw new Exception("只允许上传.jpg格式的文件。");
  50. }
  51. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && (postedFile.ContentLength > (200 * 1024) || postedFile.ContentLength < (50 * 1024)))
  52. {
  53. throw new Exception("只允许上传50-200k大小的照片。");
  54. }
  55. string photoUrl = FileUploadHelper.UploadFile(postedFile);
  56. if (photoUrl != null)
  57. {
  58. studentRecordView.PhotoUrl = photoUrl;
  59. }
  60. StudentRecordService.RecordSave(studentRecordView);
  61. string UrlStr = Url.Action("Record").AddMenuParameter();
  62. return RedirectToAction("MsgShowAndOpenAddUrl", "Common", new
  63. {
  64. WindowID = Request["WindowID"],
  65. msg = "保存成功!",
  66. url = UrlStr
  67. });
  68. }
  69. catch (Exception ex)
  70. {
  71. string UrlStr = Url.Action("Record").AddMenuParameter();
  72. return RedirectToAction("MsgShowAndOpenAddUrl", "Common", new
  73. {
  74. WindowID = Request["WindowID"],
  75. msg = "保存失败,原因:" + ex.Message,
  76. url = UrlStr
  77. });
  78. }
  79. }
  80. }
  81. }