private void BanUser(UserEntity user)
 {
     user.UserBanned = true;
     _userService.UpdateUser(user);
     _bidService.DeleteAllBidsByUser(user.Id);
     _lotService.CloseAllActiveLotsCreatedByUser(user);
 }
        public MembershipUser CreateUser(UserEntity userEntity)
        {
            MembershipUser membershipUser = GetUser(userEntity.Login, false);

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

            userEntity.Password = Crypto.HashPassword(userEntity.Password);
            UserService.CreateUser(userEntity);
            var user = UserService.GetUserByLogin(userEntity.Login);
            var userRole = new RoleUserEntity
            {
                UserId = user.Id
            };            
            RoleEntity role = RoleService.GetAllRoleEntities().FirstOrDefault(r => r.RoleOfUser == "simple user");           
            if (role != null )
            {
                userRole.RoleId = role.Id;
            }

           
            RoleUserService.CreateRoleUser(userRole);
            membershipUser = GetUser(userEntity.Login, false);
            return membershipUser;
        }
        public ActionResult Register(UserRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new UserEntity()
                {
                    Name = model.Name,
                    Password = model.Password,
                    Roles = new List<RoleEntity>() { new RoleEntity() { Id = 3 } }
                };

                user = _userService.CreateUser(user);
                if (user != null)
                {
                    _signService.IdentitySignin(user);
                    return RedirectToAction("Index", "Home",null);
                }

                ViewBag.Error = "This user already exists";
                return View("Register");
            }
            ViewBag.Error = string.Join("; ", ModelState.Values
                                        .SelectMany(x => x.Errors)
                                        .Select(x => x.ErrorMessage)); ;
            return View("Register");

        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new UserEntity()
                {
                    Login = model.UserName,
                    E_mail = model.UserEmail,
                    Password = model.Password,
                    Role_Id = 2
                };

                MembershipUser membershipUser = ((CustomMembershipProvider)Membership.Provider).CreateUser(user);

                if (membershipUser != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Registration error.");
                }
            }
            return View(model);
        }
        public MembershipUser CreateUser(string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

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

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

            var role = RoleService.GetRoleEntityByName("User");
            if (role != null)
            {
                user.RoleId = role.Id;
            }

            UserService.CreateUser(user);
            membershipUser = GetUser(email, false);
            return membershipUser;
        }
        public MembershipUser CreateUser(string login, string password, 
            string email, string firstName, string lastName, DateTime birthDate)
        {
            MembershipUser membershipUser = GetUser(login, false);

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

            var user = new UserEntity
            {
                Login = login,
                Password = Crypto.HashPassword(password),

                //http://msdn.microsoft.com/ru-ru/library/system.web.helpers.crypto(v=vs.111).aspx
                //CreationDate = DateTime.Now
            };

            var profile = new ProfileEntity
            {
                FirstName = firstName,
                LastName = lastName,
                Email = email,
                BirthDate = birthDate
            };

            user.RoleId = RoleService.GetRoleId("User");
            
            UserService.CreateUser(user, profile);
            membershipUser = GetUser(login, false);
            return membershipUser;
        }
 /// <summary>
 /// Create new user and save it to database.
 /// </summary>
 /// <param name="user"></param>
 public void CreateUser(UserEntity user)
 {
     if (user == null)
         throw new ArgumentNullException(nameof(user));
     userRepository.Create(user.ToDalUser());
     uow.Commit();
 }
Example #8
0
 public void Init(string name, IUserService repository)
 {
     if (!string.IsNullOrEmpty(name))
     {
         User = repository.GetUserByName(name);
     }
 }
Example #9
0
 public UserEntity CreateUser(UserEntity user)
 {
     user.Roles.Add(userRepository.GetRole("User").ToBllRole());
     var temp = userRepository.Create(user.ToDalUser());
     if (temp != null)
         uow.Commit();
     return temp?.ToBllUser();
 }
 public void UpdateUser(UserEntity user)
 {
    var blluser= userRepository.GetById(user.Id).ToBllUser();
     if (blluser==null) throw new ArgumentNullException();
     user.Password = blluser.Password;
     user.CreationDate =blluser.CreationDate;
     userRepository.Update(user.ToDalUser());
     uow.Commit();
 }
 public void CreateUser(UserEntity user, ProfileEntity profile)
 {
     DalUser du = user.ToDalUser();
     du.Profile = profile.ToDalProfile();
     DalProfile dp = profile.ToDalProfile();
     dp.User = user.ToDalUser();
     uow.Users.Create(du);
     //uow.Profiles.Create(dp);
     uow.Commit();
 }
 public ActionResult Create(RegistrationViewModel user)
 {
     var blluser = new UserEntity()
     {
         UserName = user.UserName,
         RoleId = (int)user.Role
     };
     service.CreateUser(blluser);
     return RedirectToAction("Index");
 }
 public void UpdateUser(UserEntity user)
 {
     try
     {
         _userRepository.Update(user.ToDalUser());
         _unitOfWorkuow.Commit();
     }
     catch (Exception e)
     {
         Log.LogError(e);
     }
 }
