public ActionResult Create(FormCollection collection)
 {
     var model = new TrainNeed();
     TryUpdateModel(model, collection.ToValueProvider());
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         model.CreatedAt = DateTime.Now;
         model.CreatedBy = CurrentAccountNo;
         ViewData.Model = model;
         if (session.Create(model))
         {
             session.Commit();
             FlashSuccess("创建记录成功!");
             return Close();
         }
         session.Rollback();
         FlashFailure("创建记录失败!");
         return View();
     }
 }
        public ActionResult Create(FormCollection collection)
        {
            var model = new TrainNeed();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {

                session.BeginTransaction();
                var dept = new Criteria<Department>(session)
                  .AndIn<User>(m => m.Id, n => n.DepartmentId, m => m.Code.Equals(CurrentAccountNo)).Load();
                var models = session.Find<TrainNeed>(m => !m.IsCollected && m.Status.Equals(TrainNeedStatus.已提交部门负责人) && m.DeptId == dept.Id && m.Type.Equals(TrainNeedType.员工));
                if (models == null || !models.Any())
                {
                    FlashWarn("没有未汇总的需求!");
                    return Close();
                }
                foreach (var trainNeed in models)
                {
                    trainNeed.IsCollected = true;
                }
                model.DeptId = dept != null ? dept.Id : 0;
                model.Dept = dept != null ? dept.Name : null;
                model.IsCollected = false;
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                model.Type = TrainNeedType.部门;
                ViewData.Model = model;
                ViewData["StaffNeeds"] = models;
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.部门) && m.DeptId.Equals(model.DeptId) && m.Year.Equals(model.Year));
                if (exist != null)
                {
                    ModelState.AddModelError("Year", "本部门该年度部门培训需求已经存在!");
                    return View(model);
                }
                if (session.Create(model) && session.Update(models))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            var model = new TrainNeed();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {

                session.BeginTransaction();
                var models = session.Find<TrainNeed>(m =>
                        !m.IsCollected && m.Status.Equals(TrainNeedStatus.已提交培训部门) && m.Type.Equals(TrainNeedType.部门));
                if (models == null || !models.Any())
                {
                    FlashWarn("没有未汇总的需求!");
                    return Close();
                }
                foreach (var trainNeed in models)
                {
                    trainNeed.IsCollected = true;
                }
                model.IsCollected = false;
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                model.Type = TrainNeedType.公司;
                ViewData["StaffNeeds"] = models;
                ViewData.Model = model;
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.公司) && m.Year.Equals(model.Year));
                if (exist != null)
                {
                    ModelState.AddModelError("Year", "该年度公司培训需求已经存在!");
                    return View(model);
                }
                if (session.Create(model) && session.Update(models))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            var model = new TrainNeed();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();

                model.StaffCode = CurrentAccountNo;
                model.StaffName = CurrentAccountNo.GetName();
                var dept = new Criteria<Department>(session)
                   .AndIn<User>(m => m.Id, n => n.DepartmentId, m => m.Code.Equals(CurrentAccountNo)).Load();
                model.DeptId = dept != null ? dept.Id : 0;
                model.Dept = dept != null ? dept.Name : null;
                model.IsCollected = false;
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                model.Type = TrainNeedType.员工;
                model.Status = "";
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.员工) && m.DeptId.Equals(model.DeptId) && m.Year.Equals(model.Year) && m.StaffCode.Equals(CurrentAccountNo));
                if (exist != null)
                {
                    ModelState.AddModelError("Year", "您该年度需求已经存在!");
                    return View(model);
                }
                ViewData.Model = model;
                if (session.Create(model))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
 private static bool CanSubmit(TrainNeed item)
 {
     return item != null && string.IsNullOrEmpty(item.Status);
 }
 private static bool CanSubmit(TrainNeed item)
 {
     return item != null && item.Status.Equals(TrainNeedStatus.已提交分管领导);
 }