コード例 #1
0
        public Keg GetById(string id)
        {
            var KegItem = Kegs.Find(b => b.id == id).FirstOrDefault();

            KegItem = AttachEntities(KegItem);
            return(KegItem);
        }
コード例 #2
0
        internal IEnumerable <PourEvent> AttachEntities(IEnumerable <PourEvent> pourEventList)
        {
            //Load Kegs
            var kegIdsToLoad = pourEventList.Select(p => p.kegId).Distinct().ToList();
            var kegs         = Kegs.Find(k => kegIdsToLoad.Contains(k.id)).ToList();

            kegs = AttachEntities(kegs).ToList();
            //Load Taps
            var tapIdsToLoad = pourEventList.Select(p => p.tapId).Distinct().ToList();
            var taps         = Taps.Find(t => tapIdsToLoad.Contains(t.id)).ToList();

            taps = AttachEntities(taps).ToList();

            pourEventList.ToList().ForEach(p => {
                if (p.kegId != null)
                {
                    p.keg = kegs.FirstOrDefault(k => k.id == p.kegId);
                }
                if (p.tapId != null)
                {
                    p.tap = taps.FirstOrDefault(t => t.id == p.tapId);
                }
            });
            return(pourEventList);
        }
コード例 #3
0
        public IEnumerable <Keg> GetAll()
        {
            var KegList = Kegs.Find(b => true).ToList();

            KegList = AttachEntities(KegList).ToList();
            return(KegList);
        }
コード例 #4
0
 public Keg Update(Keg item)
 {
     item.beer    = null;
     item.kegSize = null;
     //UpdateOne if need performance
     Kegs.ReplaceOne(b => b.id == item.id, item);
     return(item);
 }
コード例 #5
0
 public Keg Create(Keg item)
 {
     item.id      = Guid.NewGuid().ToString();
     item.kegSize = null;
     item.beer    = null;
     Kegs.InsertOne(item);
     return(item);
 }
コード例 #6
0
 internal Tap AttachEntities(Tap tapItem)
 {
     if (tapItem != null && tapItem.current_keg_id != null)
     {
         var keg = Kegs.Find(k => k.id == tapItem.current_keg_id).FirstOrDefault();
         keg = AttachEntities(keg);
         tapItem.current_keg = keg;
     }
     return(tapItem);
 }
コード例 #7
0
 internal PourEvent AttachEntities(PourEvent pourEventItem)
 {
     if (pourEventItem != null && pourEventItem.kegId != null)
     {
         var keg = Kegs.Find(k => k.id == pourEventItem.kegId).FirstOrDefault();
         keg = AttachEntities(keg);
         pourEventItem.keg = keg;
     }
     if (pourEventItem != null && pourEventItem.tapId != null)
     {
         var tap = Taps.Find(t => t.id == pourEventItem.tapId).FirstOrDefault();
         tap = AttachEntities(tap);
         pourEventItem.tap = tap;
     }
     return(pourEventItem);
 }
コード例 #8
0
ファイル: EditTapViewModel.cs プロジェクト: pwalke/Pourcast
        public EditTapViewModel(IEnumerable <KegModel> kegs, string kegId)
        {
            if (null == kegs)
            {
                throw new ArgumentNullException("kegs");
            }

            Kegs = kegs.Select(k => new SelectListItem()
            {
                Text = k.BeerName, Value = k.Id, Selected = (k.Id == kegId)
            }).ToList();
            Kegs.Insert(0, new SelectListItem()
            {
                Text = Resources.Admin_Tap_Edit_Dropdownlist, Value = ""
            });
        }
コード例 #9
0
ファイル: CreateTapViewModel.cs プロジェクト: pwalke/Pourcast
        public CreateTapViewModel(IEnumerable <KegModel> kegs)
        {
            if (null == kegs)
            {
                throw new ArgumentNullException("kegs");
            }

            Kegs = kegs.Select(k => new SelectListItem()
            {
                Text = k.BeerName, Value = k.Id
            }).ToList();
            Kegs.Insert(0, new SelectListItem()
            {
                Text = Resources.Admin_Tap_Create_Dropdownlist, Value = "", Selected = true
            });
        }
コード例 #10
0
        internal IEnumerable <Tap> AttachEntities(IEnumerable <Tap> tapList)
        {
            //Load Kegs
            var kegIdsToLoad = tapList.Select(t => t.current_keg_id).Distinct().ToList();
            var kegs         = Kegs.Find(k => kegIdsToLoad.Contains(k.id)).ToList();

            kegs = AttachEntities(kegs).ToList();

            tapList.ToList().ForEach(t => {
                if (t.current_keg_id != null)
                {
                    var current_keg = kegs.FirstOrDefault(k => k.id == t.current_keg_id);
                    t.current_keg   = current_keg;
                }
            });
            return(tapList);
        }
コード例 #11
0
 public string Delete(Keg item)
 {
     Kegs.DeleteOne(b => b.id == item.id);
     return(item.id);
 }