Example #1
0
 public async Task <CarWash> ReadCarWash(int ID)
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         return(await Task.FromResult(db.CarWashes.Where (w => w.ID == ID).FirstOrDefault()));
     }
 }
Example #2
0
 public async Task <List <CarWash> > CarWashGetAll()
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         return(await Task.FromResult(db.CarWashes.ToList()));
     }
 }
Example #3
0
 public async Task <List <CarWash> > CarWashGetAll(string search)
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         return(await Task.FromResult(db.CarWashes.Where (w => w.Name.Contains(search)).ToList()));
     }
 }
Example #4
0
        public async Task <Dictionary <int, string> > AvailibleTimes(int carWashID, DateTime AtDate)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var result = await Task.FromResult(db.WashBookings.Where(w => w.CarWashID == carWashID && w.Booking.Date == AtDate.Date).Select(s => s.Booking).ToList());

                var availibleMinutes = new Dictionary <int, string>();
                var selectedMin      = new List <int>();
                result.ForEach(f => selectedMin.Add(f.Hour * 60 + f.Minute));
                // TODO  forretningslogik,! Husk at flytte !!!
                for (int hour = 0; hour < 24; hour++)
                {
                    for (int min = 0; min < 60; min += 20)
                    {
                        var val = hour * 60 + min;
                        if (selectedMin.Contains(val))
                        {
                            continue;
                        }

                        availibleMinutes.Add(val, $"{hour}:{min:d2}");
                    }
                }
                return(availibleMinutes);
            }
        }
Example #5
0
 public async Task <List <WashBooking> > GetAllBookings(int year, int month, int washHallID)
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         return(await Task.FromResult(db.WashBookings.Where(w => w.Booking.Year == year && w.Booking.Month == month).ToList()));
     }
 }
Example #6
0
 public async Task <List <DateTime> > Reserved(int carWashID, DateTime AtDate)
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         return(await Task.FromResult(db.WashBookings.Where(w => w.CarWashID == carWashID && w.Booking.Date == AtDate.Date ).Select(s => s.Booking).ToList()));
     }
 }
Example #7
0
        public async Task   DeleteCarWash(CarWash carWash)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var result = await Task.FromResult(db.CarWashes.Remove(carWash));

                var saved = await Task.FromResult(db.SaveChanges());
            }
        }
Example #8
0
        public void AddCarWash(CarWash carWash)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                db.CarWashes.Add(carWash);

                db.SaveChanges();
            }
        }
Example #9
0
        public async Task <Dictionary <string, int> > GetStatistik(DateTime FromDate, DateTime ToDate)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var result = await Task.FromResult(db.WashBookings.Where(w => w.Booking >= FromDate && w.Booking <= ToDate).GroupBy(g => g.CarWash.Name).ToDictionary(g => g.Key, g => g.Count()));

                return(result);
            }
        }
Example #10
0
        public async Task <CarWash> LatestCarWash(Guid UserID)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var result = await Task.FromResult(db.WashBookings.Where(w => w.UserID == UserID).OrderByDescending(o => o.Booking).FirstOrDefault());

                return(result?.CarWash ?? null);
            }
        }
Example #11
0
 public WashBooking AddBooking(WashBooking booking)
 {
     using (var db = new CarWashBookingDbContext(_context))
     {
         db.WashBookings.Add(booking);
         db.SaveChanges();
         return(booking);
     }
 }
Example #12
0
        public async Task <List <WashBooking> > GetUserBookings(Guid userID)
        {
            var now = DateTime.Now;

            using (var db = new CarWashBookingDbContext(_context))
            {
                // TODO >= now. Er det ikke forretningslogik! overfør som argument.
                return(await Task.FromResult(db.WashBookings.Where(w => w.UserID == userID && w.Booking >= now).ToList()));
            }
        }
Example #13
0
        public async Task <Dictionary <int, string> > SearchCarWash(string search)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var searchResult = new Dictionary <int, string>();
                var result       = await Task.FromResult(db.CarWashes.Where(w => w.Name.StartsWith(search)).Select(s => new { s.ID, s.Name }).Take(5).ToList());

                foreach (var item in result)
                {
                    searchResult.Add(item.ID, item.Name);
                }
                return(searchResult);
            }
        }
Example #14
0
        public async Task SaveCarWash(CarWash carWash)
        {
            using (var db = new CarWashBookingDbContext(_context))
            {
                var result = await Task.FromResult(db.CarWashes.Where(w => w.ID == carWash.ID).FirstOrDefault());

                if (result != null)
                {
                    result.Adresse = carWash.Adresse;
                    result.Name    = carWash.Name;
                    result.Image   = carWash.Image;
                    db.SaveChanges();
                }
            }
        }