public async Task <Result> Handle(UpdateLeaveCommand request, CancellationToken cancellationToken)
        {
            var entity = _context.LeaveRequests.FirstOrDefault(x => x.Id == request.LeaveId);

            if (entity == null)
            {
                return(Result.Success("İzin bulunamadı."));
            }

            if (request.Approve && entity.LeaveStatus == LeaveStatus.Approved)
            {
                return(Result.Success("Onaylı İzin onaylanamaz."));
            }


            if (request.Approve)
            {
                entity.LeaveStatus = LeaveStatus.Approved;
                entity.Description = request.Description;
            }
            else
            {
                entity.LeaveStatus = LeaveStatus.Rejected;
                entity.Description = request.Description;
            }

            _context.LeaveRequests.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            if (entity.LeaveStatus == LeaveStatus.Approved)
            {
                await _leaveService.ApproveLeave(entity.Id, entity.LeaveDay, cancellationToken);

                _notificationService.SendNotification(entity.EmployeeId, "İzin onaylandı.");
            }
            else
            {
                var rejectedMessage = string.Format("Yönetici izininizi reddetti. Nedeni ise : {0}", request.Description);
                _notificationService.SendNotification(entity.EmployeeId, rejectedMessage);
            }

            return(Result.Success(entity.Id));
        }
示例#2
0
        public async Task <Result> Handle(CreateLeaveCommand request, CancellationToken cancellationToken)
        {
            var leaveRequestResult = await _leaveService.CheckLeave(request);

            if (!leaveRequestResult.CanUseLeave)
            {
                return(Result.Failure("İzin bulunamadı."));
            }

            if (leaveRequestResult.LeaveCount == 0)
            {
                return(Result.Failure("Bu tarihte izin kullanılmasına gerek yok."));
            }

            var entity = new LeaveRequest
            {
                LeaveDay    = leaveRequestResult.LeaveCount,
                EmployeeId  = request.EmployeeId,
                LeaveType   = request.LeaveType,
                LeaveStatus = CalculateLeaveStatus(request, leaveRequestResult)
            };

            _context.LeaveRequests.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            if (entity.LeaveStatus == LeaveStatus.Approved)
            {
                await _leaveService.ApproveLeave(leaveRequestResult.Id, leaveRequestResult.LeaveCount, cancellationToken);

                _notificationService.SendNotification(request.EmployeeId, "İzin onaylandı.");
            }
            else
            {
                _notificationService.SendNotification(request.EmployeeId, "İzin Yönetici onayında.");
            }

            return(Result.Success(entity.Id));
        }
示例#3
0
        public async Task <IActionResult> Approve(int id)
        {
            await _service.ApproveLeave(id, User);

            return(View(nameof(MyApprovals)));
        }