Ejemplo n.º 1
0
        //[AllowAnonymous]
        public async Task <ActionResult <LeaveItemResponse> > ProViewLeaves([FromBody] ViewLeavesRequest request)
        {
            var pro_id = Int32.Parse(User.Identity.Name);

            if (await UserAccessor.CheckRole(pro_id) == Constants.Role.Student)
            {
                return(BadRequest(new { message = "ProViewLeaves is not for students." }));
            }

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

            leaves.pagenum   = request.pagenum;
            leaves.leavelist = new System.Collections.Generic.List <LeaveResponse>();

            var leave_list = await LeaveAccessor.ProViewLeaves(pro_id);

            if (leave_list != null)
            {
                for (int i = start; i < end && i < leave_list.total; i++)
                {
                    LeaveResponse lr = _mapper.Map <LeaveResponse>(leave_list.leaveItem[i]);
                    lr.student_name = await UserAccessor.GetUserName(lr.student_id);

                    lr.work_name = await WorkAccessor.GetWorkName(lr.work_id);

                    leaves.leavelist.Add(lr);
                }
                leaves.total = leave_list.total;
                return(Ok(leaves));
            }
            return(Ok(-1)); // Never arrive there
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <LeaveItemResponse> > ViewLeave([FromBody] ViewLeavesRequest request)
        {
            LeaveItemResponse LeaveItem = new LeaveItemResponse();

            LeaveItem.total     = 0;
            LeaveItem.pagenum   = request.pagenum;
            LeaveItem.leavelist = new List <LeaveResponse>();

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

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

            if (await UserAccessor.CheckRole(user_id) == Constants.Role.Provider)
            {
                return(BadRequest(new { message = "Providers cannot manage leave application." }));
            }
            var temp = await LeaveAccessor.ViewLeave(user_id);

            if (temp != null)
            {
                for (int i = 0; i < temp.total; i++)
                {
                    LeaveItem.total++;
                    if (i >= start && i <= end)
                    {
                        var list = await LeaveAccessor.Find(temp.leaveItem[i].leave_id);

                        LeaveResponse a = _mapper.Map <LeaveResponse>(list);

                        LeaveItem.leavelist.Add(a);
                    }
                }

                return(Ok(LeaveItem));
            }
            return(Ok(-1));
        }