コード例 #1
0
        public IHttpActionResult Apply(ApplyLeaveCommand command)
        {
            CheckModelSate();

            var workingDays = WorkingDays.Query(new GetWorkingDays {
                EndDate = command.EndDate, StartDate = command.StartDate
            });

            if (workingDays <= 0)
            {
                throw new ApiException("Cannot apply for 0 working days");
            }

            var overlappedResult = OverlapWithApprovedLeaves.Query(new OverlapWithApprovedLeaves {
                StartDate = command.StartDate, EndDate = command.EndDate
            });

            if (overlappedResult.Overlaped)
            {
                throw new ApiException(string.Format("Overlapped with existing Leave: start at: {0}, end at: {1}", overlappedResult.OverlappedLeave.StartDate, overlappedResult.OverlappedLeave.EndDate));
            }

            command.UserName = User.Identity.Name;
            CommandSender.Send(command);
            return(Content(HttpStatusCode.OK, 0));
        }
コード例 #2
0
 public ToAppResponse OnApplyLeaveCommand(long id, ApplyLeaveCommand command)
 {
     _playerInfos.TryGetValue(id, out var player);
     if (player == null)
     {
         return(new ToAppResponse(null, StatusCodeDefines.PlayerNotInRoom, null));
     }
     PlayerStandup(player);
     return(new ToAppResponse());
 }
コード例 #3
0
        public async Task ShouldApplyLeave()
        {
            var leavePlanDto = await CreateLeavePlanAsync();

            var resourceLeave = await CreateResourceLeaveAsync(leavePlanDto.Id, resourceIdList[0]);

            var leaveTypeList = await GetLeaveTypeListAsync();

            var command = new ApplyLeaveCommand()
            {
                ResourceId   = resourceIdList[0],
                Description  = "test leave",
                Emergency    = false,
                LeaveTypeId  = leaveTypeList.Single(l => l.Name.Equals("Annual")).Id,
                StartDate    = DateTime.Now,
                EndDate      = DateTime.Now.AddDays(3),
                TotalApplied = 3
            };
            var leave = await SendAsync(command);

            var created = await ExecuteDbContextAsync(db => db.Leaves
                                                      //.Include(l => l.LeavePlanAssignments)
                                                      .SingleOrDefaultAsync(l => l.Id.Equals(leave.Id)));

            created.ShouldNotBeNull();
            created.Id.ShouldBe(leave.Id);
            created.ResourceId.ShouldBe(resourceIdList[0]);
            created.LeaveTypeId.ShouldBe(leaveTypeList.Single(l => l.Name.Equals("Annual")).Id);
            created.StartDate.Equals(command.StartDate);
            created.EndDate.Equals(command.EndDate);
            created.Status.Equals(LeaveStatus.Pending);
            created.Description.Equals(command.Description);
            created.StatusReason.ShouldBeNull();

            var resourceLeaveAssignmentsEntity = await ExecuteDbContextAsync(db =>
                                                                             db.ResourceLeaveAssignments
                                                                             .SingleOrDefaultAsync(l => l.LeaveType.Name.Equals("Annual"))
                                                                             );

            leave.RemainingLeaveCount.ShouldBe(resourceLeaveAssignmentsEntity.Amount);
        }