public async Task <ActionResult> AddLeaveImages(AddLeaveImagesViewModel omodel)
        {
            if (ModelState.IsValid)
            {
                if (Session["TempLeave"] == null)
                {
                    return(View("Error", new[] { "请按照流程" }));
                }
                var model = Session["TempLeave"] as LeaveApplyViewModel;
                if (model == null)
                {
                    return(View("Error", new[] { "请按照流程" }));
                }
                model.ImageUrls = omodel.ImagesUrl;
                var userid = User.Identity.GetUserId();
                var user   = await UserManager.FindByIdAsync(userid);

                var config = await LeaveConfigManager.GetConfigAsync();

                Leave leave = new Leave
                {
                    Category    = model.Category,
                    StartDate   = model.StartDate,
                    EndDate     = model.EndDate,
                    ImageUrls   = model.ImageUrls,
                    OneDayTime  = model.OneDayTime,
                    OneDayStart = model.OneDayStart,
                    OneDayEnd   = model.OneDayEnd,
                    Reason      = model.Reason,
                    ToWhere     = model.ToWhere,
                    TimeType    = model.TimeType,
                    //UserId = userid,
                    LeaveStatus = LeaveStatus.已提交,
                    AddTime     = DateTime.Now,
                    ResumeTime  = DateTime.Now,
                    IsResume    = 0,
                };
                leave.Checks = new Check[] { };
                var classHeadTeacher = user.StudentInfo.BelongClass.ClassTeacher;
                leave.Checks.Add(new Check()
                {
                    CheckTeacher = classHeadTeacher,
                    CheckOrder   = 0,
                    CheckStatus  = CheckStatus.未查看,
                    CheckTime    = DateTime.Now,
                    CheckOpinion = ""
                });
                if (model.TimeType == TimeType.一天以上)
                {
                    if ((model.EndDate - model.StartDate).Days > config.LeastDayToSign)
                    {
                        var clerk = config.ClerkTeacher;
                        leave.Checks.Add(new Check()
                        {
                            CheckTeacher = clerk.Teacher.TeacherInfo,
                            CheckOrder   = 1,
                            CheckStatus  = CheckStatus.未查看,
                            CheckTime    = DateTime.Now,
                            CheckOpinion = ""
                        });
                    }
                }
                await LeaveManager.AddEntityAsync(leave);

                return(RedirectToAction("Index"));
            }
            return(View(omodel));
        }
        public async Task <ActionResult> Apply(LeaveApplyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userid = User.Identity.GetUserId();
                var user   = await UserManager.FindByIdAsync(userid);

                if (user.StudentInfo.BelongClass == null ||
                    user.StudentInfo.Dormitory == null ||
                    user.StudentInfo.HomeAddress == null ||
                    user.StudentInfo.PersonalTel == null)
                {
                    ModelState.AddModelError("", "请完善个人信息");
                    return(View(model));
                }

                if (!await LeaveManager.IsAllLeaveResumedAsync(userid))
                {
                    ModelState.AddModelError("", "还未销假");
                }
                else
                {
                    var config = await LeaveConfigManager.GetConfigAsync();

                    if (await LeaveManager.IsAllLeaveConditionMeeted(userid, config))
                    {
                        if (model.Category == LeaveCategory.病假)
                        {
                            if (model.TimeType == TimeType.一天以上)
                            {
                                if ((model.EndDate - model.StartDate).Days + 1 >= config.LeastSickLeaveDay)
                                {
                                    if (model.UploadFile == null)
                                    {
                                        ModelState.AddModelError("", "请上传图片附件");
                                        return(View(model));
                                    }
                                    else
                                    {
                                        //"E:\\MyPrivateProject\\StudentManageSystem\\LeaveSystem\\LeaveSystem.Web\\"
                                        var p = Server.MapPath("/UploadImageAttach/");
                                        if (!Directory.Exists(p))
                                        {
                                            Directory.CreateDirectory(p);
                                        }
                                        var t        = DateTime.Now.Ticks;
                                        var namea    = model.UploadFile.FileName.Split('\\');
                                        var name     = namea[namea.Length - 1];
                                        var filename = "/UploadImageAttach/" + t.ToString() + "_" +
                                                       name;

                                        model.UploadFile.SaveAs(p + t.ToString() + "_" + name);
                                        model.ImageUrls = filename;
                                    }
                                }
                            }
                        }

                        Leave leave = new Leave
                        {
                            Category    = model.Category,
                            StartDate   = model.StartDate,
                            EndDate     = model.EndDate,
                            ImageUrls   = model.ImageUrls,
                            OneDayTime  = model.OneDayTime,
                            OneDayStart = model.OneDayStart,
                            OneDayEnd   = model.OneDayEnd,
                            Reason      = model.Reason,
                            ToWhere     = model.ToWhere,
                            TimeType    = model.TimeType,
                            Student     = user.StudentInfo,
                            LeaveStatus = LeaveStatus.已提交,
                            AddTime     = DateTime.Now,
                            ResumeTime  = DateTime.Now,
                            IsResume    = 0,
                        };
                        leave.Checks = new List <Check>();
                        var classHeadTeacher = user.StudentInfo.BelongClass.ClassTeacher;
                        leave.Checks.Add(new Check()
                        {
                            CheckTeacher = classHeadTeacher,
                            CheckOrder   = 0,
                            CheckStatus  = CheckStatus.未查看,
                            CheckTime    = DateTime.Now,
                            AddTime      = DateTime.Now
                        });
                        if (model.TimeType == TimeType.一天以上)
                        {
                            if ((model.EndDate - model.StartDate).Days > config.LeastDayToSign)
                            {
                                var clerk = config.ClerkTeacher;
                                leave.Checks.Add(new Check()
                                {
                                    CheckTeacher = clerk.Teacher.TeacherInfo,
                                    CheckOrder   = 1,
                                    CheckStatus  = CheckStatus.未查看,
                                    CheckTime    = DateTime.Now,
                                    AddTime      = DateTime.Now
                                });
                            }
                        }
                        await LeaveManager.AddEntityAsync(leave);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "请假添加不符合");
                    }
                }
            }
            return(View(model));
        }