Beispiel #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);
 }
Beispiel #2
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();
        }
Beispiel #3
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();
 }
Beispiel #4
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());
 }
Beispiel #5
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);
        }
Beispiel #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();
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// Save method.
        /// </summary>
        public void Save()
        {
            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                var outputLines = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    outputLines.Add(string.Format("{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:", DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        outputLines.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                    }
                }
                System.IO.File.AppendAllLines(@"C:\errors.txt", outputLines);

                throw e;
            }
        }
Beispiel #11
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);
        }