예제 #1
0
        public IResult AddOrEdit(Rental entity)
        {
            try
            {
                if (entity.Id == 0)
                {
                    bool result = _dal.Any(r => r.CarId == entity.CarId && r.ReturnDate == null);
                    if (!result)
                    {
                        _dal.Add(entity);
                        return(new SuccessResult(Messages.Added));
                    }

                    return(new ErrorResult(Messages.CarError));
                }
                else
                {
                    _dal.Update(entity);
                    return(new SuccessResult(Messages.Updated));
                }
            }
            catch (Exception e)
            {
                return(new ErrorResult(Messages.Error + e.Message));
            }
        }
예제 #2
0
        private IResult IsCarAvaliable(int carId)
        {
            var result = _rentalDal.Any(x => x.CarId == carId && (x.ReturnDate == null || x.ReturnDate <= DateTime.Now));

            if (result)
            {
                return(new ErrorResult(Messages.CarIsNotAvaliable));
            }
            return(new SuccessResult());
        }
예제 #3
0
        public IResult IsCarAvaliable(int carId)
        {
            var result = _rentalDal.Any(r => r.CarId == carId && (r.ReturnDate == null || r.ReturnDate < DateTime.Now));

            if (result)
            {
                return(new ErrorResult("Araba Kiralanmaya uygun değil"));
            }
            return(new SuccessResult());
        }
예제 #4
0
        public IResult Add(Rental rental)
        {
            var result = _rentalDal.Any(r => r.CarId == rental.CarId && r.ReturnDate == null);

            if (!result)
            {
                _rentalDal.Add(rental);
                return(new SuccessResult(Messages.Rental.Add()));
            }
            return(new ErrorResult(Messages.Error()));
        }
예제 #5
0
        public IResult Add(RentalDetailDto rentalDto)
        {
            var result = _rentalDal.Any(r => r.CarId == rentalDto.CarId && (r.ReturnDate == null || r.ReturnDate >= rentalDto.RentDate));

            if (!result)
            {
                var rental = _mapper.Map <Rental>(rentalDto);
                _rentalDal.Add(rental);
                return(new SuccessResult(Messages.Rental.Add()));
            }
            return(new ErrorResult(Messages.Rental.Exists()));
        }
예제 #6
0
 private IResult CheckRentals(Rental rental)
 {
     if (!_dal.Any(r => r.CarId == rental.CarId && (r.ReturnDate == null || r.ReturnDate > DateTime.UtcNow)))
     {
         return(new SuccessResult());
     }
     return(new ErrorResult());
 }
예제 #7
0
        public IResult Add(Rental rental)
        {
            var result = _rentalDal.Any(p => p.CarId == rental.CarId && (p.ReturnDate == null || p.ReturnDate > DateTime.Now));

            if (result)
            {
                return(new ErrorResult("Araba hala kullanılıyor"));
            }

            _rentalDal.Add(rental);
            return(new SuccessResult("Araba Eklendi"));
        }