//Uppdaterar Kunder public void UpdateCustomerAdress() { Console.WriteLine("Type the Customer ID for update"); int _Customer_ = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Type for Update Address"); string address = Console.ReadLine(); using (var context = new BicycleContext()) { var CustomerToBeUppdated = context.Customers.FirstOrDefault(b => b.Customer_Id == _Customer_); if (CustomerToBeUppdated != null) { CustomerToBeUppdated.Address = address; context.Update(CustomerToBeUppdated); context.SaveChanges(); UpdateCustomerAdress(); } if (CustomerToBeUppdated == null) { Console.Clear(); Console.WriteLine("You have entered an Id that doesn't exist, try again"); } } }
protected void Page_Load(object sender, EventArgs e) { string requestedID = Request.QueryString["id"]; if (!String.IsNullOrEmpty(requestedID) && int.TryParse(requestedID, out int bikeID)) { var db = new BicycleContext(); Bicycle bicycle = (from bike in db.Bicycles where bike.BicycleID == bikeID select bike).FirstOrDefault(); bicycle.Votes++; db.SaveChanges(); } else { Response.Redirect("404.aspx"); } Uri previousUri = Request.UrlReferrer; if (previousUri != null) { Response.Redirect(previousUri.ToString()); } else { Response.Redirect("BikeList.aspx"); } }
//private readonly IMapper _mapper; public StationService(BicycleContext db /*, IMapper mapper*/) { _db = db; Algorithm.BicycleStations = GetAllStations(); Algorithm.WayStations = GetAllRoutes(); //_mapper = mapper; }
//Hämtar information ifrån utvald tabell public Product GetProductById(int id) { using BicycleContext context = new BicycleContext(); var returnProduct = context.Products.FirstOrDefault(p => p.Product_id == id); Console.WriteLine("ID: " + returnProduct.Product_id + ", Name: " + returnProduct.BicycleDesign + ", Price: " + returnProduct.Price + ", TireSize: " + returnProduct.TireSize + ", NumberOfTires: " + returnProduct.NumberOfTires + ", Material: " + returnProduct.Material + ", Color: " + returnProduct.Colors_ID); return(returnProduct); }
public void AddOrder(int Quantity, DateTime OrderPlaced, DateTime?EndTime, int Costumer_Id, int Productid) { using (var context = new BicycleContext()) { var order = new Order(Quantity, OrderPlaced, EndTime, Costumer_Id, Productid); context.Orders.Add(order); context.SaveChanges(); } }
public IQueryable <Bicycle> GetBikes([QueryString("id")] int?categoryID) { var db = new BicycleContext(); IQueryable <Bicycle> query = db.Bicycles; if (categoryID != null && categoryID.HasValue) { query = from line in query where line.CategoryID == categoryID select line; } return(query); }
public IQueryable <Bicycle> GetOneBike([QueryString("BicycleID")] int?bicycleID) { var db = new BicycleContext(); if (bicycleID == null || !bicycleID.HasValue) { bicycleID = 1; } IQueryable <Bicycle> query = from line in db.Bicycles where line.BicycleID == bicycleID select line; return(query); }
//Gjort en lista på alla produkter som finns i databasen public void ProductsTable() { using (var result = new BicycleContext()) { List <Product> products = result.Products.ToList(); foreach (Product product in products) { Console.WriteLine($"Id: {product.Product_id}"); Console.WriteLine($"Design: {product.BicycleDesign}"); Console.WriteLine($"Price: {product.Price} "); Console.WriteLine($"TireSize: {product.TireSize}"); Console.WriteLine($"Material: {product.Material}"); Console.WriteLine($"NomerOfTiers: {product.NumberOfTires}"); Console.WriteLine($"Color: {product.Colors_ID}"); } } }
}// Tar bort Kunder public void RemoveCustomer() { Console.WriteLine("Enter the Customer ID you want to delete"); int customerIdToDelete = Convert.ToInt32(Console.ReadLine()); using (var context = new BicycleContext()) { var customerToDelete = context.Customers.Find(customerIdToDelete); if (customerToDelete == null) { Console.Clear(); Console.WriteLine("You have entered an Id that doesn't exist, try again"); RemoveCustomer(); } context.Customers.Remove(customerToDelete); context.SaveChanges(); } }
//Lägger till kunder public bool AddCustomer(string firstname, string lastName, string email, int phonenumber, string address, out int customerId) { using (var context = new BicycleContext()) { var CustomerAdd = new Customer(firstname, lastName, email, phonenumber, address); context.Customers.Add(CustomerAdd); if (CustomerAdd == null) { Console.Clear(); Console.WriteLine("Add Customer faild"); RemoveCustomer(); } context.SaveChanges(); customerId = CustomerAdd.Customer_Id; return(true); } customerId = 0; return(false); }// Tar bort Kunder
//private static IEnumerable<Product> ; public void ProductInformation() { //Using Bicyclecontext visar allt i min databas using BicycleContext context = new BicycleContext(); //Visar en specefik vara över 50000 kr var products = from product in context.Products where product.Price > 50000 orderby product.Product_id select product; foreach (Product p in products) { Console.WriteLine($"Id: {p.Product_id}"); Console.WriteLine($"Design: {p.BicycleDesign}"); Console.WriteLine($"Price: {p.Price} "); Console.WriteLine($"TireSize: {p.TireSize}"); Console.WriteLine($"Material: {p.Material}"); Console.WriteLine($"NomerOfTiers: {p.NumberOfTires}"); Console.WriteLine($"Color: {p.Colors_ID}"); } }
public void AddColorInformation() { using BicycleContext context = new BicycleContext(); Color Red = new Color() { ColorName = "Red" }; context.Add(Red); context.SaveChanges(); Color Gold = new Color() { ColorName = "Guld" }; context.Add(Gold); context.SaveChanges(); Color Black = new Color() { ColorName = "Black" }; context.Add(Black); context.SaveChanges(); Color Diamond = new Color() { ColorName = "diamond " }; context.Add(Diamond); context.SaveChanges(); }
//Meny för Customers public void CustomerMenu() { //Skriver information till tabellen för customer Console.WriteLine("First Name: "); string firstname = Console.ReadLine(); Console.WriteLine("Last Name: "); string lastname = Console.ReadLine(); Console.WriteLine("Email: "); string email = Console.ReadLine(); Console.WriteLine("Adress: "); string address = Console.ReadLine(); Console.WriteLine("Phonenumber: "); int phonenumber = Convert.ToInt32(Console.ReadLine()); //Lägger till costumer int customerId; if (Program.productmaneger.AddCustomer(firstname, lastname, email, phonenumber, address, out customerId)) { customerId = customerId; Console.WriteLine("Customer successfully added"); } using BicycleContext context = new BicycleContext(); Console.WriteLine("Press 1 to see the product options"); Console.WriteLine("Press 2 to se the most expensive bike to rent "); Console.WriteLine("Press 3 to rent a bike "); Console.WriteLine("Press 9 for EXIT"); string input1 = Console.ReadLine(); switch (input1) { case "1": Program.productmaneger.ProductsTable(); break; case "2": Program.productmaneger.ProductInformation(); break; case "3": Program.productmaneger.ProductsTable(); Console.WriteLine("What bike do you wanna rent, choose between 1-5 "); int Product_id = Convert.ToInt32(Console.ReadLine()); Program.ordermaneger.AddOrder(1, DateTime.Now, DateTime.Now.AddDays(10), customerId, Product_id); Console.WriteLine("du har nu hyrt " + Product_id); string product_id = Console.ReadLine(); break; case "9": Environment.Exit(0); break; } this.CustomerMenu(); }
public BicyclesController(BicycleContext context) { _context = context; }
//lägger till informartion i tabellerna public void Addinformarion() { using BicycleContext context = new BicycleContext(); Product BMX = new Product() { BicycleDesign = "BMX", Price = 15000, TireSize = "Small(18'')", NumberOfTires = "Two", Material = "Steel", Colors_ID = 1 }; context.Add(BMX); Product TreiningBike = new Product() { BicycleDesign = "Treining bike", Price = 500, TireSize = "Small(12'')", NumberOfTires = "Three", Material = "Plastic", Colors_ID = 2 }; context.Add(TreiningBike); Product TerrainBike = new Product { BicycleDesign = "Terrain bike", Price = 8999.99, TireSize = "Big(29'')", NumberOfTires = "Two", Material = "Steel", Colors_ID = 2 }; context.Add(TerrainBike); Product SportBike = new Product { BicycleDesign = " Sport bike", Price = 25000, TireSize = "Small(18'')", NumberOfTires = "Two", Material = "carbon fiber", Colors_ID = 3 }; context.Add(SportBike); Product WorldsBestBike = new Product { BicycleDesign = " Worlds best bike", Price = 99999.99, TireSize = "hovering", NumberOfTires = "Two", Material = "Diamond", Colors_ID = 4 }; context.Add(WorldsBestBike); context.SaveChanges(); }
public BicycleRepos() { _db = new BicycleContext(); _table = _db.Set <T>(); }