public void TestAll() { bool test = true; using (RaceContext context = new RaceContext()) { var list1 = context.Cars.ToArray(); using (CarCRUD CarCRUD = new CarCRUD(new RaceContext())) { var list2 = CarCRUD.All().ToArray(); if (list1.Length != list2.Length) { test = false; Assert.True(test); } Boolean equalTest = false; foreach (Cars car in list1) { foreach (Cars car2 in list2) { if (car.Id == car2.Id) { equalTest = true; } } if (equalTest != true) { Assert.True(equalTest); } } Assert.True(true); } } }
public List <ProdCategoryInfo> ProdCategory_List(int id) { using (var context = new RaceContext()) { var results = from x in context.VendorCatalogs where x.VendorID == id group x by x.Product.Category into gTemp orderby gTemp.Key.Description select new ProdCategoryInfo { Category = gTemp.Key.Description, ProductList = from y in gTemp select new InventoryInfo { ProductID = y.ProductID, ProductName = y.Product.ItemName, Reorder = y.Product.ReOrderLevel, InStock = y.Product.QuantityOnHand, OnOrder = y.Product.QuantityOnOrder, UnitType = y.OrderUnitType, UnitSize = y.OrderUnitSize } }; return(results.ToList()); } }
public void TestTrackInfo() { using (RaceContext context = new RaceContext()) { context.Races.Clear(); context.Cars.Clear(); context.Tracks.Clear(); context.CarInRaces.Clear(); context.Cars.AddRange(TrackTestCars); context.Tracks.AddRange(TrackTestTracks); context.Races.AddRange(TrackTestRaces); context.CarInRaces.AddRange(TrackTestCarInRaces); context.SaveChanges(); Queries querie = new Queries(); var trackInfo = querie.GetTrackInfo(TrackTestTracks[0].Id); var expected = new TrackInfo() { Id = TrackTestTracks[0].Id, FastestLap = TimeSpan.FromTicks(2345524323), FastestsCar = "PW", FastestsDriver = "Karl", Name = "LongTrack", NumberOfRaces = 4 }; Assert.Equal(expected.ToString(), trackInfo.ToString()); } }
public void TestRaceInfo() { using (RaceContext context = new RaceContext()) { context.Races.Clear(); context.Cars.Clear(); context.Tracks.Clear(); context.CarInRaces.Clear(); context.Cars.AddRange(RaceTestCars); context.Tracks.AddRange(RaceTestTracks); context.Races.AddRange(RaceTestRaces); context.CarInRaces.AddRange(RaceTestCarInRaces); context.SaveChanges(); Queries queries = new Queries(); var raceInfo = queries.GetRaceInfo(RaceTestRaces[2].Id); var expected = new RaceInfo() { RaceId = RaceTestRaces[2].Id, ActualEnd = RaceTestRaces[2].ActualEndTime, ActualStart = RaceTestRaces[2].ActualStartTime, NumberOfLaps = RaceTestRaces[2].NumberOfLaps, PlannedEnd = RaceTestRaces[2].PlannedEndTime, PlannedStart = RaceTestRaces[2].PlannedStartTime, TrackId = RaceTestRaces[2].Tracks.Id, TrackName = RaceTestRaces[2].Tracks.Name, Cars = CreateListOfCarInfo(new CarInRaces[3] { RaceTestCarInRaces[2], RaceTestCarInRaces[6], RaceTestCarInRaces[10] }) }; Assert.Equal(expected.ToString(), raceInfo.ToString()); } }
public List <PurchaseOrderPOCO> GetPurchaseOrder(int vendorid) { using (var context = new RaceContext()) { var result = (from x in context.Orders from y in x.OrderDetails join prod in context.Products on y.ProductID equals prod.ProductID join order in context.ReceiveOrders on x.OrderID equals order.OrderID join item in context.ReceiveOrderItems on order.ReceiveOrderID equals item.ReceiveOrderID where x.VendorID == vendorid select new PurchaseOrderPOCO { OrderID = x.OrderID, Item = prod.ItemName, QuantityOrdered = y.Quantity * y.OrderUnitSize, OrderedUnits = y.Quantity + " x case of " + y.OrderUnitSize, QuantityOutstanding = y.ReceiveOrderItems.Count() == 0 ? y.Quantity * y.OrderUnitSize : (y.Quantity * y.OrderUnitSize) - (from sum in y.ReceiveOrderItems where sum.OrderDetailID == y.OrderDetailID select(sum.ItemQuantity)).Sum(), ReceivedUnitSize = //((from roi in y.ReceiveOrderItems where roi.OrderDetailID == y.OrderDetailID select (roi.ItemQuantity)).FirstOrDefault() / y.OrderUnitSize) + y.OrderUnitSize, //RejectedUnitsReason = (from ret in y.ReturnOrderItems where ret.OrderDetailID == y.OrderDetailID select (ret.ItemQuantity + " " + ret.Comment)).FirstOrDefault(), //SalvagedItems = 0 }).Distinct().OrderBy(x => x.QuantityOrdered); return(result.ToList()); } }
public List <UnOrderedItem> GetUnOrderedItems() { using (var context = new RaceContext()) { return(context.UnOrderedItems.ToList()); } }
public UnitOfWork(CharacterContext context, SpellsContext spellsContext, ItemsContext itemsContext, PlayableClassContext playableClassContext, RaceContext raceContext) { _context = context; Characters = RepositoryFactory.GetCharacterRepository(context); HealthRecords = RepositoryFactory.GetHealthRepository(context); CurrencyRecords = RepositoryFactory.GetCurrencyRepository(context); ProficiencyRecords = RepositoryFactory.GetIsProficientRepository(context); Notes = RepositoryFactory.GetNotesRepository(context); Stats = RepositoryFactory.GetStatsRepository(context); _spellsContext = spellsContext; Spells = RepositoryFactory.GetSpellsRepository(spellsContext); _itemsContext = itemsContext; Items = RepositoryFactory.GetItemsRepository(itemsContext); _playableClassContext = playableClassContext; Classes = RepositoryFactory.GetPlayableClassRepository(playableClassContext); ClassAbilities = RepositoryFactory.GetClassAbilityRepository(playableClassContext); Subclasses = RepositoryFactory.GetSubclassRepository(playableClassContext); SubclassAbilities = RepositoryFactory.GetSubclassAbilityRepository(playableClassContext); _raceContext = raceContext; Races = RepositoryFactory.GetRacesRepository(raceContext); }
public void ForceCloseOrder(int orderid, string reason, List <ForceClearPOCO> clearitem, int vendorid) { List <string> errors = new List <string>(); using (var context = new RaceContext()) { var closed = (from x in context.Orders where x.OrderID == orderid select x.Closed).FirstOrDefault(); var closeorderlist = new List <ForceClearPOCO>(); if (closed) { errors.Add("You cannot close an already closed order"); } else { foreach (var item in clearitem) { var closesearch = (from x in context.Products where x.ItemName == item.ItemName select x).FirstOrDefault(); closesearch.QuantityOnOrder = closesearch.QuantityOnOrder - item.Remaining; } var query = (from x in context.Orders where x.OrderID == orderid && x.VendorID == vendorid select x).FirstOrDefault(); query.Comment = reason; CloseOrder(orderid); context.SaveChanges(); } } }
public PurchaseOrder InventoryToPO(int vendorid, int productid, List <PurchaseOrder> list) { using (var context = new RaceContext()) { int items = list.Where(x => x.ProductID == productid).Select(x => x).Count(); PurchaseOrder results = null; if (items == 0) { results = (from x in context.VendorCatalogs where x.VendorID == vendorid && x.ProductID == productid select new PurchaseOrder { ProductID = x.ProductID, Product = x.Product.ItemName, OrderQty = 1, UnitSize = x.OrderUnitSize, UnitType = x.OrderUnitType, UnitCost = x.OrderUnitCost, Warning = " ", PerItemCost = x.OrderUnitCost / x.OrderUnitSize, ExtendedCost = x.OrderUnitCost * x.OrderUnitSize }).FirstOrDefault(); } return(results); } }
public int Update_RaceResultsView(int employeeid, int raceid, List <RaceResultsView> items) { using (var context = new RaceContext()) { foreach (RaceResultsView item in items) { if (item.Time == null) { errors.Add("Times must be in the format hh:mm:ss."); break; } } foreach (RaceResultsView item in items) { if (item.Time != null & item.Time < new TimeSpan(00, 00, 00)) { errors.Add("Times must be positive."); break; } } if (errors.Count == 0) { items = items.OrderBy(x => x.Time).ToList(); int?placement = 0; int?penalties = null; foreach (RaceResultsView item in items) { if (item.Time != new TimeSpan(00, 00, 00)) { placement++; } else { item.Time = null; } if (item.Penalties != 0) { penalties = item.Penalties; } RaceDetail newitem = (from x in context.RaceDetails where x.RaceDetailID == item.RaceDetailID select x).FirstOrDefault(); newitem.Place = placement == 0 ? null : placement; newitem.RunTime = item.Time; newitem.PenaltyID = penalties; context.Entry(newitem).State = System.Data.Entity.EntityState.Modified; } } if (errors.Count == 0) { return(context.SaveChanges()); } else { throw new BusinessRuleException("Race Time Validation Error.", errors); } } }
public PilotRepository( RaceContext context, IMapper mapper, ILogger <PilotRepository> logger) { this.context = context; this.mapper = mapper; this.logger = logger; }
public List <CategoryDDL> Get_CategoryDDL() { using (var context = new RaceContext()) { return(context.Categories.Select(x => new CategoryDDL { CategoryID = x.CategoryID, CategoryName = x.Description }).ToList()); } }
public int Item_Delete(int itemid) { using (var context = new RaceContext()) { var existing = context.UnOrderedItems.Find(itemid); context.UnOrderedItems.Remove(existing); return(context.SaveChanges()); } }
public void CloseOrder(int orderid) { using (var context = new RaceContext()) { var query = (from q in context.Orders where q.OrderID == orderid select q).First(); query.Closed = true; context.SaveChanges(); } }
public int Do_RefundTransaction(List <RefundItem> list) { // Check refund for Oinvoice already there using (var context = new RaceContext()) { int invoiceID = list[0].InvoiceID; if (context.StoreRefunds.Where(x => x.InvoiceID == invoiceID) != null) { var totals = CalculateTotals(list); // Invoice with negative values Invoice invoice = new Invoice(); invoice.EmployeeID = list[0].EmployeeID; invoice.GST = (decimal)totals.Item2; invoice.SubTotal = (decimal)totals.Item1; invoice.Total = (decimal)totals.Item3; invoice.InvoiceDate = DateTime.Now; context.Invoices.Add(invoice); // Invoice details foreach (RefundItem item in list) { InvoiceDetail temp = new InvoiceDetail(); StoreRefund retemp = new StoreRefund(); if (item.ItemToBeRefunded) { temp.InvoiceID = invoice.InvoiceID; temp.ProductID = item.ProductID; temp.Quantity = item.ProductQuantity; temp.Price = (decimal)item.ProductPrice; retemp.InvoiceID = invoice.InvoiceID; retemp.ProductID = item.ProductID; retemp.OriginalInvoiceID = item.InvoiceID; retemp.Reason = item.Reason; context.StoreRefunds.Add(retemp); Product prodTemp = context.Products.Where(x => x.ProductID == item.ProductID && x.CategoryID == item.CategoryID).Single(); prodTemp.QuantityOnHand += item.ProductQuantity; context.Entry(prodTemp).State = System.Data.Entity.EntityState.Modified; } } context.SaveChanges(); return(invoice.InvoiceID); } else { throw new BusinessRuleException("Refund Error", new List <string> { "Refund already exsists" }); } } }
public AccountController( RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration conf, RaceContext context) { this.roleManager = roleManager; this.userManager = userManager; this.conf = conf; this.context = context; }
public List <DriverList> Get_DriverList() { using (var context = new RaceContext()) { var results = from x in context.Members select new DriverList { MemberID = x.MemberID, Name = x.FirstName + " " + x.LastName }; return(results.ToList()); } }
public List <EmployeeList> Get_Employees() { using (var context = new RaceContext()) { var results = from x in context.Employees select new EmployeeList { ID = x.EmployeeID, Name = x.FirstName + " " + x.LastName }; return(results.ToList()); } }
public List <PenaltyList> Get_PenaltyList() { using (var context = new RaceContext()) { var results = from x in context.RacePenalties select new PenaltyList { PenaltyID = x.PenaltyID, Description = x.Description }; return(results.ToList()); } }
public List <ProductDDL> Get_ProductDDL(int categoryID) { using (var context = new RaceContext()) { return(context.Products.Where(x => x.CategoryID == categoryID) .Select(x => new ProductDDL { ProductID = x.ProductID, ProductName = x.ItemName, CategoryID = x.CategoryID }).ToList()); } }
public List <VINList> Get_VINList(int carclassid) { using (var context = new RaceContext()) { var results = from x in context.Cars where x.CarClassID == carclassid select new VINList { CarID = x.CarID, SerialNumber = x.SerialNumber }; return(results.ToList()); } }
public void TestCarCreate() { using (RaceContext context = new RaceContext()) { using (CarCRUD CarCRUD = new CarCRUD(new RaceContext())) { var Car = new Cars { Name = "Test", DriverName = "Test" }; Assert.NotNull(context.Cars.Where(a => a.Id == CarCRUD.Create(Car)).FirstOrDefault()); } } }
public List <SelectionList> Vendor_List() { using (var context = new RaceContext()) { var results = from x in context.Vendors orderby x.Name select new SelectionList { ValueField = x.VendorID, TextField = x.Name }; return(results.ToList()); } }
public List <VendorOrder> GetVendors() { using (var context = new RaceContext()) { var result = from x in context.Vendors from y in x.Orders where y.Closed == false && y.OrderNumber != null && y.OrderDate != null select new VendorOrder { VendorID = x.VendorID, VendorOrderNumber = y.OrderNumber + " - " + x.Name }; return(result.ToList()); } }
public void TestUpdate() { using (RaceContext context = new RaceContext()) { using (CarCRUD CarCRUD = new CarCRUD(new RaceContext())) { var car = new Cars { Name = "Update" }; CarCRUD.Update(car); Assert.NotNull(context.Cars.Where(a => a.Name.Contains("Update")).FirstOrDefault()); } } }
public List <SelectionList> User_List() { using (var context = new RaceContext()) { var results = from x in context.Employees where x.PositionID == 1 || x.PositionID == 10 orderby x.LastName, x.FirstName select new SelectionList { ValueField = x.EmployeeID, TextField = x.FirstName + " " + x.LastName }; return(results.ToList()); } }
public CartDisplay Get_CartDisplayItem(int productID, int categoryID) { using (var context = new RaceContext()) { return(context.Products.Where(x => x.ProductID == productID && x.CategoryID == categoryID) .Select(x => new CartDisplay { CategoryID = x.CategoryID, ProductID = x.ProductID, ProductName = x.ItemName, ProductPrice = (double)x.ItemPrice, ProductQuantity = 0, }).Single()); } }
public List <VendorContact> GetVendorContacts(int vendorid) { using (var context = new RaceContext()) { var result = from x in context.Vendors where x.VendorID == vendorid select new VendorContact { VendorName = x.Name, Contact = x.Contact, Address = x.Address + " " + x.City, Phone = x.Phone }; return(result.ToList()); } }
private static void PopulatePilotData(RaceContext context) { context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Pilots ON"); context.Pilots.Add(new Pilot { Id = 1000, Code = "Test", Name = "Test Pilot", Nationality = "HUN", Number = "33", TeamId = 1000, }); context.SaveChanges(); context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Pilots OFF"); }
public List <CarClassList> Get_CarClassList(int raceid) { using (var context = new RaceContext()) { var results = from x in context.CarClasses where x.CertificationLevel == (from y in context.Races where y.RaceID == raceid select y.CertificationLevel).FirstOrDefault() select new CarClassList { CarClassID = x.CarClassID, CarClassName = x.CarClassName }; return(results.ToList()); } }
protected DataServiceBase() { Db = new RaceContext(); }