コード例 #1
0
        private static List<PickViewModel> GetFilteredList(int? id = null, string userId = null, int? week = null, int? scheduleId = null)
        {
            var predicate = PredicateBuilder.True<Pick>();
            if (id.HasValue)
            {
                predicate = predicate.And(p => p.Id == id.Value);
            }
            if (week.HasValue)
            {
                predicate = predicate.And(p => p.Schedule.Week == week.Value);
            }
            if (userId != null)
            {
                predicate = predicate.And(p => p.UserId == userId);
            }
            if (scheduleId.HasValue)
            {
                predicate = predicate.And(p => p.Schedule.Id == scheduleId.Value);
            }

            using (var db = new PicksDb())
            {
                return db.Picks.Include("Schedule").OrderBy(p => p.Schedule.Date).AsExpandable().Where(predicate).ToList().Select(p => PickViewModel.FromPick(p)).ToList();
            }
        }
コード例 #2
0
        public void Save()
        {
            var pick = ToPick();

            using (var db = new PicksDb())
            {
                db.Entry(pick).State = (Id == 0) ? EntityState.Added : EntityState.Modified;

                db.SaveChanges();
            }
        }
コード例 #3
0
ファイル: PickViewModels.cs プロジェクト: suceava/Foosball
        public static void DeleteForUser(string userId)
        {
            var picks = PickViewModel.GetListForUser(userId, null);
            using (var db = new PicksDb())
            {
                foreach (var pick in picks)
                {
                    var p = pick.ToPick();

                    db.Entry(p).State = EntityState.Deleted;
                }
                db.SaveChanges();
            }
        }