예제 #1
0
 public ActionResult Create(User user)
 {
     if (new UsersServices().GetByUserName(User.Identity.Name).Company.CompaniesType.Name == "Customer")
     {
         user.Company_Id = new UsersServices().GetByUserName(User.Identity.Name).Company_Id;
     }
     if (GetAuthorization(user))
     {
         ValidateUserModel(user);
         ImageFileValidation();
         if (ModelState.IsValid)
         {
             if (_userService.Add(user))
             {
                 UploadImageToServer(user.Id);
                 _userService.SaveChanges();
                 EmailBroadcaster.SendEmail(ViewRes.Controllers.Users.UserWelcome, ViewRes.Controllers.Users.Message, user.Email);
                 return(RedirectToAction("Index"));
             }
         }
         InitializeViews(null);
         return(View(_userViewModel));
     }
     else
     {
         return(RedirectToLogOn());
     }
 }
        public MembershipUser CreateUser(string login, string password, string email, out MembershipCreateStatus status)
        {
            UsersServices userService = new UsersServices();

            if (userService.GetByEmail(email).Email != String.Empty)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }
            else if (userService.GetByUserName(login).UserName != String.Empty)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return(null);
            }
            else
            {
                User user = new User();
                user.UserName                   = login;
                user.Password                   = EncryptPassword(password);
                user.Email                      = email;
                user.CreationDate               = DateTime.Now;
                user.LastLockOutDate            = DateTime.Now;
                user.LastPasswordChangedDate    = DateTime.Now;
                user.LastLoginDate              = DateTime.Now;
                user.LastLogoutDate             = DateTime.Now;
                user.FailedLoginAttemptsCounter = 0;
                user.IsApproved                 = true;
                user.IsLockedOut                = false;
                user.IsOnline                   = false;
                userService.Add(user);
                status = MembershipCreateStatus.Success;

                return(GetMembershipUser(login));
            }
        }
        public void addToolStripButton_Click(object sender, EventArgs e)
        {
            var newDataUsers = new Users
            {
                Roles = new Roles()
            };
            var newWindow = new EditUsersView(newDataUsers);

            var res = newWindow.ShowDialog();

            if (res == DialogResult.OK)
            {
                _usersDataGridView.Rows.Add(newDataUsers.Name, newDataUsers.PhoneNumber, newDataUsers.Roles.Role);
                _services.Add(newDataUsers);
                GetData(_services.GetAll());
            }
        }
예제 #4
0
 public ActionResult Save(UsersViewModel viewModel)
 {
     SessionKontrol();
     if (_users != null)
     {
         try
         {
             var isValid = Validate(viewModel, new UserValidator(), ModelState);
             if (isValid)
             {
                 if (viewModel.Id == 0)
                 {
                     viewModel.Status = true;
                     _UsersServices.Add(viewModel);
                 }
                 else
                 {
                     viewModel.Status = true;
                     _UsersServices.Update(viewModel);
                 }
             }
             else
             {
                 return(View(ViewForm, viewModel));
             }
         }
         catch (Exception)
         {
             return(View(ViewForm, viewModel));
         }
         _unitOfWork.SaveChanges();
         return(RedirectToAction("UserList", "User"));
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }