public bool Delete(long id) { using (var contextAccessor = new WriteContextAccessor()) { var user = Get(id); if (user != null) { contextAccessor.ReadWriteContext.Users.Remove(user); contextAccessor.ReadWriteContext.SaveChanges(); return true; } } return false; }
public bool DeleteAll(ICollection<long> ids) { using (var contextAccessor = new WriteContextAccessor()) { var users = contextAccessor.ReadWriteContext.Users.Where(u => ids.Contains(u.Id)).ToList(); if (users.Any()) { contextAccessor.ReadWriteContext.Users.RemoveRange(users); contextAccessor.ReadWriteContext.SaveChanges(); return true; } } return false; }
public User CreateNew(NewUser model) { using (var contextAccessor = new WriteContextAccessor()) { SHA256Managed sha = new SHA256Managed(); sha.Initialize(); var user = new User { Name = model.UserName, PasswordHash = sha.ComputeHash(Encoding.UTF8.GetBytes(model.Password)).ToHexString() }; contextAccessor.ReadWriteContext.Users.Add(user); contextAccessor.ReadWriteContext.SaveChanges(); return user; } }