コード例 #1
0
        public async Task <ActionResult <int> > CreateApply(ApplyRequest request)
        {
            var stu_id = Int32.Parse(User.Identity.Name);

            if (await UserAccessor.CheckRole(stu_id) != Role.Student)
            {
                return(BadRequest(new { message = "CreateApply is for students." }));
            }
            int check_apply = await ApplyAccessor.CheckApply(stu_id, request.work_id);

            if (check_apply == 1)
            {
                // 已通过改工作的申请
                return(Ok(-21));
            }
            else if (check_apply == 2)
            {
                // 正在申请该工作
                return(Ok(-22));
            }
            var temp = _mapper.Map <ApplyEntity>(request);

            temp.student_id = stu_id;
            temp.teacher_id = await WorkAccessor.GetTeacher(temp.work_id);

            temp.resume_id = await ResumeAccessor.GetResume(temp.student_id);

            if (temp.resume_id == -1)
            {
                return(Ok(-10));
            }
            var ans = await ApplyAccessor.Create(temp);

            if (ans > 0)
            {
                return(Ok(ans));
            }
            return(Ok(-1));
        }
コード例 #2
0
ファイル: WorkController.cs プロジェクト: chuckleLZY/FeedPet
        public async Task <ActionResult <WorkItemResponse> > ViewOwnWork([FromBody] ViewWorkRequest request)
        {
            WorkItemResponse workItem = new WorkItemResponse();

            workItem.totalpage = 0;
            workItem.pagenum   = request.pagenum;
            workItem.worklist  = new List <WorkResponse>();

            var start = (request.pagenum - 1) * request.pagesize;
            var end   = request.pagenum * request.pagesize - 1;

            //取得存在cookie的当前账户id
            var stu_id = Int32.Parse(User.Identity.Name);

            var temp = await WorkAccessor.FindOwnWork(stu_id);

            if (temp != null)
            {
                for (int i = 0; i < temp.total; i++)
                {
                    var work_info = await WorkAccessor.FindWorkInfo(temp.TakesItem[i].work_id);

                    var status = await TakesAccessor.FindInfo(stu_id, temp.TakesItem[i].work_id);

                    workItem.totalpage++;
                    if (i >= start && i <= end && work_info != null)
                    {
                        WorkResponse a = _mapper.Map <WorkResponse>(work_info);
                        a.status = status.status;
                        workItem.worklist.Add(a);
                    }
                }

                return(Ok(workItem));
            }
            return(Ok(-1));
        }
コード例 #3
0
ファイル: WorkController.cs プロジェクト: chuckleLZY/FeedPet
        public async Task <ActionResult <WorkResponse> > CreateWork([FromBody] ProvideWorkRequest request)
        {
            //判断request里是否满足前置条件
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var provider_id = Int32.Parse(User.Identity.Name);

            if (await UserAccessor.CheckRole(provider_id) == Role.Student)
            {
                return(BadRequest(new { message = "Student cannot create work" }));
            }
            if (request.week_day < 1 || request.week_day > 7)
            {
                return(BadRequest(new { message = "week day must between 1 to 7." }));
            }
            var work = _mapper.Map <WorkEntity>(request);

            work.teacher_id = provider_id;
            //work.work_time = "none"; //tobe delete

            // 计算工作总小时数total_time
            work.total_time = CalTotalTime(request.start_day, request.end_day, request.start_time, request.end_time, request.week_day);
            if (work.total_time == 0)
            {
                return(Ok("Duration time is 0."));
            }
            int work_id = await WorkAccessor.Create(work);

            if (work_id == 0)
            {
                return(Ok("Fail to create work."));
            }
            work.work_id = work_id;
            return(Ok(_mapper.Map <WorkResponse>(work)));
        }
コード例 #4
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));
        }