public Keg GetById(string id) { var KegItem = Kegs.Find(b => b.id == id).FirstOrDefault(); KegItem = AttachEntities(KegItem); return(KegItem); }
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); }
public IEnumerable <Keg> GetAll() { var KegList = Kegs.Find(b => true).ToList(); KegList = AttachEntities(KegList).ToList(); return(KegList); }
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); }
public Keg Create(Keg item) { item.id = Guid.NewGuid().ToString(); item.kegSize = null; item.beer = null; Kegs.InsertOne(item); return(item); }
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); }
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); }
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 = "" }); }
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 }); }
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); }
public string Delete(Keg item) { Kegs.DeleteOne(b => b.id == item.id); return(item.id); }