コード例 #1
0
        public async Task <ActionResult <LeaveResponse> > RequestRest([FromBody] LeaveRequest request)
        {
            var stu_id = 3;//Int32.Parse(User.Identity.Name);

            var temp = _mapper.Map <LeaveEntity>(request);

            temp.student_id = stu_id;

            var ans = await LeaveAccessor.Create(temp);

            if (ans > 0)
            {
                var leavere = await LeaveAccessor.Find(ans);

                if (leavere != null)
                {
                    return(Ok(_mapper.Map <LeaveResponse>(leavere)));
                }
                return(Ok(-1));
            }
            return(Ok(-1));
        }
コード例 #2
0
        //[AllowAnonymous]
        public async Task <ActionResult <LeaveResponse> > RequestRest([FromBody] LeaveRequest request)
        {
            var stu_id = Int32.Parse(User.Identity.Name);

            if (await UserAccessor.CheckRole(stu_id) == Constants.Role.Provider)
            {
                return(BadRequest(new { message = "Providers cannot create leave application." }));
            }
            int check_leave = await LeaveAccessor.CheckLeave(stu_id, request.work_id, request.leave_day);

            if (check_leave == 1)
            {
                // 已成功申请
                return(Ok(-21));
            }
            else if (check_leave == 2)
            {
                // 正在申请中
                return(Ok(-22));
            }
            var temp = _mapper.Map <LeaveEntity>(request);

            /* 检查请假时间是否在工作时间内 */
            WorkTimeEntity work_time = await WorkAccessor.GetWorkTime(temp.work_id);

            DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();

            dtFormat.ShortDatePattern = "yyyy-MM-dd";
            DateTime stDay = Convert.ToDateTime(work_time.start_day, dtFormat);
            DateTime edDay = Convert.ToDateTime(work_time.end_day, dtFormat);
            DateTime lvDay = Convert.ToDateTime(temp.leave_day);

            if (lvDay < stDay || lvDay > edDay || Convert.ToInt32(lvDay.DayOfWeek) != work_time.week_day)
            {
                return(Ok(-10)); //"The date of leave is not included in the work date."
            }

            dtFormat.ShortDatePattern = "HH:mm";
            DateTime stTime   = Convert.ToDateTime(work_time.start_time, dtFormat);
            DateTime edTime   = Convert.ToDateTime(work_time.end_time, dtFormat);
            DateTime lvStTime = Convert.ToDateTime(temp.leave_start, dtFormat);
            DateTime lvEdTime = Convert.ToDateTime(temp.leave_end, dtFormat);

            if (lvStTime < stTime || lvEdTime > edTime)
            {
                return(Ok(-11)); //"The time of leave is not included in the work time."
            }

            temp.leave_duration = CalDurationTime(temp.leave_start, temp.leave_end);
            temp.student_id     = stu_id;

            var ans = await LeaveAccessor.Create(temp);

            if (ans > 0)
            {
                var leavere = await LeaveAccessor.Find(ans);

                if (leavere != null)
                {
                    return(Ok(_mapper.Map <LeaveResponse>(leavere)));
                }
                return(Ok(-1));
            }
            return(Ok(-1));
        }