public async Task<Unit> Handle(UpdateCarCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Cars.FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Car), request.Id);
            }

            entity.Name = request.Name;
            entity.ShortDesc = request.ShortDesc;
            entity.Price = request.Price;
            entity.PriceSecond = request.PriceSecond;
            entity.PriceThird = request.PriceThird;
            entity.PriceFourth = request.PriceFourth;
            entity.Run = request.Run;
            entity.SeetsCount = request.SeetsCount;
            entity.Conditioner = request.Conditioner;
            entity.TankVolume = request.TankVolume;
            entity.ColorId = request.ColorId;
            entity.CarTypeId = request.CarTypeId;
            entity.TransmissionId = request.TransmissionId;

            await _context.SaveChangesAsync(cancellationToken);

            return Unit.Value;
        }
        public async Task <Guid> Handle(CreateCarCommand request, CancellationToken cancellationToken)
        {
            var entity = new Car
            {
                Name           = request.Name,
                ShortDesc      = request.ShortDesc,
                Price          = request.Price,
                PriceSecond    = request.PriceSecond,
                PriceThird     = request.PriceThird,
                PriceFourth    = request.PriceFourth,
                Run            = request.Run,
                SeetsCount     = request.SeetsCount,
                Available      = request.Available,
                Conditioner    = request.Conditioner,
                TankVolume     = request.TankVolume,
                ColorId        = request.ColorId,
                CarTypeId      = request.CarTypeId,
                TransmissionId = request.TransmissionId
            };

            _context.Cars.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#3
0
        public async Task <Guid> Handle(CreateRentCommand request, CancellationToken cancellationToken)
        {
            var entity = new Rent
            {
                IsConfirmed       = true,
                StartDataRend     = request.StartDataRend,
                FinishDataRend    = request.FinishDataRend,
                DataConfirmed     = DateTime.Now,
                Price             = request.Price,
                CarId             = request.CarId,
                LocationId        = request.LocationId,
                ApplicationUserId = request.ApplicationUserId
            };

            _context.Rents.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            var user = await _userManager.FindByIdAsync(request.ApplicationUserId);

            var car = await _context.Cars.FirstAsync(c => c.Id == request.CarId);

            _emailService.SendEmailAsync(user.Email, "Informtion About Rent",
                                         $"Thank you for rent! Your car is {car.Name}.Start date of rent is {request.StartDataRend}.Finish date of rent is {request.StartDataRend} .The cost of rent is {request.Price}$.");

            return(entity.Id);
        }
        public async Task <Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
        {
            var entity = await _userManager.FindByEmailAsync(request.Email);

            if (entity == null)
            {
                throw new NotFoundException(nameof(ApplicationUser), request.Id);
            }

            entity.FirstName   = (request.FirstName.Replace(" ", "").Substring(0, 1).ToUpper() + request.FirstName.Replace(" ", "").Substring(1).ToLower());
            entity.LastName    = (request.LastName.Replace(" ", "").Substring(0, 1).ToUpper() + request.LastName.Replace(" ", "").Substring(1).ToLower());
            entity.Email       = (request.Email).Replace(" ", "");
            entity.City        = (request.City.Replace(" ", "").Substring(0, 1).ToUpper() + request.City.Replace(" ", "").Substring(1).ToLower());
            entity.Street      = (request.Street.Replace(" ", "").Substring(0, 1).ToUpper() + request.Street.Replace(" ", "").Substring(1).ToLower());
            entity.PostalCode  = (request).PostalCode.Replace(" ", "");
            entity.PhoneNumber = request.PhoneNumber;

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
示例#5
0
        public async Task <Unit> Handle(DeleteCarCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Cars.FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Car), request.Id);
            }

            var hasOrders = _context.Cars.Any(od => od.Id == entity.Id);

            if (hasOrders)
            {
                throw new DeleteFailureException(nameof(Car), request.Id, "There are existing orders associated with this car.");
            }

            _context.Cars.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }