Пример #1
0
        internal void AddCarToDb(CarVM carToAdd)
        {
            Cars c = new Cars
            {
                RegNr       = carToAdd.RegNr,
                CarType     = carToAdd.CarType,
                Mileage     = carToAdd.Mileage,
                IsAvailable = true,
                TimesRented = 0,
                ToBeCleaned = false,
                ToBeRemoved = false,
                NeedService = false
            };

            context.Cars.Add(c);
            context.SaveChanges();
        }
Пример #2
0
        static void Main(string[] args)
        {
            MercuryContext mercury = new MercuryContext();

            //Product product = new Product()
            //{
            //    ProductName = "ETTAN",
            //    Price = 51.0m
            //};

            //mercury.Products.Add(product);
            //mercury.SaveChanges();


            var productToUpdate = mercury.Products
                                  .FirstOrDefault(o => o.ProductName.ToLower() == "ettan");

            //if(productToUpdate != null)
            //{
            //productToUpdate.Price *= 0.9m;
            //mercury.SaveChanges();
            //}

            bool done = false;

            while (!done)
            {
                HistoricalPrice hp = mercury
                                     .HistoricalPrices
                                     .FirstOrDefault(p => p.ProductsId == productToUpdate.Id);

                done = hp == null;

                if (!done)
                {
                    mercury.HistoricalPrices.Remove(hp);
                    mercury.SaveChanges();
                }
            }

            mercury.Products.Remove(productToUpdate);
            mercury.SaveChanges();
        }
Пример #3
0
        internal void BookCar(OrderVM newOrder)
        {
            var carToBook = context.Cars.First(c => c.Id == newOrder.CarId);

            Orders x = new Orders
            {
                CustomerId = context.Customers
                             .Where(c => c.Ssn == newOrder.Ssn)
                             .Select(c => c.CustomerId)
                             .FirstOrDefault(),
                CarId          = newOrder.CarId,
                PickUpDate     = newOrder.PickUpDate,
                ReturnDate     = newOrder.ReturnDate,
                CurrentMileage = carToBook.Mileage,
                IsReturned     = false,
                IsActive       = true,
            };

            carToBook.IsAvailable  = false;
            carToBook.TimesRented += 1;

            context.Orders.Add(x);

            HistoryLog y = new HistoryLog
            {
                CustomerId = x.CustomerId,
                CarId      = newOrder.CarId,
                Activity   = $"Kund {x.CustomerId} hyrde bil {newOrder.CarId}"
            };

            context.HistoryLog.Add(y);
            context.SaveChanges();
        }
        internal void CreateCustomer(CustomerVM newCustomer)
        {
            Customers x = new Customers();

            x.Ssn         = newCustomer.Ssn;
            x.FirstName   = newCustomer.FirstName;
            x.LastName    = newCustomer.LastName;
            x.Vipstatus   = 0;
            x.TimesRented = 0;
            x.MilesDriven = 0;

            context.Customers.Add(x);
            context.SaveChanges();
        }