Exemplo n.º 1
0
        public Task <bool> Handle(UpdateApartment request, CancellationToken cancellationToken)
        {
            var currentApartment = _apartmentRepository.GetApartmentWithResidents(request.Id);

            if (currentApartment == null)
            {
                Mediator.RaiseNotification(new DomainNotification(nameof(Apartment), "Apartamento não existe", NotificationType.Error));

                return(Task.FromResult(false));
            }

            currentApartment.UpdateApartment(User.GetUserId(), request.Number, request.Block, request.Roof, request.CondominiumId);

            if (!IsAValidApartment(currentApartment))
            {
                return(Task.FromResult(false));
            }

            _apartmentRepository.Update(currentApartment);

            if (Commit())
            {
                Mediator.RaiseNotification(new DomainNotification(nameof(Apartment), "Operação realizada com sucesso", NotificationType.Info));

                return(Task.FromResult(true));
            }

            Mediator.RaiseNotification(new DomainNotification(nameof(Apartment), "Erro ao realizar a operação", NotificationType.Error));

            return(Task.FromResult(false));
        }
        public IActionResult UpdateApartment(UpdateApartment viewAapartment)
        {
            var updatedApartment = Mapper.Map <IApartment>(viewAapartment);

            var existingApartment = Repository.Apartments.FindById(updatedApartment.Id);

            existingApartment.Address        = updatedApartment.Address;
            existingApartment.Coordinates    = updatedApartment.Coordinates;
            existingApartment.Title          = updatedApartment.Title;
            existingApartment.Description    = updatedApartment.Description;
            existingApartment.CostPerNight   = updatedApartment.CostPerNight;
            existingApartment.SleepingPlaces = updatedApartment.SleepingPlaces;
            existingApartment.RoomAmount     = updatedApartment.RoomAmount;

            Repository.Apartments.Modify(existingApartment);
            Repository.Save();

            var apartmentFacilities = new ApartmentFacilities
            {
                ApartmentId = updatedApartment.Id,
                Facilities  = Enum.GetNames(typeof(Models.Intefaces.Facility))
                              .Select(a => new Views.ViewModels.ApartmentModels.Facility
                {
                    Title = a,
                })
            };

            return(View("AddFacilities", apartmentFacilities));
        }
Exemplo n.º 3
0
        Task <OneOf <Success, NotFound> > IRequestHandler <UpdateApartment, OneOf <Success, NotFound> > .Handle(UpdateApartment request, CancellationToken cancellationToken)
        {
            var apt = request.Apartment;

            apt.SetId(request.ApartmentId);
            return(this.apartmentRepository.Update(apt, cancellationToken));
        }