Example #1
0
        public Identity(User user)
        {
            if (user == null)
            {
                Email = "Guest";
                return;
            }

            Id = user.Id;
            Email = user.Email;
        }
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Email = e.Email,
         CreationDate = e.CreationDate,
         Password = e.Password,
         RoleId = e.RoleId
     };
     context.Set<User>().Add(user);
     context.SaveChanges();
 }
Example #3
0
 public void Create(DalUser entity)
 {
     User user = new User()
     {
         Name = entity.Name,
         Email = entity.Email,
         Password = entity.Password,
         CreationDate = entity.CreationDate,
         RoleId = entity.RoleId
     };
     _context.Set<User>().Add(user);
 }
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Login = e.Login,
         Role_Id = e.Role_Id,
         Password = e.Password,
         RegistryDate = DateTime.Now,
         E_mail = e.E_mail
     };
     context.Set<User>().Add(user);
 }
 public void Add(User entity)
 {
     DbEntityEntry<User> dbEntity = _context.Entry<User>(entity);
     dbEntity.State = EntityState.Added;
     if (_context != null)
     {
         _context.SaveChanges();
         foreach (var ent in _context.ChangeTracker.Entries())
         {
             ((IObjectContextAdapter)_context).ObjectContext.Detach(ent.Entity);
         }
     }
 }
 public static void CopyFieldsTo(this DalUser source, User target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     target.Login = source.Login;
     target.Roles = source.Roles.Select(item => item.ToRole()).ToList();
 }
Example #7
0
 public void Delete(DalUser entity)
 {
     User user = new User()
     {
         Id = entity.Id,
         Name = entity.Name,
         Email = entity.Email,
         Password = entity.Password,
         CreationDate = entity.CreationDate,
         RoleId = entity.RoleId
     };
     user = _context.Set<User>().Single(u => u.Id == user.Id);
     _context.Set<User>().Remove(user);
 }
Example #8
0
        public static User ToModel(this DalUserEntity item)
        {
            if (item == null)
                return null;

            User userEntity = new User
            {
                Id = item.Id,
                Name = item.Name,
                Password = item.Password,
                RoleId = item.DalRole.Id
            };
            return userEntity;
        }
Example #9
0
 public static void CopyFieldsTo(this DalUser source, User target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     target.Name = source.Name;
     target.RoleId = source.RoleId;
     target.Blog = source.Blog == null ? null : source.Blog.ToBlog();
 }
Example #10
0
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Name = e.Name,
         Password = e.Password,
         Email = e.Email,
         Roles = new List<Role>()
     };
     foreach (var dalRole in e.Roles)
     {
         user.Roles.Add(context.Set<Role>().FirstOrDefault(m => m.Name == dalRole.Name));
     }
     context.Set<User>().Add(user);
     context.SaveChanges();
 }
        /// <summary>
        /// create new user
        /// </summary>
        /// <returns>null if user exist</returns>
        public static User CreateUser(string email, string password)
        {
            IUserRepository users = (IUserRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IUserRepository));
            User membershipUser = null;

            if (null == FindUser(email))
            {
                User user = new User()
                            {
                                Id = Guid.NewGuid(),
                                Email = email,
                                Password = Crypto.HashPassword(password)
                            };
                users.Add(user);
                membershipUser = user;
            }

            return membershipUser;
        }
Example #12
0
        static void Main(string[] args)
        {
            string connectionString = @"Data Source=localhost\sqlexpress;Integrated Security=SSPI;Initial Catalog=Demo";
            Database.Init(typeof(User).Assembly, connectionString);

            User[] users = Database.FindAll<User>();
            //Database.Transaction(delegate
            //{
            //    foreach (User user in users)
            //    {
            //        user.Email = user.Firstname + "$" + user.Lastname + "@bar.com";
            //        Database.Save(user);
            //    }
            //});

            Database.Transaction(delegate
             {
                 User user = new User();
                 user.Lastname = "lala";
                 user.Firstname = "orennn";
                 user.Email = "[email protected]";
                 user.Username = "username";

                 Database.Create(user);
                 Console.WriteLine("User {0}, created with ID: {1}", user.Username, user.Id);
             });

            Database.Transaction(delegate
             {
                 User user = new User();
                 user.Lastname = "lala";
                 user.Firstname = "orennn";
                 user.Email = "[email protected]";
                 user.Username = "username";

                 Database.Create(user);
                 Console.WriteLine("User {0}, created with ID: {1}", user.Username, user.Id);
                 bool res=Database.Delete(user);
                 Console.WriteLine(res);  
             });
        }
 private DalUser ConvertToDalUserFromOrmUser(User ormuser)
 {
     return new DalUser()
     {
         Id = ormuser.Id,
         Login = ormuser.Login,
         E_mail = ormuser.E_mail,
         Password = ormuser.Password,
         Role_Id = ormuser.Role_Id,
         RegistryDate = ormuser.RegistryDate,
         Products = ormuser.Products.Select(product => new DalProduct()
         {
             Id = product.Id,
             Auction_Cost = product.Auction_Cost,
             AuctionStart = product.AuctionStart,
             AuctionEnd = product.AuctionEnd,
             Seller_Id = product.Seller_Id,
             Buyer_Id = product.Buyer_Id,
             Description = product.Description
         }).ToList(),
         Products1 = ormuser.Products.Select(product => new DalProduct()
         {
             Id = product.Id,
             Auction_Cost = product.Auction_Cost,
             AuctionStart = product.AuctionStart,
             AuctionEnd = product.AuctionEnd,
             Seller_Id = product.Seller_Id,
             Buyer_Id = product.Buyer_Id,
             Description = product.Description
         }).ToList()
     };
 }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);