public ActionResult Details(String id) { CustomerModel cusModel = null; try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { cusModel = Mapper.CustomerEntityToModel(customer); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return View(cusModel); }
public ActionResult Search(String query) { List <Customer> customers = null; try { using (var dbContext = new NORTHWNDContext()) { if (query == null) { customers = dbContext.Customers.ToList(); } else { customers = dbContext.Customers.Where(o => o.ContactTitle == query || o.CompanyName == query || o.ContactName == query).ToList(); if (customers == null) { throw new Exception("Customer resutrn null"); } } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return(View(customers)); }
public ActionResult Details(String id) { CustomerModel cusModel = null; try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { cusModel = Mapper.CustomerEntityToModel(customer); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return(View(cusModel)); }
public ActionResult Delete(String id) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { dbContext.Customers.Remove(customer); dbContext.SaveChanges(); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return RedirectToAction("Index", "Default"); }
public static void SelectSimple() { // select *from Employees NORTHWNDContext dataContext = new NORTHWNDContext(); var employeeQry = dataContext.Employees.Select(s => s).AsQueryable(); var output = employeeQry.ToList(); }
public IActionResult Index() { NORTHWNDContext northWindcontext = new NORTHWNDContext(); var jsonCustomerDetail = northWindcontext.Customers.ToList(); return(new JsonResult(jsonCustomerDetail)); }
public EfRepository(NORTHWNDContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } this.Context = context; this.DbSet = this.Context.Set <TEntity>(); }
protected void Dispose(bool disposing) { if (disposing) { if (_context != null) { _context.Dispose(); _context = null; } } }
public static void CustomersWithNamesLongerThan25Characters() { using (var db = new NORTHWNDContext()) { Console.Clear(); Console.WriteLine("Company name longer than 25 characters\n---------------------------------"); var select = db.Customers.Where(x => x.CompanyName.Length > 25).Select(x => x.CompanyName); foreach (var companyName in select) { Console.WriteLine(companyName); } } }
public static void Register(HttpConfiguration config) { using (var context = new NORTHWNDContext()) { config.EnableCors(new EnableCorsAttribute("*", "*", "*", "DataServiceVersion, MaxDataServiceVersion")); config.Routes.MapODataRoute( routeName: "odata", routePrefix: "", model: context.GetEdm(), batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer) ); } }
public ActionResult Create(CustomerModel cusModel) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = Mapper.CustomerModelToEntity(cusModel); dbContext.Customers.Add(customer); dbContext.SaveChanges(); } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return(RedirectToAction("Index", "Default")); }
public NORTHWNDContextTest() { IConfiguration configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true) .Build(); // configure our database var connection = configuration.GetConnectionString("ConnectionString"); var options = new DbContextOptionsBuilder <NORTHWNDContext>() .UseSqlServer(connection) .Options; DbContext = new NORTHWNDContext(options); // begin the transaction Transaction = DbContext.Database.BeginTransaction(); }
public ActionResult Create(CustomerModel cusModel) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = Mapper.CustomerModelToEntity(cusModel); dbContext.Customers.Add(customer); dbContext.SaveChanges(); } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return RedirectToAction("Index", "Default"); }
static void Main(string[] args) { var ctx = new Context(); ctx.Database.EnsureCreated(); ctx.Zajecias.Add(new Zajecia() { Nazwa = "P4", IloscObecnych = 15, Sala = "B316" }); ctx.SaveChanges(); // foreach (var item in ctx.Zajecias) // { // Console.WriteLine(item.Nazwa); // } using var northwindContext = new NORTHWNDContext(); var ukClients = northwindContext.Customers.Where(x => x.Country == "UK"); foreach (var item in ukClients) { Console.WriteLine(item.CompanyName); } }
//public ActionResult Search() //{ // return View(); //} public JsonResult GetCostumers(String query, String type) { List <Customer> customers = null; try { using (var dbContext = new NORTHWNDContext()) { customers = dbContext.Customers.ToList(); } } catch (Exception ex) { throw new ArgumentException(ex.Message); } //List<Customer> customers = null; //try //{ // using (dbContext = new NORTHWNDContext()) // { // customers = dbContext.Customers.Where(o => o.ContactTitle == query).ToList(); // if (customers == null) // { // throw new Exception("Customer resutrn null"); // } // } //} //catch (Exception ex) //{ // throw new ArgumentException(ex.Message); //} return(Json(customers, JsonRequestBehavior.AllowGet)); }
public OrdersViewModel(NORTHWNDContext data, bool showDiscontinued) { base.DisplayName = showDiscontinued ? "Discontinued" : "Edit Orders"; Cities = new CollectionViewSource() { Source = data.Cities }.View; // Define a live view of orders filtered by Customer on the server, // containing order details Orders = from ord in data.Orders.AsFiltered(o => o.Customer != null) .AsFilteredBound(o => o.Customer.City).BindFilterKey(Cities, "CurrentItem") .Include("Customer").Include("Order_Details.Product") let orderDetails = from od in ord.Order_Details.AsLive() where !showDiscontinued || od.Product.Discontinued // show only discontinued products if showDiscontinued==true select new OrderDetailViewModel() { OrderID = ord.OrderID, ProductID = od.ProductID, ProductName = od.Product.ProductName, Quantity = od.Quantity, UnitPrice = od.UnitPrice, Discount = (decimal)od.Discount, TotalCost = od.Quantity * od.UnitPrice * (1m - (decimal)od.Discount) } where orderDetails.Count() != 0 // filter out orders without details select new OrderViewModel() { OrderID = ord.OrderID, OrderDate = ord.OrderDate, CustomerName = ord.Customer.CompanyName + " (" + ord.Customer.CustomerID + ", " + ord.Customer.City + ")", TotalCost = orderDetails.Sum(od => od.Quantity * od.UnitPrice * (1m - od.Discount)), // Order cost is the sum of order detail costs. OrderDetails = orderDetails }; }
public ActionResult Delete(String id) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { dbContext.Customers.Remove(customer); dbContext.SaveChanges(); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return(RedirectToAction("Index", "Default")); }
private static void CustomersWithNamesLongerThan25Characters() { using (NORTHWNDContext cx = new NORTHWNDContext()) { //using (NorthwindContext cx = new NorthwindContext()) //{ // foreach (var supplier in cx.Suppliers) // { // if (supplier.Products.Count > 3) // { // Console.WriteLine(supplier.CompanyName); // } // } //} foreach (var name in cx.Customers) { if (name.CompanyName.Length > 25) { Console.WriteLine(name.CompanyName); } } } }
public ActionResult Edit(CustomerModel cusModel) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == cusModel.CustomerID).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { customer = Mapper.UpdateCustomerModelToEntity(customer, cusModel); dbContext.SaveChanges(); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return(RedirectToAction("Index", "Default")); }
public CustomerRepository(NORTHWNDContext context) : base(context) { }
public UserRepository(NORTHWNDContext context) : base(context) { }
public OrderDetailsRepository(NORTHWNDContext context) : base(context) { }
//public ActionResult Search() //{ // return View(); //} public JsonResult GetCostumers(String query, String type) { List<Customer> customers = null; try { using (var dbContext = new NORTHWNDContext()) { customers = dbContext.Customers.ToList(); } } catch (Exception ex ) { throw new ArgumentException(ex.Message); } //List<Customer> customers = null; //try //{ // using (dbContext = new NORTHWNDContext()) // { // customers = dbContext.Customers.Where(o => o.ContactTitle == query).ToList(); // if (customers == null) // { // throw new Exception("Customer resutrn null"); // } // } //} //catch (Exception ex) //{ // throw new ArgumentException(ex.Message); //} return Json(customers, JsonRequestBehavior.AllowGet); }
public void Add(T entity) { Context.Set <T>().Add(entity); Context.SaveChanges(); Context = new NORTHWNDContext(); }
public CategoriesController(NORTHWNDContext context) { _context = context; }
public static void MigrateNorthwindData(NORTHWNDContext oldContext, ApplicationDbContext newContext) { AccountabilityType customerType = new AccountabilityType { Description = "Customers" }; AccountabilityType employeeType = new AccountabilityType { Description = "Employees" }; AccountabilityType shipperType = new AccountabilityType { Description = "Shippers" }; AccountabilityType supplierType = new AccountabilityType { Description = "Suppliers" }; if (!newContext.AccountabilityTypes.Any()) { //accountabilitytypes newContext.AccountabilityTypes.Add(customerType); newContext.AccountabilityTypes.Add(employeeType); newContext.AccountabilityTypes.Add(shipperType); newContext.AccountabilityTypes.Add(supplierType); newContext.SaveChanges(); } if (!newContext.Parties.Any()) { Party northwind = new Party() { Name = "Northwind" }; newContext.Parties.Add(northwind); newContext.SaveChanges(); foreach (var shipper in oldContext.Shippers.ToList()) { Party party = new Party() { Name = shipper.CompanyName }; newContext.Parties.Add(party); newContext.Accountabilities.Add(new Accountability() { Accountable = party, Commissioner = northwind, AccountabilityType = shipperType }); } foreach (var customer in oldContext.Customers.ToList()) { Party party = new Party() { Name = customer.CompanyName }; newContext.Parties.Add(party); newContext.Accountabilities.Add(new Accountability() { Accountable = northwind, Commissioner = party, AccountabilityType = customerType }); } foreach (var supplier in oldContext.Suppliers.ToList()) { Party party = new Party() { Name = supplier.CompanyName }; newContext.Parties.Add(party); newContext.Accountabilities.Add(new Accountability() { Accountable = party, Commissioner = northwind, AccountabilityType = supplierType }); } foreach (var employee in oldContext.Employees.ToList()) { Party party = new Party() { Name = $"{ employee.FirstName } { employee.LastName }" }; newContext.Parties.Add(party); newContext.Accountabilities.Add(new Accountability() { Accountable = party, Commissioner = northwind, AccountabilityType = employeeType }); } newContext.SaveChanges(); } }
public SupplierRepository(NORTHWNDContext context) : base(context) { }
public List <Product> Get() { var ProductsQry = new NORTHWNDContext().Products.AsQueryable().ToList(); return(ProductsQry); }
public ActionResult Edit(CustomerModel cusModel) { try { using (var dbContext = new NORTHWNDContext()) { Customer customer = dbContext.Customers.Where(o => o.CustomerID == cusModel.CustomerID).First(); if (customer == null) { ViewBag.ErrorMessage = "User was not found"; } else { customer = Mapper.UpdateCustomerModelToEntity(customer, cusModel); dbContext.SaveChanges(); } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return RedirectToAction("Index", "Default"); }
public ProductRepository(NORTHWNDContext dbcontext) : base(dbcontext) { }
public OrdersController(NORTHWNDContext context) { _context = context; }
public CategoryController(NORTHWNDContext DBContext) { this.DBContext = DBContext; }
public void Delete(T entity) { Context.Set <T>().Remove(entity); Context.SaveChanges(); Context = new NORTHWNDContext(); }
public ActionResult Search(String query) { List<Customer> customers = null; try { using (var dbContext = new NORTHWNDContext()) { if (query == null) { customers = dbContext.Customers.ToList(); } else { customers = dbContext.Customers.Where(o => o.ContactTitle == query || o.CompanyName == query || o.ContactName == query).ToList(); if (customers == null) { throw new Exception("Customer resutrn null"); } } } } catch (Exception ex) { throw new ArgumentException(ex.Message); } return View(customers); }
public CustomersRepository(NORTHWNDContext context) { _context = context; }
public GridController(NORTHWNDContext context) { _context = context; }