Beispiel #1
0
        public async Task <Unit> Handle(WorkerUpdateCommand request, CancellationToken cancellationToken)
        {
            var worker = await _workerRepository.GetAsync(request.Id);

            worker.Update(
                request.FirstName,
                request.LastName,
                request.Birthday,
                request.CityOfBirthday,
                request.Pesel,
                request.DocumentType,
                request.DocumentNumber,
                request.Gender,
                request.Street,
                request.PropertyNumber,
                request.ApartmentNumber,
                request.ZipCode,
                request.City,
                request.Country,
                request.ActNumber,
                request.MotherName,
                request.FatherName,
                request.Phone
                );
            await _workerRepository.UpdateAsync(worker);

            return(Unit.Value);
        }
Beispiel #2
0
        public async Task HandleAsync(DeleteWorker command)
        {
            var worker = await _workerRepository.GetAsync(command.WorkerID);

            if (worker == null)
            {
                throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie można znaleźć pracownika w bazie danych");
            }

            if (worker.Active == false)
            {
                throw new ServiceException(ErrorCodes.BładUsuwania, $"Nie można zwolnić pracownika, gdyż został już zwolniony wcześniej");
            }

            var teamIDs = _context.WorkerTeam.AsNoTracking().Where(x => x.WorkerID == command.WorkerID).Select(y => y.TeamID).ToList();

            foreach (var teamID in teamIDs)
            {
                var ordersID = _context.OrderTeam.AsNoTracking().Where(x => x.TeamID == teamID).Select(y => y.OrderID).ToList();

                foreach (var orderID in ordersID)
                {
                    var order = await _orderRepository.GetAsync(orderID);

                    if (!order.Paid)
                    {
                        throw new ServiceException(ErrorCodes.BładUsuwania, $"Nie można zwolnić pracownika, ponieważ pracuje on w przynajmniej jednym aktywnym zleceniu");
                    }
                }
            }

            worker.Active = false;

            await _workerRepository.UpdateAsync(worker);
        }
        public async Task <IActionResult> Workers(Guid id)
        {
            var worker = _mapper.Map <WorkerDTO>(await _workerRepository.GetAsync(id));

            if (worker == null)
            {
                throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie można znaleźć pracownika w bazie danych");
            }

            return(new JsonResult(worker));
        }
Beispiel #4
0
        public async Task HandleAsync(PayOrder command)
        {
            if (command == null)
            {
                throw new ServiceException(ErrorCodes.PustyRequest, "Post request add/payment is empty");
            }

            var order = await _orderRepository.GetAsync(command.Order.OrderID);

            if (order == null)
            {
                throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie znaleziono zlecenia w bazie danych");
            }

            foreach (var teamID in command.Order.Teams)
            {
                var team = await _teamRepository.GetAsync(teamID.TeamID);

                if (team == null)
                {
                    throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie znaleziono zespołu w bazie danych");
                }

                var workers = (await _context.WorkerTeam.ToListAsync()).Where(x => x.TeamID == team.TeamID).ToList();

                if (!workers.Any())
                {
                    throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie znaleziono pracowników w bazie danych");
                }

                foreach (var ele in workers)
                {
                    var worker = await _workerRepository.GetAsync(ele.WorkerID);

                    var days = DaysWithoutWeekends.Count(order.StartDate, (DateTime)order.EndDate);

                    var payment = new Payment
                    {
                        OrderID     = command.Order.OrderID,
                        WorkerID    = worker.WorkerID,
                        Amount      = worker.ManHour * 8 * days,
                        PaymentDate = DateTime.UtcNow,
                        PaymentID   = Guid.NewGuid()
                    };

                    await _paymentRepository.AddAsync(payment);
                }
            }

            order.Paid = true;
            await _orderRepository.UpdateAsync(order);
        }
        public async Task HandleAsync(EditWorker command)
        {
            if (command.Worker == null)
            {
                throw new ServiceException(ErrorCodes.PustyRequest, "Post request edit/worker is empty");
            }

            var workerFromDB = await _workerRepository.GetAsync(command.Worker.WorkerID);

            if (workerFromDB == null)
            {
                throw new ServiceException(ErrorCodes.Nieznaleziono, $"Nie można znaleźć pracownika w bazie danych");
            }

            await _workerRepository.UpdateAsync(_mapper.Map <Core.Models.Worker>(command.Worker));
        }
Beispiel #6
0
        public async Task <WorkerDetailDto> Handle(WorkerDetailQuery request, CancellationToken cancellationToken)
        {
            var worker = await _workerRepository.GetAsync(new Guid(request.Guid.ToByteArray()));

            return(_mapper.Map <Worker, WorkerDetailDto>(worker));
        }