Пример #1
0
        public HerbCount Delete(int herbId, string userName)
        {
            HerbCount herbCount = context.HerbCounts.Find(herbId, userName);

            if (herbCount != null)
            {
                context.HerbCounts.Remove(herbCount);
                context.SaveChanges();
            }
            return(herbCount);
        }
Пример #2
0
        public HerbViewModel Update(HerbCount herbCount)
        {
            var oldHerbCount = context.HerbCounts.Find(herbCount.HerbId, herbCount.UserName);

            if (oldHerbCount != null)
            {
                oldHerbCount.Count = herbCount.Count;
                context.HerbCounts.Update(oldHerbCount);
                context.SaveChanges();
            }
            var herbInfo = context.HerbInfos.Find(herbCount.HerbId);

            return(new HerbViewModel(herbInfo, herbCount.Count));
        }
Пример #3
0
        public IEnumerable <HerbViewModel> InstantiateHerbs(string userName)
        {
            List <HerbInfo> herbInfos = context.HerbInfos.ToList();
            var             herbs     = new List <HerbViewModel>();

            foreach (HerbInfo h in herbInfos)
            {
                var herbCount = new HerbCount()
                {
                    HerbId   = h.Id,
                    UserName = userName,
                    Count    = 0
                };
                herbs.Add(new HerbViewModel(h, herbCount.Count));
                context.HerbCounts.Add(herbCount);
            }
            context.SaveChanges();
            return(herbs);
        }
Пример #4
0
 public HerbViewModel Add(HerbCount herbCount)
 {
     context.HerbCounts.Add(herbCount);
     context.SaveChanges();
     return(new HerbViewModel(context.HerbInfos.Find(herbCount.HerbId), herbCount.Count));
 }