Example #14
0
        public UserViewModel ToMvcUser(UserEntity user)
        {
            var profile = profileService.GetProfileByUserId(user.Id);
            if (profile == null) profile = new ProfileEntity();
            return new UserViewModel()
            {
                Id = user.Id,
                Email = user.Email,
                FirstName = profile.FirstName,
                LastName = profile.LastName,
                Role = (Role)user.RoleId

            };
        }
 public ActionResult Create(RegisterModel user)
 {
     
     var blluser = new UserEntity()
     {
         Login = user.UserName,
         Role_Id = 2, // user
         RegistryDate = DateTime.Now,
         Password = "******",
         E_mail = "12345"                
     };
     service.Create(blluser);
     return RedirectToAction("Index");
 }
        public ActionResult Index(RegistrationViewModel user)
        {
            var blluser = new UserEntity()
            {
                UserName = user.UserName,
                Email = user.Email,
                Password = user.Password,
                Roles = new List<RoleEntity>()
            };
            blluser.Roles.Add(new RoleEntity() { Name = "User" });
            UserService.CreateUser(blluser);

            return RedirectToAction("Index", "Home");
        }
 private void PopulateRoles(UserEntity user)
 {
     var allRoles = _userService.GetAllRoles();
     var userRoles = new HashSet<int>(user.Roles.Select(x => x.Id));
     var viewModel = new List<RoleViewModel>();
     foreach (var role in allRoles)
     {
         viewModel.Add(new RoleViewModel()
         {
             Id = role.Id,
             Name = role.Name,
             IsAssigned = userRoles.Contains(role.Id)
         });
     }
     ViewBag.Roles = viewModel;
 }
Example #18
0
        public void IdentitySignin(UserEntity user, bool isPersistent = false)
        {
            var claims = new List<Claim>();

            claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()));
            claims.Add(new Claim(ClaimTypes.Name, user.Name));
            foreach (var role in user.Roles)
            {
                claims.Add(new Claim(ClaimTypes.Role, role.Name));
            }

            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc = DateTime.UtcNow.AddDays(7)
            }, identity);
        }
        private void CreateCookie(HttpContext context, UserEntity user, bool isPersistent = false)
        {
            var ticket = new FormsAuthenticationTicket(
                1,
                user.UserEmail,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                isPersistent,
                string.Empty,
                FormsAuthentication.FormsCookiePath);


            var encTicket = FormsAuthentication.Encrypt(ticket);

            var authCookie = new HttpCookie(CookieName)
            {
                Value = encTicket,
                Expires = DateTime.Now.AddDays(1)
            };
            context.Response.Cookies.Set(authCookie);
        }
        public MembershipUser CreateUser(string username, string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

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

            var user = new UserEntity()
            {
                Username = username,
                Email = email,
                Password = Crypto.HashPassword(password),
                RegistrationDate = DateTime.Now,
            };

            userService.Create(user);
            membershipUser = GetUser(email, false);
            return membershipUser;
        }
        public MembershipUser CreateUser(string login, string password,string userName)
        {
            MembershipUser membershipUser = GetUser(login, false);

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

            var user = new UserEntity
            {
                Login = login,
                Password = password,
                Ban = false,
                UserName = userName,
            };

            user.RoleId = roleService.GetByRoleName("User").Id;

            userService.CreateUser(user);
            membershipUser = GetUser(login, false);
            return membershipUser;
        }
        public MembershipUser CreateUser(UserEntity user)
        {
            if (user == null) return null;

            MembershipUser membershipUser = null;

            try
            {
                //userService = (IUserService)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IUserService));

                membershipUser = GetUser(user.Login, false);

                if (membershipUser == null)
                {
                    userService.Create(user);
                    membershipUser = GetUser(user.Login, false);                    
                }
            }
            catch
            {
                return null;
            }
            return membershipUser;
        }
 public void DeleteUser(UserEntity user)
 {
     userRepository.Delete(user.ToDalUser());
     unitOfWork.Commit();
 }
 public void AddUser(UserEntity user)
 {
     userRepository.Create(user.ToDalUser());
     unitOfWork.Commit();
 }
        public MembershipUser CreateUser(string email, string password)
        {
            userService = (IService<UserEntity>)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IService<UserEntity>));
            roleService = (IService<RoleEntity>)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IService<RoleEntity>));
            MembershipUser membershipUser = GetUser(email, false);
            if (membershipUser != null)
                return null;
                var user = new UserEntity
                {
                    Email = email,
                    Password = Crypto.HashPassword(password),
                    Files = new List<FileEntity>(),
                    Roles = new List<RoleEntity>(),
                    Profile = new ProfileEntity{Age=0,FirstName = "Noname",LastName = "Noname",LastUpdate = DateTime.Now}
                };

                var role = roleService.GetAllEntities().FirstOrDefault(r => r.Name == "User");
                if (role != null)
                {
                    user.Roles.Add(role);
                }
                userService.Create(user);
                membershipUser = GetUser(email, false);
                return membershipUser;
        }
Example #26
0
 public ICollection<RoleEntity> GetRoles(UserEntity user)
 {
     throw new NotImplementedException();
     //return roleRepository.GetById(user.RoleId).ToBllRole();
 }
Example #27
0
 public void CreateUser(UserEntity user)
 {
     userRepository.Create(user.ToDalUser());
     uow.Commit();
 }
        public IEnumerable<ProjectEntity> GetAllProjectsByUser(UserEntity user)
        {

            return repository.GetAllProjectsByUser(user.ToDalUser()).Select(p=>p.ToBllProject());
        }
 public void DeleteUserFromProject(UserEntity user, int projectId)
  {
      repository.DeleteUserFromProject(user.ToDalUser(), projectId);
      uow.Commit();
  }
 public void AddUserToProject(UserEntity user, int projectId)
  {
      repository.AddUserToProject(user.ToDalUser(), projectId);
      uow.Commit();
  }