Exemple #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            IRepo <Customer> repo = new SQLRepo <Customer>(new ModelContext());

            var customer = repo.FirstOrDefault(x => x.CustomId == CustomId);

            if (customer != null)
            {
                if (IsCreating)
                {
                    errors.Add(new ValidationResult("Customer with this Id already exists"));
                    return(errors);
                }
                Customer = customer;
            }
            else if (!IsCreating)
            {
                errors.Add(new ValidationResult("There is no customer with this id"));
                return(errors);
            }

            return(errors);
        }
        public void GetTicketsReturnsTicket()
        {
            SupportTicketDbContext ctx = GetTestDbContextScenario0();

            try
            {
                var repo   = new SQLRepo(ctx);
                var result = repo.GetTicket(1);
                Assert.IsType <Ticket>(result);
                result.ShouldDeepEqual(ctx.Tickets.FirstOrDefault());
            }
            finally
            {
                ctx.Database.EnsureDeleted();
            }
        }
        public void AddTicket()
        {
            SupportTicketDbContext ctx = GetTestDbContextScenario0();

            var newTicket = GetNewTicketStubEntity(999);

            try
            {
                var repo   = new SQLRepo(ctx);
                var result = repo.AddTicket(newTicket);
                Assert.IsType <Ticket>(result);
                result.ShouldDeepEqual(newTicket);
            }
            finally
            {
                ctx.Database.EnsureDeleted();
            }
        }
        public void UpdateTicketUpdatesSuccessfully()
        {
            SupportTicketDbContext ctx = GetTestDbContextScenario0();
            var          ticket        = ctx.Tickets.First();
            const string updatedValue  = "Problem Updated";

            try
            {
                var repo = new SQLRepo(ctx);
                ticket.Problem = updatedValue;
                var result = repo.UpdateTicket(ticket);
                Assert.IsType <Ticket>(result);
                result.ShouldDeepEqual(ctx.Tickets.FirstOrDefault());
            }
            finally
            {
                ctx.Database.EnsureDeleted();
            }
        }
Exemple #5
0
        public static IMovieRepo GetMovieRepo(string repoType)
        {
            IMovieRepo movieRepo = null;

            switch (repoType)
            {
            case "Azure":
                movieRepo = new AzureRepo();
                break;

            case "AWS":
                movieRepo = new AWSRepo();
                break;

            case "SQL":
                movieRepo = new SQLRepo();
                break;

            default:
                throw new ArgumentException("Invalid Repo Type");
            }
            return(movieRepo);
        }
Exemple #6
0
        public override bool IsValid(object value)
        {
            var reservation = value as QueryReservation;

            if (!reservation.IsCreating)
            {
                return(true);
            }
            if (value == null)
            {
                return(false);
            }

            IRepo <Customer> customerRepo = new SQLRepo <Customer>(new ModelContext());
            var customer = customerRepo.FirstOrDefault(x => x.CustomId == (int)reservation.CustomerId);

            if (customer == null)
            {
                this.ErrorMessage = "There is no customer with this id";
                return(false);
            }

            return(true);
        }
Exemple #7
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            ModelContext context = new ModelContext();

            IRepo <Reservation> reservationRepo = new SQLRepo <Reservation>(context);
            Reservation         reservation     = null;

            if ((bool)!IsCreating)
            {
                reservation = reservationRepo.Find(this.Id);
                if (reservation == null)
                {
                    errors.Add(new ValidationResult("There is no reservation with this id"));
                    return(errors);
                }
            }

            IRepo <Car>      carRepo = new SQLRepo <Car>(context);
            Func <Car, bool> predicate;

            if ((bool)IsCreating)
            {
                predicate = x => x.Plate == this.Plate;
            }
            else
            {
                predicate = x => x.Id == reservation.CarId;
            }
            var car = carRepo.FirstOrDefault(predicate);


            if ((bool)IsCreating)
            {
                if (car == null)
                {
                    errors.Add(new ValidationResult("There is no car with this plate"));
                    return(errors);
                }

                IRepo <Location> locationRepo = new SQLRepo <Location>(context);
                var location = locationRepo.Find(car.LocationId);
                if (location.Name != Location)
                {
                    errors.Add(new ValidationResult("This car is not available in this city"));
                    return(errors);
                }
            }

            var r = reservationRepo.FirstOrDefault(x => x.CarId == car.Id && (
                                                       StartDate >= x.StartDate && StartDate <= x.EndDate ||
                                                       EndDate >= x.StartDate && EndDate <= x.EndDate));

            if (r != null && (bool)IsCreating || ((bool)!IsCreating && r != null && r.Id != reservation.Id))
            {
                errors.Add(new ValidationResult(String.Format("Error. Car was rented from {0} to {1}",
                                                              r.StartDate.ToString("dd-MM-yyyy"), r.EndDate.ToString("dd-MM-yyyy"))));
                return(errors);
            }

            CarId       = car.Id;
            LocationId  = car.LocationId;
            Reservation = reservation;

            return(errors);
        }