public ContactTableDetailEdit(ManufacturingContext context) { this._context = context; this._contactRepository = new ContactRepository(context); this._distributorRepository = new DistributorRepository(context); this._unitOfWork = new UnitOfWork(context); }
public static async Task CreatingUsers() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); Console.WriteLine("Creating Users"); User user1 = new User(); user1.UserName = "******"; user1.PermissionId = 1; User user2 = new User(); user2.UserName = "******"; user2.PermissionId = 1; User user3 = new User(); user3.UserName = "******"; user3.PermissionId = 1; context.Users.Add(user1); context.Users.Add(user2); context.Users.Add(user3); await context.SaveChangesAsync(); Console.WriteLine("Should be created"); }
public static async Task RemovePartFromCategory() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); Console.WriteLine("Working, Please Wait..."); CategoryEdit categoryService = new CategoryEdit(context); var categories = await categoryService.GetCategories(); var category = categories.FirstOrDefault(e => e.Id == 14); //var instance=category var partInstances = await categoryService.GetCategoryPartInstances(category); var partInstance = partInstances.FirstOrDefault(e => e.Id == 1); var output = await categoryService.RemovePartFrom(partInstance.Id, category); if (output.Success) { Console.WriteLine(output.Message); } else { Console.WriteLine(output.Message); } }
private bool ShowLogin() { //Startup Login LoginWindow loginWindow = new LoginWindow(); DomainManager domainManager = new DomainManager(); ManufacturingContext context = new ManufacturingContext(this.optionsBuilder.Options); IUserSettingsService userSettingsService = new UserSettingsService(this._logger, context); IAuthenticationUseCase auth = new AuthenticationService(context, domainManager, this._logger, userSettingsService); var loginVM = new LoginViewModel(auth, userSettingsService); loginVM.LoginCompleted += (sender, args) => { if (loginVM.LoginResponce.Success) { this.userService = loginVM.LoginResponce.Service; DXSplashScreen.Show <SETSplashScreen>(); } loginWindow.Close(); }; loginWindow.DataContext = loginVM; if (DXSplashScreen.IsActive) { DXSplashScreen.Close(); } loginWindow.ShowDialog(); return(this.userService.IsValid()); }
public static void ImportPartInstances() { var context = new ManufacturingContext(); var lines = File.ReadAllLines(@"C:\InventoryTransfer\PartInstances.txt"); foreach (var line in lines) { var rows = line.Split('\t'); PartInstance instance = new PartInstance(); var properties = typeof(PartInstance).GetProperties(); foreach (var keyValue in HeaderIndex) { if (keyValue.Key == 0 || keyValue.Key == 4) { instance.GetType().GetProperty(keyValue.Value).SetValue(instance, rows[keyValue.Key]); } else if ((keyValue.Key >= 1 && keyValue.Key <= 3) || (keyValue.Key >= 8 && keyValue.Key <= 11)) { instance.GetType().GetProperty(keyValue.Value).SetValue(instance, Convert.ToInt32(rows[keyValue.Key])); } else if (keyValue.Key >= 5 && keyValue.Key <= 7) { instance.GetType().GetProperty(keyValue.Value).SetValue(instance, false); } } context.Add(instance); } context.SaveChanges(); Console.WriteLine("Maybe???"); Console.ReadKey(); }
public DistributorEdit(ManufacturingContext context) { this._context = context; this._distributorRepository = new DistributorRepository(context); this._priceProvider = new PriceProvider(context); this._contactProvider = new ContactProvider(context); this._unitOfWork = new UnitOfWork(context); }
public CategoryEdit(ManufacturingContext context) { this._context = context; this._categoryRepository = new CategoryRepository(context); this._instanceRepository = new PartInstanceRepository(context); this._partRepository = new PartRepository(context); this._unitOfWork = new UnitOfWork(context); }
public PartSummaryEdit(ManufacturingContext context) { this._context = context; this._partRepository = new PartRepository(context); this._locationProvider = new LocationProvider(context); this._categoryProvider = new CategoryProvider(context); this._unitOfWork = new UnitOfWork(context); }
public AlertService() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); this._context = new ManufacturingContext(optionsBuilder.Options); this._emailer = new Emailer(); this._users = new List <User>(); }
public LocationEditUseCase(ManufacturingContext context) { this._context = context; this._locationRepository = new LocationRepository(context); this._instanceProvider = new PartInstanceProvider(context); this._partProvider = new PartProvider(context); this._transactionProvider = new TransactionProvider(context); this._unitOfWork = new UnitOfWork(context); }
public static async Task DeleteAll() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); IRepository <PartInstance> instanceRepository = new PartInstanceRepository(context); IRepository <Part> partRepository = new PartRepository(context); await partRepository.LoadAsync(); var parts = await context.Parts.Include(e => e.PartInstances).Where(e => e.Id > 1).ToListAsync(); List <int> instanceIds = new List <int>(); foreach (var part in parts) { var ids = part.PartInstances.Select(e => e.Id); instanceIds.AddRange(ids); } await instanceRepository.LoadAsync(); Console.WriteLine("Attempting to delete id list, see log below"); foreach (var id in instanceIds) { var partInstance = await instanceRepository.GetEntityAsync(e => e.Id == id); if (partInstance != null) { var output = await instanceRepository.DeleteAsync(partInstance); if (output != null) { var count = await context.SaveChangesAsync(); if (count > 0) { Console.WriteLine("Successfully Deleted: Id:{0} Name:{1}", partInstance.Id, partInstance.Name); } else { Console.WriteLine("Error Saving Id:{0} Name:{1}", partInstance.Id, partInstance.Name); } } else { Console.WriteLine("Error Deleting: Id:{0} Name:{1}", partInstance.Id, partInstance.Name); } } else { Console.WriteLine("Could Not Find: Id:{0} ", id); } } }
public PriceEdit(ManufacturingContext context) { this._context = context; this._priceRepository = new PriceRepository(context); this._partInstanceRepository = new PartInstanceRepository(context); this._partPriceRepository = new PartPriceRepository(context); this._partRepository = new PartRepository(context); this._distributorProvider = new DistributorProvider(context); this._priceLogRepository = new PriceLogRepository(context); this._unitOfWork = new UnitOfWork(context); }
public AuthenticationService(ManufacturingContext context, IDomainManager domainManager, ILogger logger, IUserSettingsService userSettingsService) { this._context = context; this._userRepository = new UserRepository(this._context); this._sessionRepository = new SessionRepository(this._context); this._permissionRepository = new PermissionRepository(this._context); this._unitOfWork = new UnitOfWork(this._context); this._domainManager = domainManager; this._logger = logger; this._userSettingsService = userSettingsService; }
public CheckOut(ManufacturingContext context, IUserService userService) { this._bubblerRepository = new BubblerParameterRepository(context); this._transactionRepository = new TransactionRepository(context); this._locationProvider = new LocationProvider(context); this._partInstanceRepository = new PartInstanceRepository(context); this._categoryRepository = new CategoryRepository(context); this._userService = userService; this._unitOfWork = new UnitOfWork(context); this._context = context; }
public PartInstanceDetailsEdit(ManufacturingContext context) { this._context = context; this._instanceRepository = new PartInstanceRepository(context); this._attachmentRepository = new AttachmentRepository(context); this._transactionProvider = new TransactionProvider(context); this._categoryProvider = new CategoryProvider(context); this._locationProvider = new LocationProvider(context); this._bubblerRepository = new BubblerParameterRepository(context); this._unitOfWork = new UnitOfWork(context); }
public TransactionTableEdit(ManufacturingContext context) { this._context = context; this._transactionRepository = new TransactionRepository(context); this._partInstanceRepository = new PartInstanceRepository(context); this._locationRepository = new LocationRepository(context); this._bubblerRepository = new BubblerParameterRepository(context); this._partProvider = new PartProvider(context); this._categoryRepository = new CategoryRepository(context); this._unitOfWork = new UnitOfWork(context); }
public AlertService(ILoggerFactory loggerFactory, IEmailer emailer) { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); this._context = new ManufacturingContext(optionsBuilder.Options); this._logger = loggerFactory.CreateLogger <AlertService>(); this._logger.LogInformation("Alert Service Initialized"); this._emailer = emailer; this._users = new List <User>(); }
public static void AddAlertToAllInstances() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var user = context.Users .Include(e => e.Sessions) .ThenInclude(e => e.Transactions) .Include(e => e.Permission) .FirstOrDefault(e => e.FirstName == "Andrew"); UserService userService = new UserService(); if (user != null) { Session session = new Session(user); context.Sessions.Add(session); context.SaveChanges(); userService.CurrentUserName = user.UserName; userService.CurrentSessionId = session.Id; userService.UserPermissionName = user.Permission.Name; } var partInstances = context.PartInstances.Include(e => e.IndividualAlert).Include(e => e.StockType).ThenInclude(e => e.CombinedAlert); List <Task> tasks = new List <Task>(); foreach (var instance in partInstances) { if (instance.StockType.IsDefault) { //individual alert if (instance.IndividualAlert == null) { Console.WriteLine("Individual Alert, PartInstance: {0}", instance.Name); IndividualAlert alert = new IndividualAlert(); alert.PartInstance = instance; instance.IndividualAlert = alert; context.Add(alert); } } else { //combined alert if (instance.StockType.CombinedAlert == null) { Console.WriteLine("Combined Alert, StockType: {0}", instance.StockType.Name); CombinedAlert alert = new CombinedAlert(); alert.StockHolder = instance.StockType; context.Add(alert); } } } context.SaveChanges(); }
public static async Task WorkingWithCombinedAlerts() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.27.192.1;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var user = context.Users .Include(e => e.Sessions) .ThenInclude(e => e.Transactions) .Include(e => e.Permission) .FirstOrDefault(e => e.FirstName == "Andrew"); UserService userService = new UserService(); if (user != null) { Session session = new Session(user); await context.Sessions.AddAsync(session); await context.SaveChangesAsync(); userService.CurrentUserName = user.UserName; userService.CurrentSessionId = session.Id; userService.UserPermissionName = user.Permission.Name; } var stockType = await context.Categories.OfType <StockType>().Include(e => e.PartInstances).ThenInclude(e => e.BubblerParameter).FirstOrDefaultAsync(e => e.Id == 16); if (stockType != null) { CombinedAlert tmaAlert = new CombinedAlert(); UserAlert userAlert = new UserAlert(); userAlert.IsEnabled = true; tmaAlert.StockHolder = stockType; userAlert.Alert = tmaAlert; userAlert.User = user; var added = await context.AddAsync(userAlert); if (added != null) { await context.SaveChangesAsync(); Console.WriteLine("Should be saved"); } else { Console.WriteLine("Could Not Save UserAlert"); } } else { Console.WriteLine("StockType is null"); } }
public static async Task TestCurrentInventory() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); IEntityProvider <PartInstance> partInstanceProvider = new PartInstanceProvider(context); await partInstanceProvider.LoadAsync(); DateTime now = DateTime.Now; var allParts = await partInstanceProvider.GetEntityListAsync(e => e.CostReported && e.Quantity != 0); List <CurrentInventoryItem> currentInventory = new List <CurrentInventoryItem>(); foreach (var part in allParts) { if (part.IsBubbler) { DateTime dateIn = part.Transactions.OrderByDescending(e => e.TimeStamp).First().TimeStamp; currentInventory.Add(new CurrentInventoryItem() { Id = part.Id, Today = now, DateIn = dateIn, Age = (now - dateIn).Days, PartCategory = part.Part.Name, Part = part.Name, Quantity = part.BubblerParameter.NetWeight, Cost = part.TotalCost }); } else { DateTime dateIn = part.Transactions.OrderByDescending(e => e.TimeStamp).First().TimeStamp; currentInventory.Add(new CurrentInventoryItem() { Id = part.Id, Today = now, DateIn = dateIn, Age = (now - dateIn).Days, PartCategory = part.Part.Name, Part = part.Name, Quantity = part.Quantity, Cost = part.TotalCost }); } } ConsoleTable table = ConsoleTable.From <CurrentInventoryItem>(currentInventory); Console.WriteLine(table.ToMinimalString()); }
public static async Task WorkingWithIndividualAlerts() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.27.192.1;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var user = context.Users .Include(e => e.Sessions) .ThenInclude(e => e.Transactions) .Include(e => e.Permission) .FirstOrDefault(e => e.FirstName == "Andrew"); UserService userService = new UserService(); if (user != null) { Session session = new Session(user); await context.Sessions.AddAsync(session); await context.SaveChangesAsync(); userService.CurrentUserName = user.UserName; userService.CurrentSessionId = session.Id; userService.UserPermissionName = user.Permission.Name; } var partInstance = await context.PartInstances.Include(e => e.BubblerParameter).Include(e => e.IndividualAlert).FirstOrDefaultAsync(e => e.Id == 1); if (partInstance != null) { IndividualAlert alert = new IndividualAlert(); alert.PartInstance = partInstance; UserAlert userAlert = new UserAlert(); userAlert.Alert = alert; userAlert.User = user; var added = await context.AddAsync(userAlert); if (added != null) { await context.SaveChangesAsync(); Console.WriteLine("Should be saved"); } else { Console.WriteLine("Failed to add Alert"); } } else { Console.WriteLine("PartInstance Not Found"); } }
public static async Task TestingCategoryUseCase() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.27.192.1;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var categoryService = new CategoryEdit(context); Console.WriteLine("Adding partInstance to category, please wait"); var category = await categoryService.GetCategory(7); Console.WriteLine("Category {0} ", category.Name); //var output = await categoryService.AddPartTo(3, category); //Console.WriteLine(output.Message); Console.WriteLine("Done, Please come again"); }
public static async Task AlertQueryTestingExisting() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var tempIndividual = context.UserAlerts.Include(e => e.Alert).Where(e => e.Alert.AlertType == AlertType.IndividualAlert && e.UserId == 1).Select(e => e.Alert); var tempCombined = context.UserAlerts.Include(e => e.Alert).Where(e => e.Alert.AlertType == AlertType.CombinedAlert && e.UserId == 1).Select(e => e.Alert); List <AlertDto> alerts = new List <AlertDto>(); foreach (var temp in tempIndividual) { var alert = await context.Alerts.OfType <IndividualAlert>().Include(e => e.PartInstance).ThenInclude(e => e.Part).FirstOrDefaultAsync(e => e.Id == temp.Id); if (alert != null) { alerts.Add(new AlertDto(temp)); } } foreach (var temp in tempCombined) { var alert = await context.Alerts.OfType <CombinedAlert>().Include(e => e.StockHolder).ThenInclude(e => e.PartInstances).ThenInclude(e => e.Part).FirstOrDefaultAsync(e => e.Id == temp.Id); if (alert != null) { alerts.Add(new AlertDto(alert)); } } foreach (var alert in alerts) { Console.WriteLine("Alert: {0} AlertType: {1}", alert.AlertId, alert.AlertType); Console.WriteLine("PartInstance(s)"); Console.Write(" Name(s): "); foreach (var instance in alert.PartInstances) { Console.Write(instance.Name + ","); } Console.WriteLine(); } }
public static async Task AlertQueryTestingAvailable() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); //optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); Console.WriteLine("Starting Query.."); using var context = new ManufacturingContext(optionsBuilder.Options); var exisiting = context.UserAlerts.Include(e => e.Alert).Where(e => e.UserId == 1).Select(e => e.Alert); //context.Alerts.Include(e=>e.UserAlerts).Contains() var available = await context.Alerts .Include(alert => (alert as IndividualAlert).PartInstance.BubblerParameter) .Include(alert => (alert as IndividualAlert).PartInstance.Part) .Include(alert => (alert as CombinedAlert).StockHolder.PartInstances) .ThenInclude(instance => instance.BubblerParameter) .Where(alert => exisiting.All(e => e.Id != alert.Id)) .Select(alert => new AlertDto(alert)) .ToListAsync(); var alerts = await context.UserAlerts .Include(e => (e.Alert as IndividualAlert).PartInstance.BubblerParameter) .Include(e => (e.Alert as IndividualAlert).PartInstance.Part) .Include(e => (e.Alert as CombinedAlert).StockHolder.PartInstances) .Where(e => e.UserId == 1).Select(e => new AlertDto(e.Alert)).ToListAsync(); foreach (var alert in alerts) { Console.WriteLine("Alert: {0} AlertType: {1}", alert.AlertId, alert.AlertType); Console.WriteLine("PartInstance(s)"); Console.Write(" Name(s): "); foreach (var instance in alert.PartInstances) { Console.Write(instance.Name + ","); } Console.WriteLine(); } }
public static async Task TestngLocations() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); //optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); Console.WriteLine("Running..."); using var context = new ManufacturingContext(optionsBuilder.Options); //IRepository<Location> locationRepository = new LocationRepository(context); ILocationManagmentUseCase locationService = new LocationManagmentUseCase(context); var location = await locationService.GetLocation(1); location.Description = "Testing Description using the UseCase"; LocationManagmentInput input = new LocationManagmentInput(location, Application.Boundaries.EditAction.Update); var output = await locationService.Execute(input); if (output.Success) { Console.WriteLine("Should be updated"); } else { Console.WriteLine("Updated Failed:"); } Console.WriteLine(output.Message); Console.ReadKey(); //var location = await locationRepository.GetEntityAsync(e => e.Id == 1); //location.Description = location.Name; //var updated = await locationRepository.UpdateAsync(location); //if (updated != null) { // var count = await context.SaveChangesAsync(); // if (count > 0) { // Console.WriteLine("Saved Successfully"); // } else { // Console.WriteLine("Count was 0"); // } //} else { // Console.WriteLine("Updated Failed"); //} //Console.ReadKey(); }
public static async Task DeletingAlerts() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.27.192.1;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); //var alert =await context.Alerts.OfType<IndividualAlert>().Include(e=>e.UserAlerts).ThenInclude(e=>e.User).Include(e=>e.PartInstance).FirstOrDefaultAsync(e => e.Id == 3); var user = context.Users .Include(e => e.Sessions) .ThenInclude(e => e.Transactions) .Include(e => e.Permission) .Include(e => e.UserAlerts) .ThenInclude(e => e.Alert) .FirstOrDefault(e => e.FirstName == "Andrew"); UserService userService = new UserService(); if (user != null) { Session session = new Session(user); await context.Sessions.AddAsync(session); await context.SaveChangesAsync(); userService.CurrentUserName = user.UserName; userService.CurrentSessionId = session.Id; userService.UserPermissionName = user.Permission.Name; Console.WriteLine("User found and Object created"); var alert = await context.UserAlerts.FirstOrDefaultAsync(e => e.UserId == user.Id && e.AlertId == 3); if (alert != null) { await context.SaveChangesAsync(); Console.WriteLine("Done?"); } else { Console.WriteLine("Could not find alert"); } } }
public static async Task DeleteUserAlerts() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); Console.WriteLine("Deleting User Alerts, Please Wait..."); var userAlerts = context.UserAlerts.Include(e => e.User).Include(e => e.Alert).Where(e => e.UserId == 1); foreach (var userAlert in userAlerts) { Console.WriteLine("User: {0} Alert: {1}", userAlert.User.UserName, userAlert.AlertId); } context.RemoveRange(userAlerts); await context.SaveChangesAsync(); Console.WriteLine("Should be cleared"); }
private void ManualLogIn() { using var context = new ManufacturingContext(this.optionsBuilder.Options); var user = context.Users .Include(e => e.Sessions) .ThenInclude(e => e.Transactions) .Include(e => e.Permission) .FirstOrDefault(e => e.FirstName == "Andrew"); if (user != null) { Session session = new Session(user); context.Sessions.Add(session); context.SaveChanges(); this.userService.CurrentUserId = user.Id; this.userService.CurrentUserName = user.UserName; this.userService.CurrentSessionId = session.Id; this.userService.UserPermissionName = user.Permission.Name; } }
public static async Task ResetStockTypeQuantity() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.27.192.1;database=manufacturing_inventory;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); var tma = await context.Categories.OfType <StockType>().Include(e => e.PartInstances).ThenInclude(e => e.BubblerParameter).FirstOrDefaultAsync(e => e.Id == 17); foreach (var instance in tma.PartInstances) { Console.WriteLine("PartInstance: {0} Quantity", instance.BubblerParameter.Weight); } tma.Quantity = 0; tma.Quantity += (int)tma.PartInstances.Sum(instance => instance.BubblerParameter.Weight); Console.WriteLine(); Console.WriteLine("New Quantity: {0}", tma.Quantity); context.Update(tma); await context.SaveChangesAsync(); Console.WriteLine("Should be done"); }
public static async Task DeleteOldAlerts() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); using var context = new ManufacturingContext(optionsBuilder.Options); await context.Alerts.OfType <IndividualAlert>().Include(e => e.PartInstance).ForEachAsync(alert => { if (alert.PartInstance != null) { Console.WriteLine("Removing {0} alert id: {1}", alert.PartInstance.Name, alert.Id); } else { Console.WriteLine("Should be combined, trying to delete id: {0}", alert.Id); } context.Remove(alert); }); await context.SaveChangesAsync(); Console.WriteLine("Should be done"); }