Esempio n. 1
0
 /// <summary>
 ///Add new Glass to pour beer from the tap
 /// </summary>
 public Glass AddGlass(Glass glass)
 {
     _dbContext = new BeerTapDBContext();
     _dbContext.Glasses.Add(glass);
     _dbContext.SaveChanges();
     return(glass);
 }
Esempio n. 2
0
 /// <summary>
 ///Add new Office
 /// </summary>
 public Office AddOffice(Office office)
 {
     _dbContext = new BeerTapDBContext();
     _dbContext.Offices.Add(office);
     _dbContext.SaveChanges();
     return(office);    //_dbContext.Offices.Where(o => o.Id == office.Id).FirstOrDefault();
 }
Esempio n. 3
0
 /// <summary>
 ///Add new Tap
 /// </summary>
 public Tap AddTap(Tap tap)
 {
     _dbContext = new BeerTapDBContext();
     _dbContext.Taps.Add(tap);
     _dbContext.SaveChanges();
     return(_dbContext.Taps.Where(o => o.Id == tap.Id).FirstOrDefault());
 }
Esempio n. 4
0
        /// <summary>
        ///Get Office Details by Id
        /// </summary>
        public Office GetOfficeById(int id)
        {
            _dbContext = new BeerTapDBContext();
            var office = _dbContext.Offices.Where(o => o.Id == id).FirstOrDefault();

            return(office);
        }
Esempio n. 5
0
        /// <summary>
        ///Remove an Office
        /// </summary>
        public void RemoveOffice(Office office)
        {
            _dbContext = new BeerTapDBContext();

            _dbContext.Entry(office).State = System.Data.Entity.EntityState.Deleted;
            _dbContext.SaveChanges();
        }
Esempio n. 6
0
        /// <summary>
        ///Remove a tap
        /// </summary>
        public void RemoveTap(int tapId)
        {
            _dbContext = new BeerTapDBContext();
            Tap tap = _dbContext.Taps.Where(o => o.Id == tapId).FirstOrDefault();

            _dbContext.Entry(tap).State = System.Data.Entity.EntityState.Deleted;
            _dbContext.SaveChanges();
        }
Esempio n. 7
0
        /// <summary>
        ///Update Office
        /// </summary>
        public Office  UpdateOffice(Office office)
        {
            _dbContext = new BeerTapDBContext();

            _dbContext.Entry(office).State = System.Data.Entity.EntityState.Modified;
            _dbContext.SaveChanges();
            return(office);
        }
Esempio n. 8
0
        /// <summary>
        ///Update Keg details
        /// </summary>
        public Keg UpdateKeg(int tapId)
        {
            _dbContext = new BeerTapDBContext();
            Keg keg = _dbContext.Kegs.Where(k => k.TapId == tapId).FirstOrDefault();

            keg.TapId = null;
            _dbContext.SaveChanges();
            return(keg);
        }
Esempio n. 9
0
        /// <summary>
        ///Update the Keg by Glass(pour beer)
        /// </summary>
        public Keg UpdateKegByGlass(Glass g)
        {
            _dbContext = new BeerTapDBContext();

            Keg keg = _dbContext.Kegs.Where(k => k.TapId == g.TapId).FirstOrDefault <Keg>();

            keg.Remaining -= g.AmountToPour;
            _dbContext.SaveChanges();

            return(null);
        }
Esempio n. 10
0
        /// <summary>
        ///Update Beer Tap
        /// </summary>
        public Tap UpdateTap(Tap tap)
        {
            _dbContext = new BeerTapDBContext();
            Tap t = _dbContext.Taps.Where(o => o.Id == tap.Id).Include("Keg").FirstOrDefault();

            t.Label    = tap.Label;
            t.OfficeId = tap.OfficeId;
            t.Keg      = tap.Keg;

            _dbContext.Entry(t).State = System.Data.Entity.EntityState.Modified;

            _dbContext.SaveChanges();
            return(tap);
        }
Esempio n. 11
0
        /// <summary>
        ///Get all Offices
        /// </summary>
        public IEnumerable <Office> GetOffices()
        {
            _dbContext = new BeerTapDBContext();


            //var subcate = (from a in _dbContext.Offices
            //               join b in _dbContext.Taps on a.Id equals b.OfficeId
            //               select new
            //               {
            //                   Id = a.Id,
            //                   Name = a.Name
            //               }).ToList().Select( x => new Office()
            //    {
            //        Id = x.Id,
            //        Name = x.Name
            //    }
            //    );
            return(_dbContext.Offices);
        }
Esempio n. 12
0
        /// <summary>
        ///Replace Keg
        /// </summary>
        public Keg ReplaceKeg(Keg keg)
        {
            _dbContext = new BeerTapDBContext();

            Keg oldKeg = GetKegByTapId(keg.TapId ?? 0);

            if (oldKeg != null)
            {
                //oldKeg.Tap = null;
                oldKeg.TapId = null;
            }


            Tap tap = _dbContext.Taps.Where(o => o.Id == keg.TapId).Include("Keg").FirstOrDefault();

            tap.Keg = keg;
            _dbContext.Kegs.Add(keg);

            _dbContext.SaveChanges();


            return(keg);
        }
Esempio n. 13
0
 /// <summary>
 ///Get all glasses transactions
 /// </summary>
 public IEnumerable <Glass> GetGlasses(int tapId)
 {
     _dbContext = new BeerTapDBContext();
     return(_dbContext.Glasses.Where(o => o.TapId == tapId));
 }
Esempio n. 14
0
 /// <summary>
 ///Get the current Keg of the Tap
 /// </summary>
 public Keg GetKegByTapId(int tapId)
 {
     _dbContext = new BeerTapDBContext();
     return(_dbContext.Kegs.Where(k => k.TapId == tapId).FirstOrDefault());
 }
Esempio n. 15
0
 /// <summary>
 ///Get all kegs
 /// </summary>
 public IEnumerable <Keg> GetKegs()
 {
     _dbContext = new BeerTapDBContext();
     return(_dbContext.Kegs.Include("Tap"));
 }
Esempio n. 16
0
 /// <summary>
 /// Public Constructor,initializes privately declared local variables.
 /// </summary>
 /// <param name="context"></param>
 public GenericRepository(BeerTapDBContext context)
 {
     this.Context = context;
     this.DbSet   = context.Set <TEntity>();
 }
Esempio n. 17
0
 /// <summary>
 ///Get Beer Taps int the office
 /// </summary>
 public IEnumerable <Tap> GetTaps(int officeId)
 {
     _dbContext = new BeerTapDBContext();
     return(_dbContext.Taps.Where(i => i.OfficeId == officeId).Include("Keg"));
 }
Esempio n. 18
0
 /// <summary>
 ///Get Beer Tap Details
 /// </summary>
 public Tap GetTapById(int id)
 {
     _dbContext = new BeerTapDBContext();
     return(_dbContext.Taps.Where(o => o.Id == id).Include("Keg").FirstOrDefault());
 }
Esempio n. 19
0
 public UnitOfWork()
 {
     _context = new BeerTapDBContext();
 }