public List <Product> listProduct() { using (var db = new CoffeeContext()) { List <Product> list = db.Products.SqlQuery("SELECT * FROM stock.Product").ToList(); return(list); } }
public void addProduct(Product product) { using (var db = new CoffeeContext()){ db.Products.Add(product); db.SaveChanges(); } }
public Reminder GetReminder(Guid reminderId) { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.Reminders.Include(r => r.User).Include(r => r.User.Drink).SingleOrDefault(r => r.Id == reminderId)); } }
protected void SetUpDatabase() { var options = new DbContextOptionsBuilder <CoffeeContext>() .UseInMemoryDatabase(databaseName: "CoffeeDb") .Options; Guid CoffeeEspressorId = Guid.NewGuid(); Guid EspressorEspressorId = Guid.NewGuid(); Context = new CoffeeContext(options); Context.EspressoMachines.Add(new EspressoMachineEntity { Id = CoffeeEspressorId, IsEspressor = false }); Context.EspressoMachines.Add(new EspressoMachineEntity { Id = EspressorEspressorId, IsEspressor = true }); Context.Coffees.Add(new CoffeeEntity { Name = "First Coffee", Price = 20, Sweetness = Sweetness.Bitter, EspressoMachineId = CoffeeEspressorId }); Context.Coffees.Add(new CoffeeEntity { Name = "Second Coffee", Price = 30, Sweetness = Sweetness.Sweet, EspressoMachineId = EspressorEspressorId }); Context.Coffees.Add(new CoffeeEntity { Name = "Third Coffee", Price = 45, Sweetness = Sweetness.LessSweet, EspressoMachineId = EspressorEspressorId }); Context.SaveChanges(); }
public override void Down() { // Change JSON for coffee options from KeyValuePair<string, KeyValuePair<string, string>> to KeyValuePair<string, int // THIS RESULTS IN DATA LOSS (of non-integer values) using (var db = new CoffeeContext()) { // Get all the users foreach (var user in db.Users) { // Transform JSON List <KeyValuePair <string, KeyValuePair <string, string> > > old = JsonConvert.DeserializeObject <List <KeyValuePair <string, KeyValuePair <string, string> > > >(user.CoffeeOptionsJson); List <KeyValuePair <string, int> > newOptions = new List <KeyValuePair <string, int> >(); foreach (KeyValuePair <string, KeyValuePair <string, string> > kvp in old) { if (kvp.Value.Key == "int") { newOptions.Add( new KeyValuePair <string, int>( kvp.Key, Int32.Parse(kvp.Value.Value) ) ); } } user.CoffeeOptionsJson = JsonConvert.SerializeObject(newOptions); } db.SaveChanges(); } }
public override void Up() { // Change JSON for coffee options from KeyValuePair<string, int> to KeyValuePair<string, KeyValuePair<string, string>> using (var db = new CoffeeContext()) { // Get all the users foreach (var user in db.Users) { // Transform JSON List <KeyValuePair <string, int> > old = JsonConvert.DeserializeObject <List <KeyValuePair <string, int> > >(user.CoffeeOptionsJson); List <KeyValuePair <string, KeyValuePair <string, string> > > newOptions = new List <KeyValuePair <string, KeyValuePair <string, string> > >(); foreach (KeyValuePair <string, int> kvp in old) { newOptions.Add( new KeyValuePair <string, KeyValuePair <string, string> >( kvp.Key, new KeyValuePair <string, string>( "int", kvp.Value.ToString()) ) ); } user.CoffeeOptionsJson = JsonConvert.SerializeObject(newOptions); } db.SaveChanges(); } }
public override void Up() { //Add in no sugar option to list using (var db = new CoffeeContext()) { // Get all the users foreach (var user in db.Users) { // Transform JSON List <KeyValuePair <string, KeyValuePair <string, string> > > options = JsonConvert.DeserializeObject <List <KeyValuePair <string, KeyValuePair <string, string> > > >(user.CoffeeOptionsJson); // Add in No Sugar option if (!options.Any(o => o.Key == "No Sugar")) { options.Add(new KeyValuePair <string, KeyValuePair <string, string> >( key: "No Sugar", value: new KeyValuePair <string, string>( key: "bool", value: "false" ) )); } user.CoffeeOptionsJson = JsonConvert.SerializeObject(options); } db.SaveChanges(); } }
public ReviewRepositoryTests() { db = new CoffeeContext(); db.Database.BeginTransaction(); underTest = new ReviewRepository(db); }
protected override async Task <LambdaProxyResponse> ExecutionFunction(ApiGatewayProxyRequest request) { if (!request.PathParameters.ContainsKey("id")) { return(new LambdaProxyResponse { statusCode = HttpStatusCode.BadRequest, body = "No coffee ID defined in path parameter.", }); } var id = request.PathParameters["id"]; var dbContext = new CoffeeContext(_context); return(!await dbContext.RemoveCoffee(id) ? new LambdaProxyResponse { statusCode = HttpStatusCode.InternalServerError, body = "There was a problem processing the request.", } : new LambdaProxyResponse { statusCode = HttpStatusCode.OK, }); }
public CoffeeReport GetReport(DateTime generatedTime) { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.CoffeeReports.SingleOrDefault(r => r.GeneratedOn == generatedTime)); } }
public CoffeeReport GetLastReport() { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.CoffeeReports.ToList().LastOrDefault()); } }
public IEnumerable <DrinkType> GetAllDrinkTypes() { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.DrinkTypes.ToList()); } }
public DrinkType GetDrinkType(int id) { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.DrinkTypes.FirstOrDefault(i => i.Id == id)); } }
public void GetActiveDirectoryChanges(CoffeeContext context = null) { using (var coffeeContext = context ?? new CoffeeContext()) { // Add any new users in Active Directory / Remove old users var users = new ActiveDirectoryService().GetUsers(); var dbUsers = coffeeContext.Users.ToList(); var notInDb = users.Where(u => !dbUsers.Any(dbu => dbu.Guid == u.Guid)).ToList(); var deleteMe = dbUsers.Where(u => !users.Any(adu => adu.Guid == u.Guid)).ToList(); coffeeContext.Users.AddRange(notInDb.Select(u => new User(u))); coffeeContext.Users.RemoveRange(deleteMe); coffeeContext.SaveChanges(); dbUsers = coffeeContext.Users.ToList(); // Update the rest of the users details foreach (var adUser in users) { var dbuser = dbUsers.First(u => u.Guid == adUser.Guid); dbuser.LastName = adUser.LastName; dbuser.FirstName = adUser.FirstName; coffeeContext.Users.AddOrUpdate(dbuser); } coffeeContext.SaveChanges(); } }
public IEnumerable <User> GetAllUsers() { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.Users.Include(m => m.Drink).ToList()); } }
public CoffeeReport GetReport(int id) { using (var coffeeContext = new CoffeeContext()) { return(coffeeContext.CoffeeReports.Include(r => r.GeneratedBy).FirstOrDefault(r => r.Id == id)); } }
public void start() { DbContextOptions <CoffeeContext> options = new DbContextOptions <CoffeeContext>(); CoffeeContext coffeeContext = new CoffeeContext(options); this.coffeeController = new CoffeeController(coffeeContext); //OODProjectServer.Program.Main(); }
public void UpdateUser(User user) { using (var coffeeContext = new CoffeeContext()) { coffeeContext.Users.AddOrUpdate(user); coffeeContext.SaveChanges(); } }
public DateTime GetMeeting() { using (var coffeeContext = new CoffeeContext()) { var settings = coffeeContext.GlobalInformation.FirstOrDefault(); return(settings == null ? DateTime.Now : settings.MeetingDate); } }
public User GetUser(string guid) { using (var coffeeContext = new CoffeeContext()) { var userGuid = new Guid(guid); return(coffeeContext.Users.Include(m => m.Drink).FirstOrDefault(i => i.Guid == userGuid)); } }
public void ClearOldReminders(DateTime oldestAcceptableDate) { using (var coffeeContext = new CoffeeContext()) { var removethese = coffeeContext.Reminders.Where(r => r.CreatedOn < oldestAcceptableDate); coffeeContext.Reminders.RemoveRange(removethese); coffeeContext.SaveChanges(); } }
public void SetWillBeThere(User forUser, bool value = true) { using (var coffeeContext = new CoffeeContext()) { var user = coffeeContext.Users.SingleOrDefault(u => u.Id == forUser.Id); user.WillBeThere = value; coffeeContext.SaveChanges(); } }
public void SaveReport(CoffeeReport coffeereport) { using (var coffeeContext = new CoffeeContext()) { coffeeContext.CoffeeReports.Add(coffeereport); coffeeContext.SaveChanges(); } }
public CoffeeMockDbContext() { var options = new DbContextOptionsBuilder <CoffeeContext>() .UseInMemoryDatabase() .Options; CoffeeContext = new CoffeeContext(options); MockData(); }
public CoffeeDataController(CoffeeContext context) { _context = context; if (_context.coffeeShops.Count() == 0) { //_context.coffeeShops.Add(new CoffeeShop {Name = "Lupo"} ); _context.SaveChanges(); } }
public void SetWillBeThere(User forUser, Reminder reminder) { SetWillBeThere(forUser); using (var coffeeContext = new CoffeeContext()) { var dbReminder = coffeeContext.Reminders.Single(r => r.Id == reminder.Id); coffeeContext.Reminders.Remove(dbReminder); coffeeContext.SaveChanges(); } }
//TODO inject S3 Client public CoffeeController(CoffeeContext context) { _context = context; // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. //string link1 = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSZjphQje8agD2NHCefLRzk8xdsU4kL_XlypgeublZoZAZxJhL6fw"; //string link2 = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSGbiv-DkWtSVw3Ir_6FNer3S9vB6dI6PN0ZVWhfhQnZp7EyApy"; //string link3 = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQctidq7Ig44_Enhj52pcPC0i8BxsE2RT0BaTKuuL8TjvD4rWMLkA"; }
protected override async Task <LambdaProxyResponse> ExecutionFunction(ApiGatewayProxyRequest request) { var dbContext = new CoffeeContext(_context); var coffee = await dbContext.GetCurrentCoffee(); return(new LambdaProxyResponse { statusCode = HttpStatusCode.OK, body = SerializerUtil.Serialize(coffee), }); }
public void SetMeeting(DateTime time) { using (var coffeeContext = new CoffeeContext()) { var settings = coffeeContext.GlobalInformation.FirstOrDefault(); settings = settings ?? new GlobalInformation(); settings.MeetingDate = time; coffeeContext.GlobalInformation.AddOrUpdate(settings); coffeeContext.SaveChanges(); } }
private async void ExecuteCommand(DbContextOptions options, SlackRequest request, SlackResponse response) { using var context = new CoffeeContext(options); try { await ExecuteCommandAsync(context, request, response); } catch (Exception e) { _logger.LogError(e, $"Error occured while handling {request}"); } }