예제 #1
0
 public RequestService(RequestsRepository repo, BarRepository barRepo, UserBarRepository userBarRepo, UserManager <ApplicationUser> userManager)
 {
     _userManager = userManager;
     _repo        = repo;
     _barRepo     = barRepo;
     _userBarRepo = userBarRepo;
 }
예제 #2
0
        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);
        }
예제 #3
0
 public DrinkService(DrinkRepository drinkRepo, DrinkReviewRepository reviewRepo, BarRepository barRepo, ProfileRepository profileRepo)
 {
     _drinkRepo   = drinkRepo;
     _reviewRepo  = reviewRepo;
     _barRepo     = barRepo;
     _profileRepo = profileRepo;
 }
예제 #4
0
        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));
        }
예제 #5
0
 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();
 }
예제 #6
0
        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);
        }
예제 #7
0
        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));
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
 /// <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);
 }
예제 #11
0
        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);
        }
예제 #12
0
 public BarReviewService(BarReviewRepository repo, BarRepository barRepo)
 {
     _barReviewRepo = repo;
     _barRepo       = barRepo;
 }
예제 #13
0
 public UserBarService(UserBarRepository userBarRepo, BarRepository barRepo, BarReviewRepository barReviewRepo)
 {
     _userBarRepo   = userBarRepo;
     _barRepo       = barRepo;
     _barReviewRepo = barReviewRepo;
 }
예제 #14
0
        public void TestGetBars()
        {
            List <BarModel> bars = new BarRepository().GetBars();

            Assert.IsNotNull(bars);
        }
예제 #15
0
 public BarService(BarRepository repo, BarReviewRepository reviewRepo, BarReviewService reviewService)
 {
     _barRepo       = repo;
     _reviewRepo    = reviewRepo;
     _reviewService = reviewService;
 }
예제 #16
0
 public FavoriteBarService(FavoriteBarRepository userBarRepo, BarRepository barRepo, BarReviewRepository barReviewRepo)
 {
     _userBarRepo   = userBarRepo;
     _barRepo       = barRepo;
     _barReviewRepo = barReviewRepo;
 }
예제 #17
0
        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();
            }
        }