Exemplo n.º 1
0
        public async Task <Unit> Handle(DeleteVacationTypeCommand request, CancellationToken cancellationToken)
        {
            var vacationtype = await VacationTypeRepository.Get(request.Id);

            if (vacationtype == null)
            {
                throw new ArgumentOutOfRangeException("Vacation Type does not exist.");
            }

            var employees = await EmployeeRepository.Select();

            if (employees.Any(e => e.GetVacations(DateTimeOffset.Now.Year).Any(v => v.VacationType.Equals(vacationtype))))
            {
                throw new ArgumentOutOfRangeException("Some employees has active vacations of this type.");
            }

            var vacationtypes = await VacationTypeRepository.Select();

            foreach (var type in vacationtypes.Where(e => e.Pool != null && e.Pool.Equals(vacationtype)))
            {
                type.UpdatePool(vacationtype.Pool, type.RowVersion);
                await VacationTypeRepository.Update(type);
            }

            await VacationTypeRepository.Delete(vacationtype);

            await Mediator.Publish(new VacationTypeDeletedEvent { Id = vacationtype.Id });

            return(await Unit.Task);
        }
        public async Task <Unit> Handle(UpdateVacationTypeCommand request, CancellationToken cancellationToken)
        {
            var vacationtype = await VacationTypeRepository.Get(request.Id);

            if (vacationtype == null)
            {
                throw new ArgumentOutOfRangeException("Vacation Type does not exist.");
            }

            var pool = await VacationTypeRepository.Get(request.PoolId.GetValueOrDefault(0));

            vacationtype.Update(request.Name, request.DefaultLeaveDays, request.IsPassing, pool, Convert.FromBase64String(request.Version));

            await VacationTypeRepository.Update(vacationtype);

            await Mediator.Publish(new VacationTypeUpdatedEvent { Id = vacationtype.Id });

            return(await Unit.Task);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit(VacationTypeVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var vacationType = _mapper.Map <VacationType>(model);
                var isSuccess    = await _repo.Update(vacationType);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong...");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something Went Wrong...");
                return(View(model));
            }
        }