public void AddUser(User user) { try { db.Users.Add(new Models.User { Name = user.Name, EmailId = user.Email }); db.SaveChanges(); } catch (Exception e) { throw e; } }
public User GetUser(int id) { User user = db.Users.Where(x => x.Id == id).Select(x => new User() { Id = x.Id, Name = x.Name, Email = x.EmailId }).FirstOrDefault(); if (user == null) { return(null); } return(user); }
public void UpdateUserById(int id, User user) { var dbUser = db.Users.Where(x => x.Id == id).FirstOrDefault(); if (dbUser != null) { dbUser.Name = user.Name; db.Entry(dbUser).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception e) { throw e; } return; } }