Example #1
0
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 当前用户
            var employee = (User.Identity as AppkizIdentity).Employee;

            /*
             * 参数获取
             */
            // 组团名
            var outName = collection["outName"];
            // 任务描述
            var descn = collection["desc"];
            // 出访类型
            var credType = collection["credType"];
            // 出访人员履历
            var outUsers = collection["outUsers"];
            // 申请附件
            var applyAtt = collection["applyAtt"];

            /*
             * 参数校验
             */
            // 团组名
            if (string.IsNullOrEmpty(outName))
            {
                return(ResponseUtil.Error(400, "团组名不能为空"));
            }
            // 出访任务
            if (string.IsNullOrEmpty(descn))
            {
                return(ResponseUtil.Error(400, "任务描述不能为空"));
            }
            // 出访类型
            if (string.IsNullOrEmpty(credType))
            {
                return(ResponseUtil.Error(400, "出访类型不能为空"));
            }
            // 人员ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }
            // 申请附件ID不能为空
            if (string.IsNullOrEmpty(applyAtt))
            {
                return(ResponseUtil.Error(400, "申请附件不能为空"));
            }

            /*
             * 存储申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = new YGS_Apply();
                apply.OutName     = outName;
                apply.Desc        = descn;
                apply.UserId      = employee.EmplID;
                apply.CredType    = credType;
                apply.OutUsers    = outUsers;
                apply.ApplyAtt    = applyAtt;
                apply.ApplyStatus = WHConstants.Apply_Status_Examing;
                apply.ApplyDate   = DateTime.Now;
                apply.NextStep    = "下载并填写表格";
                apply.CreateTime  = DateTime.Now;
                apply.UpdateTime  = DateTime.Now;
                apply.IsDelete    = false;
                db.Apply.Add(apply);
                db.SaveChanges();

                var notifyUserIdList = NotificationUtil.GetNotificationUsers();

                foreach (var user in notifyUserIdList)
                {
                    NotificationUtil.SendNotification(user, "您有新的出国申请审核", "/Apps/YGS/Home/Check");
                }

                return(ResponseUtil.OK(200, "创建成功"));
            }
        }
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 当前用户
            var employee = (User.Identity as AppkizIdentity).Employee;
            // 出访日期
            DateTime outDate = new DateTime();
            // 履历IDs
            List <int> historyIdList = new List <int>();

            /*
             * 参数获取
             */
            // 组团名
            var outName = collection["outName"];
            // 任务描述
            var descn = collection["desc"];
            // 出访类型
            var credType = collection["credType"];
            // 出访人员履历
            var outUsers = collection["outUsers"];
            // 出访日期
            var outDateString = collection["outDate"];
            // 履历ID列表
            var historyIds = collection["historyIds"];

            /*
             * 参数校验
             */
            // 团组名
            if (string.IsNullOrEmpty(outName))
            {
                return(ResponseUtil.Error(400, "团组名不能为空"));
            }
            // 出访任务
            if (string.IsNullOrEmpty(descn))
            {
                return(ResponseUtil.Error(400, "任务描述不能为空"));
            }
            // 出访类型
            if (string.IsNullOrEmpty(credType))
            {
                return(ResponseUtil.Error(400, "出访类型不能为空"));
            }
            // 人员ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }
            // 出访日期
            if (!string.IsNullOrEmpty(outDateString))
            {
                if (!DateTime.TryParse(outDateString, out outDate))
                {
                    return(ResponseUtil.Error(400, "出访日期格式不正确"));
                }
            }
            // 履历ID列表
            if (!string.IsNullOrEmpty(historyIds))
            {
                historyIdList = historyIds.Split(',').Select(int.Parse).ToList();
            }

            /*
             * 存储申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = new YGS_Apply();
                apply.OutName  = outName;
                apply.Desc     = descn;
                apply.UserId   = employee.EmplID;
                apply.CredType = credType;
                apply.OutUsers = outUsers;
                //apply.ApplyAtt = applyAtt;
                apply.ApplyStatus = WHConstants.Apply_Status_Passed;
                apply.ApplyDate   = DateTime.Now;
                apply.NextStep    = "";
                if (!string.IsNullOrEmpty(outDateString))
                {
                    apply.OutDate = outDate;
                }
                apply.CreateTime = DateTime.Now;
                apply.UpdateTime = DateTime.Now;
                apply.IsDelete   = true;
                db.Apply.Add(apply);
                db.SaveChanges();

                // 更新对应的履历
                if (historyIdList.Count > 0)
                {
                    var histories = db.History.Where(n => historyIdList.Contains(n.ID)).ToList();
                    foreach (var history in histories)
                    {
                        history.ApplyId = apply.ID;
                    }
                    db.SaveChanges();
                }

                return(ResponseUtil.OK(200, "创建成功"));
            }
        }