public ActionResult GetAllShippers() { var repository = new ShipperRepository(_context); return(Ok(repository.GetAll() .Select(r => new SelectItem(r.ShipperID.ToString(), r.ShipperID.ToString() + " - " + r.CompanyName)) .ToList())); }
public ActionResult Shippers() { List <Shipper> shippers = new List <Shipper>(); using (MySqlConnection conn = DBUtils.GetConnection()) { ShipperRepository repo = new ShipperRepository(conn); shippers = repo.GetAll().ToList <Shipper>(); } return(View(shippers)); }
public IEnumerable <SelectItem> GetAllShippers() { using (var context = new NorthwindDbContext(_options)) { ShipperRepository repository = new ShipperRepository(context); return(repository.GetAll() .Select(r => new SelectItem(r.ShipperID.ToString(), r.ShipperID.ToString() + " - " + r.CompanyName)) .ToList()); } }
public OrderBusinessLogic() { _repo = new OrderRepository(); _user = new UserRepository(); _detail = new OrderDetailRepository(); _product = new ProductRepository(); _country = new CountryRepository(); _city = new CityRepository(); _district = new DistrictRepository(); _message = new MessageBusinessLogic(); _shipper = new ShipperRepository(); }
public ActionResult Shipper(Int32 id) { Shipper shipper; using (MySqlConnection conn = DBUtils.GetConnection()) { ShipperRepository repo = new ShipperRepository(conn); shipper = repo.GetById(id.ToString()); } return(View(shipper)); }
public UnitOfWork() { _context = new northwindContext(); Categories = new CategoryRepository(_context); Customers = new CustomerRepository(_context); Employees = new EmployeeRepository(_context); OrderDetails = new OrderDetailRepository(_context); Orders = new OrderRepository(_context); Products = new ProductRepository(_context); Shippers = new ShipperRepository(_context); Suppliers = new SupplierRepository(_context); }
public IHttpActionResult SaveShipperOtherAddress(FrayteAddress shipperOtherAddress) { FrayteResult result = new ShipperRepository().SaveShipperOtherAddress(shipperOtherAddress); if (result != null && result.Status) { return(Ok()); } else { return(NotFound()); } }
public ActionResult CreateShipper(Shipper ship) { if (ModelState.IsValid) { using (MySqlConnection conn = DBUtils.GetConnection()) { ShipperRepository repo = new ShipperRepository(conn); repo.Save(ship); } return(RedirectToAction("Shippers")); } return(View(ship)); }
public ActionResult RemoveShipper(Administrators admin) { Shipper shipper = null; using (MySqlConnection conn = DBUtils.GetConnection()) { ShipperRepository repo = new ShipperRepository(conn); shipper = repo.GetById(admin.ShipperID.ToString()); if (shipper != null) { repo.Delete(shipper.ShipperID.ToString()); } } return(View("Administrator")); }
public IHttpActionResult DeleteShipper(int shipperId) { FrayteResult result = new FrayteResult(); result = new ShipperRepository().DeleteShipper(shipperId); if (result != null) { return(Ok(result)); } else { return(NotFound()); } }
public void AddShipper_GivenANewShipper_AddsToDatabase() { // arrange Mock <DbSet <Shipper> > mockSet = new Mock <DbSet <Shipper> >(); Mock <ShippingDb> mockContext = new Mock <ShippingDb>(); mockContext.Setup(c => c.Shippers).Returns(mockSet.Object); ShipperRepository sut = new ShipperRepository(mockContext.Object); Shipper shipper = new Shipper() { ID = 200 }; // act sut.AddShipper(shipper); // assert mockSet.Verify(s => s.Add(It.Is <Shipper>(a => a.ID == 200)), Times.Once()); mockContext.Verify(c => c.SaveChanges(), Times.Once()); }
public void GetAllShippers_Always_ReturnsTheWholeShipperRecordsFromDatabase() { // arrange List <Shipper> expected = new List <Shipper>(); expected.Add(new Shipper() { ID = 100 }); Mock <DbSet <Shipper> > mockSet = EntityMockFactory.CreateSet(expected.AsQueryable()); Mock <ShippingDb> mockContext = new Mock <ShippingDb>(); mockContext.Setup(c => c.Shippers).Returns(mockSet.Object); ShipperRepository sut = new ShipperRepository(mockContext.Object); // act var actual = sut.GetAllShippers(); // assert Assert.IsTrue(Equality.AreEqual(expected, actual)); }
public void GetShipper_GivenAValidName_ReturnsTheRecordFromDatabase() { // arrange List <Shipper> data = new List <Shipper>(); data.Add(new Shipper() { ID = 100, Name = "DHL" }); Mock <DbSet <Shipper> > mockSet = EntityMockFactory.CreateSet(data.AsQueryable()); Mock <ShippingDb> mockContext = new Mock <ShippingDb>(); mockContext.Setup(c => c.Shippers).Returns(mockSet.Object); ShipperRepository sut = new ShipperRepository(mockContext.Object); // act Shipper actual = sut.GetShipper("DHL"); // assert Assert.AreEqual(data[0], actual); }
public static void Main(string[] args) { ProductRepository productRepository = new ProductRepository(); CustomerRepository customerRepository = new CustomerRepository(); AdressRepository adressRepository = new AdressRepository(); OrderRepository orderRepository = new OrderRepository(); ShipperRepository shipperRepository = new ShipperRepository(); OrderProductRepository orderProductRepository = new OrderProductRepository(); #region address var listOfAddresses = new List <Adress>(); var address2 = new Adress { Address = "Trogatan", ZipCode = "60780", City = "Borås", Country = "Sweden" }; var address3 = new Adress { Address = "lillabrogatan", ZipCode = "50758", City = "Gothenburg", Country = "Sweden" }; var address4 = new Adress { Address = "storgatan", ZipCode = "50758", City = "Gothenburg", Country = "Sweden" }; var address5 = new Adress { Address = "Bilvägen", ZipCode = "50670", City = "Gothenburg", Country = "Sweden" }; var address6 = new Adress { Address = "trallgatan", ZipCode = "50758", City = "Borås", Country = "Sweden" }; var address7 = new Adress { Address = "nordsjövägen", ZipCode = "50890", City = "Gothenburg", Country = "Sweden" }; var address8 = new Adress { Address = "Bilvägen", ZipCode = "50758", City = "Gothenburg", Country = "Sweden" }; listOfAddresses.Add(address2); listOfAddresses.Add(address3); listOfAddresses.Add(address4); listOfAddresses.Add(address5); listOfAddresses.Add(address6); listOfAddresses.Add(address7); listOfAddresses.Add(address8); var address1 = new Adress { Address = "Trollvägen", ZipCode = "50560", City = "Gothenburg", Country = "Sweden", }; adressRepository.CreateAdress(address1); adressRepository.CreateAdresses(listOfAddresses); adressRepository.DeleteAdressById(8); var adresses = adressRepository.GetAllAdresses(); foreach (var adress in adresses) { Console.WriteLine(adress.Address + "\t" + adress.ZipCode + "\t" + adress.City + "\t" + adress.Country); } try { var addressesByZipCode = adressRepository.GetAdressesByZipCode("50758"); foreach (var adress in addressesByZipCode) { Console.WriteLine(adress.Address + "\t " + adress.ZipCode + "\t " + adress.City + " \t" + adress.Country); } } catch (ArgumentNullException argnull) { Console.WriteLine("Sorry zipcode dosent exist"); } #endregion #region product var listOfProducts = new List <Product>(); var product1 = new Product { ProductName = "Hutten Candleholder", Description = "Skultuna CandleHolder", Price = 1200 }; var product2 = new Product { ProductName = "Pillowcase Rox And Fix ", Description = "Designer Joseph Frank", Price = 900 }; var product3 = new Product { ProductName = "Pillowcase Hawai", Description = "Designer Joseph Frank", Price = 900 }; var product4 = new Product { ProductName = "Vase Dagg", Description = "Vase From Svensk Tenn", Price = 2800 }; var product5 = new Product { ProductName = "Vase Kotte", Description = "Vase From Svensk Tenn", Price = 800 }; listOfProducts.Add(product1); listOfProducts.Add(product2); listOfProducts.Add(product3); listOfProducts.Add(product4); listOfProducts.Add(product5); var product6 = new Product { ProductName = "Joseph Frank Pillowcase", Description = "Svensk Tenn", Price = 1500, }; productRepository.CreateProduct(product6); productRepository.CreateProducts(listOfProducts); product6.ProductName = "Nisse"; productRepository.UpdateProduct(product6); try { var product = productRepository.GetProductById(1); Console.WriteLine(product.ProductName); } catch (ArgumentNullException argNull) { Console.WriteLine("Sorry the product was not found!"); } catch (Exception e) { Console.WriteLine("Something very bad has happen, contact Emelie!"); } var products = productRepository.GetAllProducts(); foreach (var product in products) { Console.WriteLine(product.ProductName + " " + product.Price + "SEK"); } try { var products1 = productRepository.ProductNameStartWith("ca"); foreach (var product in products) { Console.WriteLine(product.ProductName); } } catch (ArgumentNullException argnull) { Console.WriteLine("Sorry the product was not found"); } #endregion #region customer var ListOfCustomers = new List <Customer>(); var customer1 = new Customer { FirstName = "Celine", LastName = "Wanna", PhoneNumber = "0735778990", Email = "*****@*****.**", AdressId = 1 }; var customer2 = new Customer { FirstName = "Estelle", LastName = "Wanna", PhoneNumber = "0728202020", Email = "*****@*****.**", AdressId = 2 }; ListOfCustomers.Add(customer1); ListOfCustomers.Add(customer2); var customer3 = new Customer { FirstName = "Sean", LastName = "Banan", PhoneNumber = "072866790", Email = "*****@*****.**", AdressId = 1, }; customerRepository.CreateCustomers(ListOfCustomers); customerRepository.CreateCustomer(customer3); var customer = customerRepository.GetCustomerById(1); Console.WriteLine(customer.Email); var customers = customerRepository.GetAllCustomers(); foreach (var c in customers) { Console.WriteLine(c.FirstName + " " + c.LastName); } #endregion #region shipper var listOfShippers = new List <Shipper>(); var shipper1 = new Shipper { Name = "Svensk Tenn Ab", AdressId = 4 }; var shipper2 = new Shipper { Name = "Design Online Ab", AdressId = 6 }; var shipper3 = new Shipper { Name = "Ellos Ab", AdressId = 5 }; listOfShippers.Add(shipper1); listOfShippers.Add(shipper2); listOfShippers.Add(shipper3); var shipper4 = new Shipper { Name = "Skultuna Ab", AdressId = 7, }; shipperRepository.CreateShippers(listOfShippers); shipperRepository.CreateShipper(shipper4); var shippers = shipperRepository.GetAllShippers(); foreach (var shipper in shippers) { Console.WriteLine(shipper.Name); } try { var shipperById = shipperRepository.GetShipperById(1); Console.WriteLine(shipperById.Name); } catch (ArgumentNullException argnull) { Console.WriteLine("Sorry the shipper was not found!"); } catch (Exception e) { Console.WriteLine("Something very bad has happen, contact Emelie!"); } #endregion #region order var ListOfOrders = new List <Order>(); var order1 = new Order { OrderDate = DateTime.Now, CustomerId = 1, ShipperId = 2, }; var order2 = new Order { OrderDate = DateTime.Now, CustomerId = 2, ShipperId = 1 }; ListOfOrders.Add(order1); ListOfOrders.Add(order2); var order3 = new Order { OrderDate = DateTime.Now, CustomerId = 3, ShipperId = 3, }; orderRepository.CreateOrders(ListOfOrders); orderRepository.CreateOrder(order3); var orderAsync = orderRepository.GetOrderById(2).Result; #endregion #region OrderProduct var order = new Order() { CustomerId = 1, OrderDate = DateTime.Now, ShipperId = 1, }; var product10 = new Product { ProductName = "Vase ", Description = "Vase From Svensk Tenn", Price = 2800 }; var product11 = new Product { ProductName = "Vase design", Description = "Vase From Svensk Tenn", Price = 1000 }; listOfProducts.Add(product10); listOfProducts.Add(product11); orderProductRepository.CreateOrderProduct(order, listOfProducts); orderProductRepository.ConnectProductsToOrder(1, new List <int> { 1, 2, 4 }); #endregion #region businessLogic var businessLogic = new BusinessLogic(); var city = "Borås"; var productId = 12; var customersByProductIdAndCity = businessLogic.GetCustomersByProductIdAndCity(city, productId); foreach (var customerByProductIdAndCity in customersByProductIdAndCity) { Console.WriteLine("Product with id: " + productId + " has been orderd by customer: " + customerByProductIdAndCity.FirstName + " " + customerByProductIdAndCity.LastName + "That lives in " + city); } #endregion Console.WriteLine("Do you want to drop database tables? (Y/N)"); var userInput = Console.ReadLine(); if (userInput.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine("Dropping table Orders."); var resultOrders = orderRepository.DropOrderTable().Result; Console.WriteLine("Order table was dropped:" + resultOrders + "rows where was removed"); Console.WriteLine("Dropping table Adresses."); var resultAdresses = adressRepository.DropAdressTable(); Console.WriteLine("Adresses table was dropped:" + resultAdresses + "rows where was removed"); Console.WriteLine("Dropping table Customers."); var resultCustomers = customerRepository.DropCustomerTable(); Console.WriteLine("Customers table was dropped:" + resultCustomers + "rows where was removed"); Console.WriteLine("Dropping table Products."); var resultProducts = productRepository.DropProductTable(); Console.WriteLine("Products table was dropped:" + resultProducts + "rows where was removed"); Console.WriteLine("Dropping table Shippers."); var result = shipperRepository.DropShipperTable(); Console.WriteLine("Shippers table was dropped:" + result + "rows where was removed"); } }
public IHttpActionResult UploadShippers() { List <FrayteShipperReceiver> frayteShippers = new List <FrayteShipperReceiver>(); var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { HttpFileCollection files = httpRequest.Files; HttpPostedFile file = files[0]; if (!string.IsNullOrEmpty(file.FileName)) { string connString = ""; string filename = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss_") + file.FileName; string filepath = HttpContext.Current.Server.MapPath("~/UploadFiles/" + filename); file.SaveAs(filepath); connString = new ShipmentRepository().getExcelConnectionString(filename, filepath); OleDbConnection oledbConn = new OleDbConnection(connString); try { oledbConn.Open(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn); OleDbDataAdapter oleda = new OleDbDataAdapter(); oleda.SelectCommand = cmd; DataSet ds = new DataSet(); oleda.Fill(ds, "Shippers"); var exceldata = ds.Tables[0]; if (exceldata != null && exceldata.Rows.Count > 0) { if (new ShipperRepository().CheckValidExcel(exceldata)) { frayteShippers = new ShipperRepository().GetShippers(exceldata); foreach (var shipper in frayteShippers) { FrayteResult result = new ShipperRepository().SaveShipper(shipper); } } else { return(BadRequest("Excel file not valid")); } } oledbConn.Close(); if ((System.IO.File.Exists(filepath))) { System.IO.File.Delete(filepath); } } catch { } finally { oledbConn.Close(); if ((System.IO.File.Exists(filepath))) { System.IO.File.Delete(filepath); } } } } return(Ok(frayteShippers)); }
public CheckoutController(UserManager <IdentityUser> userManager, CustomerRepository customerRepository, IHostEnvironment hostEnvironment, IConfiguration configuration, ShipperRepository shipperRepository, OrderRepository orderRepository) { _userManager = userManager; _customerRepository = customerRepository; _shipperRepository = shipperRepository; _orderRepository = orderRepository; _resourcePath = configuration.GetValue(Constants.WEBGOAT_ROOT, hostEnvironment.ContentRootPath); }
public ShipperBusinessLogic() { _repo = new ShipperRepository(); _user = new UserRepository(); _mess = new MessageRepository(); }
public ShipperController() { sRep = new ShipperRepository(); oRep = new OrderRepository(); }
public ShipperManager() { shipperRepository = new ShipperRepository(); }