Example #1
0
        public ActionResult AddTrainee(string snr, string trainingid)
        {
            var res = new TRes
            {
                data = 0,
                msg  = string.Empty
            };

            Guid gTrainingID = Guid.Empty;

            if (!Guid.TryParse(trainingid, out gTrainingID))
            {
                res.msg = "培训id无效";
                return(Json(res));
            }

            var         serr       = string.Empty;
            TPersonInfo personInfo = null;

            res.data = TraineeInfo.Add(snr, gTrainingID, out personInfo, out serr);
            res.msg  = serr;
            //var cnt = TraineeInfo.GetCountByTrainingID(gTrainingID);
            res.extra = new
            {
                //cnt = cnt,
                personInfo = personInfo
            };

            return(Json(res));
        }
Example #2
0
        /// <summary>
        /// 检查是否讲师或是否已经有授权
        /// </summary>
        /// <returns></returns>
        internal static int CheckByWorkID(string sWorkID, string courseid, out TPersonInfo lecInfo, out string serr)
        {
            lecInfo = null;
            serr    = string.Empty;
            var custom = WorkIDInfo.GetEmployeeECardInfo(sWorkID);

            if (null == custom)
            {
                serr = "没有找到员工信息";
                return(-1);
            }

            var workid = custom.OutID;

            if (null == GetByWorkID(workid))
            {
                serr = "不是讲师";
                return(-1);
            }

            Guid gid = Guid.Empty;

            if (!Guid.TryParse(courseid, out gid))
            {
                serr = "无效课程ID";
                return(-1);
            }
            //check for course privilege
            using (var context = new TrainingSign_Entities())
            {
                var people = from p in context.tbl_lector
                             from q in context.tbl_lector_course_link
                             from c in context.tbl_course
                             where string.Compare(p.lector_workid, workid, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                             c.id == gid &&
                             q.ref_lector_id == p.id && q.ref_course_id == c.id
                             select new TPersonInfo
                {
                    id      = p.id,
                    workid  = p.lector_workid,
                    cn_name = p.lector_cn_name,
                    en_name = p.lector_en_name
                };
                if (people.Any())
                {
                    lecInfo = people.First();
                    return(1);
                }
                else
                {
                    serr = "讲师没有此课程的授权";
                    return(0);
                }
            }
        }
Example #3
0
        public ActionResult CheckLector(string workid, string courseid)
        {
            var res = new TRes
            {
                data = -1,
                msg  = string.Empty
            };
            string      serr    = string.Empty;
            TPersonInfo lecInfo = null;
            int         nRet    = LectorInfo.CheckByWorkID(workid, courseid, out lecInfo, out serr);

            res.data = nRet;
            res.msg  = serr;
            if (nRet > 0)
            {
                res.extra = lecInfo;
            }
            return(Json(res));
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="snr"></param>
        /// <param name="gTrainingID"></param>
        /// <param name="empInfo"></param>
        /// <param name="serr"></param>
        /// <returns>
        ///    0 -- 失败
        ///    1 -- 签到成功
        ///    -1 -- 已经签到过
        /// </returns>
        internal static int Add(string snr, Guid gTrainingID, out TPersonInfo empInfo, out string serr)
        {
            empInfo = null;
            serr    = string.Empty;
            var info = WorkIDInfo.GetEmployeeInfo(snr);

            if (null == info)
            {
                serr = "没有找到此员工信息";
                return(0);
            }

            //insert
            int nRet = -1;

            using (var context = new TrainingSign_Entities())
            {
                //由于部门解释还是有问题,用来避免由于部门名称过长而插入失败,
                //这里的限制与 tbl_trainee的department列一致
                var sDept = StringUtility.LimitStr(info.shortDepartment, 80);
                //insert
                var entity = new tbl_trainee()
                {
                    ref_training_id = gTrainingID
                    , workid        = info.empID
                    , name          = info.cnName
                    , department    = sDept
                    , signinTime    = DateTime.Now
                                      //,organizer
                                      //,memo
                };

                if (!context.tbl_trainee.Any(x => x.ref_training_id == entity.ref_training_id &&
                                             0 == string.Compare(x.workid, entity.workid, StringComparison.InvariantCultureIgnoreCase)))
                {
                    try
                    {
                        context.tbl_trainee.Add(entity);
                        context.SaveChanges();
                        nRet    = 1;
                        empInfo = new TPersonInfo {
                            extra         = entity.id, //!注意
                            workid        = entity.workid,
                            cn_name       = entity.name,
                            org_name      = entity.department,
                            oper_time_str = LocalFormatStr.GetLocalTimeStr(entity.signinTime.Value)
                        };
                    }
                    catch (Exception ex)
                    {
                        //serr = ex.Message;
                        serr = "添加员工签到失败";
                    }
                }
                else
                {
                    //已经签到过
                    empInfo = new TPersonInfo
                    {
                        workid        = entity.workid,
                        cn_name       = entity.name,
                        org_name      = entity.department,
                        oper_time_str = ""
                    };
                }
            }
            return(nRet);
        }