public void Add(EventCheckInModel checkIn) { using (var db = new HIPContext()) { db.EventCheckIns.Add(checkIn); db.SaveChanges(); } }
public void Update(EventModel eventModel) { using (var db = new HIPContext()) { var events = db.Events.Attach(eventModel); db.SaveChanges(); } }
public UserModel Get(string email) { using (var db = new HIPContext()) { var users = db.Users .Where(b => b.Email == email) .ToList(); return(users.ElementAt(0)); } }
public EventModel Get(string id) { using (var db = new HIPContext()) { var events = db.Events .Where(b => b.Id == id) .Include(e => e.RecurringOccurrences) .Include(e => e.Occurrences) .Include(e => e.Blackouts) .ToList(); return(events.Count() > 0 ? events.ElementAt(0) : null); } }
public void Update(UserModel user) { if (user.Email == null || user.ParentEmail == null) { throw new Exception("in order to update a user, and email must be present"); } if (user.FirstName == null || user.LastName == null) { throw new Exception("in order to update an existing user, both first and last names must be provided"); } using (var db = new HIPContext()) { var users = db.Users.Attach(user); db.SaveChanges(); } }
public void Add(UserModel user) { using (var db = new HIPContext()) { var existingUsers = db.Users.Where(u => u.Email == user.Email).ToList(); if (existingUsers != null && existingUsers.Count() > 0) { Update(existingUsers.First()); } else { db.Users.Add(user); db.SaveChanges(); } } }
public void Add(EventModel eventModel) { try { using (var db = new HIPContext()) { db.Events.Add(eventModel); db.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public IEnumerable <EventModel> GetAll() { using (var db = new HIPContext()) { try { var events = db.Events .Include(e => e.RecurringOccurrences) .Include(e => e.Occurrences) .Include(e => e.Blackouts) .ToList(); return(events); } catch (Exception e) { Console.WriteLine(e); throw; } } }