public void Create(DalUser entity)
 {
     var user = new Users()
     {
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     context.Set<Users>().Add(user);
     context.SaveChanges();
 }
        //private IUserRepository userRepository;//IAccountService!!!
        public MembershipUser CreateUser(string email, string password)
        {
            //userRepository = (IUserRepository)DependencyResolver.Current.GetService(typeof(IUserRepository));

            MembershipUser membershipUser = GetUser(email, false);

            if (membershipUser != null)
            {
                return null;
            }

            using (var context = new AlbumDbEntities())
            {
                var user = new Users
                {
                    Email = email,
                    Password = Crypto.HashPassword(password),
                    //http://msdn.microsoft.com/ru-ru/library/system.web.helpers.crypto(v=vs.111).aspx
                };

                var role = context.Roles.FirstOrDefault(r => r.Name == "user");
                if (role != null)
                {
                    user.Roles.Add(role);
                }
                if (!context.Users.Any())
                {
                    var adminRole = context.Roles.FirstOrDefault(r => r.Name == "admin");
                    if (adminRole != null)
                    {
                        user.Roles.Add(adminRole);
                    }
                }

                user.Name = "name";

                context.Users.Add(user);
                context.SaveChanges();
                membershipUser = GetUser(user.Email, false);
                return membershipUser;
            }
        }
 public void Update(DalUser entity)
 {
     var user = new Users()
     {
         Id = entity.Id,
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     context.Set<Users>().Attach(user);
     var entry = context.Entry(user);
     entry.Property(x => x.Login).IsModified = true;
     entry.Property(x => x.Password).IsModified = true;
     entry.Property(x => x.Name).IsModified = true;
     entry.Property(x => x.Role).IsModified = true;
     context.SaveChanges();
 }
 public void Delete(DalUser entity)
 {
     var user = new Users()
     {
         Id = entity.Id,
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     user = context.Set<Users>().Single(u => u.Id == user.Id);
     context.Set<Users>().Remove(user);
     context.SaveChanges();
 }