public RequestService(RequestsRepository repo, BarRepository barRepo, UserBarRepository userBarRepo, UserManager <ApplicationUser> userManager) { _userManager = userManager; _repo = repo; _barRepo = barRepo; _userBarRepo = userBarRepo; }
public WebAPICallResponse UploadData(List <BarModel> bars) { WebAPICallResponse webApiResponse = new WebAPICallResponse(); try { var insertedBars = new BarRepository().UploadData(bars); if (insertedBars.Count == bars.Count) { webApiResponse.WebAPICallStatus = true; webApiResponse.WebAPICallMessage = EnumHelper.GetDescription(Definitions.StatusMessage.InsertSuccess); } else { webApiResponse.WebAPICallStatus = true; webApiResponse.WebAPICallMessage = EnumHelper.GetDescription(Definitions.StatusMessage.InsertFail); } } catch { webApiResponse.WebAPICallStatus = true; webApiResponse.WebAPICallMessage = EnumHelper.GetDescription(Definitions.StatusMessage.InsertFail); } return(webApiResponse); }
public DrinkService(DrinkRepository drinkRepo, DrinkReviewRepository reviewRepo, BarRepository barRepo, ProfileRepository profileRepo) { _drinkRepo = drinkRepo; _reviewRepo = reviewRepo; _barRepo = barRepo; _profileRepo = profileRepo; }
public void TestUploadBars() { BarRepository brep = new BarRepository(); //Get bars from database List <BarModel> bars = brep.GetBars(); //create bar for insert List <BarModel> barsForInsert = new List <BarModel>(); barsForInsert.Add(new BarModel { Color = "testColor", Name = "testName", Size = 10 }); //Insert new data and get from databaase var insertedBar = brep.UploadData(barsForInsert); //Get bars for check does insert pass well List <BarModel> newBars = brep.GetBars(); foreach (var bar in newBars) { bar.BarId = 0; } //Delete added test bar var isDeleted = brep.DeleteById(insertedBar[0].BarId); if (bars.Count > 0) { new BarRepository().UploadData(bars); } Assert.AreEqual(JsonConvert.SerializeObject(newBars), JsonConvert.SerializeObject(barsForInsert)); }
public void Setup() { _connection = new SqliteConnection("Datasource=:memory:"); _connection.Open(); _options = new DbContextOptionsBuilder <BarOMeterContext>().UseSqlite(_connection).Options; _context = new BarOMeterContext(_options); _repository = new BarRepository(_context); _context.Database.EnsureCreated(); }
private void AddNotes_Click(object sender, RoutedEventArgs e) { var bar = CreateBar(); var b = new BarRepository().SaveBar(bar); var noteList = CreateNewNotes(b); var bSegment = new BassTabSegment(bar, noteList); bSegment.Height = 150; bSegment.Width = 150; BassTabSegments.Add(bSegment); bts.Items.Add(bSegment); }
public void TestGetRandomizedBars() { List <BarModel> bars1 = new BarRepository().GetRandomizedBars(); List <BarModel> bars2 = new BarRepository().GetRandomizedBars(); Assert.IsNotNull(bars1); Assert.IsNotNull(bars1); if (bars1.Count > 0 && bars2.Count > 0) { Assert.AreNotEqual(JsonConvert.SerializeObject(bars1), JsonConvert.SerializeObject(bars2)); } else { Assert.AreEqual(JsonConvert.SerializeObject(bars1), JsonConvert.SerializeObject(bars2)); } }
private Bar CreateBar() { var bl = new BarRepository().GetBars(Project.ProjectId); var bar = new Bar(); bar.ProjectId = Project.ProjectId; if (bl.Count == 0) { bar.PositionId = 1; return(bar); } var sbl = bl.OrderBy(x => x.PositionId).ToList(); var lastPostionId = sbl.Last().PositionId; bar.PositionId = lastPostionId + 1; return(bar); }
public WebAPICallResponseT <List <BarModel> > GetBars() { WebAPICallResponseT <List <BarModel> > webApiResponse = new WebAPICallResponseT <List <BarModel> >(); try { List <BarModel> bars = new BarRepository().GetBars(); webApiResponse.Value = bars; webApiResponse.WebAPICallStatus = true; } catch { webApiResponse.Value = new List <BarModel>(); webApiResponse.WebAPICallStatus = false; } return(webApiResponse); }
/// <summary> /// Initialize the database and repositories. Inject the database context to repositories. /// </summary> public BaseController() { var db = new BarContext(); BarRepository = new BarRepository(db); BottleRepository = new BottleRepository(db); DrinkRepository = new DrinkRepository(db); DrinkBarRepository = new DrinkBarRepository(db); EventRepository = new EventRepository(db); IngredientDrinkRepository = new IngredientDrinkRepository(db); IngredientRepository = new IngredientRepository(db); OrderDrinkRepository = new OrderDrinkRepository(db); OrderRepository = new OrderRepository(db); QuantityRepository = new QuantityRepository(db); UnitRepository = new UnitRepository(db); UserBarRepository = new UserBarRepository(db); UserRepository = new UserRepository(db); UserRoleRepository = new UserRoleRepository(db); }
public WebAPICallResponseT <List <BarModel> > GetRandomizedBars() { WebAPICallResponseT <List <BarModel> > webApiResponse = new WebAPICallResponseT <List <BarModel> >(); try { List <BarModel> bars = new BarRepository().GetRandomizedBars(); webApiResponse.WebAPICallStatus = true; webApiResponse.Value = bars; } catch (Exception ex) { webApiResponse.Value = new List <BarModel>(); webApiResponse.WebAPICallStatus = true; webApiResponse.WebAPICallMessage = ex.Message; } return(webApiResponse); }
public BarReviewService(BarReviewRepository repo, BarRepository barRepo) { _barReviewRepo = repo; _barRepo = barRepo; }
public UserBarService(UserBarRepository userBarRepo, BarRepository barRepo, BarReviewRepository barReviewRepo) { _userBarRepo = userBarRepo; _barRepo = barRepo; _barReviewRepo = barReviewRepo; }
public void TestGetBars() { List <BarModel> bars = new BarRepository().GetBars(); Assert.IsNotNull(bars); }
public BarService(BarRepository repo, BarReviewRepository reviewRepo, BarReviewService reviewService) { _barRepo = repo; _reviewRepo = reviewRepo; _reviewService = reviewService; }
public FavoriteBarService(FavoriteBarRepository userBarRepo, BarRepository barRepo, BarReviewRepository barReviewRepo) { _userBarRepo = userBarRepo; _barRepo = barRepo; _barReviewRepo = barReviewRepo; }
static void Main(string[] args) { //a unit of work is created using (var uow = UnitOfWorkFactory.Get()) { //get an instance of a repo var repo = new FooRepository(); var entity = repo.Get(uow, 2); //no committing is necessary on a SELECT } //let's save something using (var uow = UnitOfWorkFactory.Get()) { var repo = new FooRepository(); var entity = repo.Get(uow, 0) ?? new MyDbEntity(); entity.Name = "Minnie Mouse"; repo.Save(uow, entity); //we need to commit our changes or else it won't be saved! //if the code throws before this point, the entire transaction is rolled back uow.Commit(); } //let's delete something using (var uow = UnitOfWorkFactory.Get()) { var repo = new FooRepository(); var entity = repo.Get(uow, 2); if (entity != null) { repo.Delete(uow, entity); //if we don't make it here or this is never called, the transaction gets rolled back uow.Commit(); } } //the best part of a UOW pattern is that you can do many things across more than one repo and have them linked as a single transaction using (var uow = UnitOfWorkFactory.Get()) { //look, we need to manipulate TWO repos in the same transaction var fooRepo = new FooRepository(); var barRepo = new BarRepository(); var entity = fooRepo.Get(uow, 0) ?? new MyDbEntity(); entity.Name = "Minnie Mouse"; fooRepo.Save(uow, entity); var phoneNumber = new MyOtherDbEntity { PhoneNumber = "5558675309" }; barRepo.Save(uow, phoneNumber); //we need to commit our changes or else it won't be saved! //if the code throws before this point, the entire transaction is rolled back uow.Commit(); } }