Beispiel #1
0
        public async Task <ActionResult <LeaveResponse> > ViewLeave([FromBody] ViewLeavesRequest request)
        {
            ViewLeaveResponse LeaveItem = new ViewLeaveResponse();

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

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

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

            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);

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

                        LeaveItem.leavelist.Add(a);
                    }
                }

                return(Ok(LeaveItem));
            }
            return(Ok(-1));
        }
Beispiel #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));
        }