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(); } }
public void Save() { var pick = ToPick(); using (var db = new PicksDb()) { db.Entry(pick).State = (Id == 0) ? EntityState.Added : EntityState.Modified; db.SaveChanges(); } }
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(); } }