Пример #1
0
        public void Update(SystemUserViewModel systemUserViewModel)
        {
            if (_systemUserRepository.GetExactEmail(systemUserViewModel.Email) != null)
            {
                throw new BusisnessException("Já existe um usuário cadastrado com este e-mail");
            }

            var passwordPower = UtilValidation.GetPasswordPower(systemUserViewModel.Password);

            if ((int)passwordPower < 3)
            {
                throw new BusisnessException($"A senha digitada não atende os requisitos mínimos - Nível {passwordPower}");
            }

            if (systemUserViewModel.Password != systemUserViewModel.ConfirmPassword)
            {
                throw new BusisnessException($"A senha digitada não é igual a confirmação de senha");
            }

            var model = _mapper.Map <SystemUserViewModel, SystemUser>(systemUserViewModel);

            model.Password = EncryptData.EncryptPassword(model.Password);

            _systemUserRepository.Add(model);
        }
Пример #2
0
        public IActionResult PutUser(int id, [FromBody] SystemUserViewModel value)
        {
            try
            {
                var result = _systemUserAppService.GetById(id);

                if (result == null)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    _systemUserAppService.Update(value);
                    return(NoContent());
                }

                return(BadRequest(new { Errors = ModelState }));
            }
            catch (BusisnessException ex)
            {
                return(BadRequest(new { Errors = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex.StackTrace);
                return(BadRequest(new { Errors = $"Erro não catalogado. Entre em contato com Administrador. Erro - {ex.Message}" }));
            }
        }
Пример #3
0
        public IActionResult Authenticate([FromBody] SystemUserViewModel userVM)
        {
            var user = _userService.Authenticate(userVM.Cpf, userVM.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Senha ou Cpf incorretos" }));
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.ID.ToString()),
                    new Claim(ClaimTypes.Role, user.GetType().Name)
                }),
                Expires            = DateTime.UtcNow.AddDays(1),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            // return basic user info (without password) and token to store client side
            return(Ok(new
            {
                Id = user.ID,
                Cpf = user.Cpf,
                Name = user.Name,
                Token = tokenString
            }));
        }
        public SystemUserViewModel PrepareAdministrationSystemUserViewModel()
        {
            SystemUserViewModel model = new SystemUserViewModel();

            model.ListOfListSystemUsers.AddRange(_userService.GetAllUsersByRole("Individual").Result);
            model.ListOfAgents.AddRange(_userService.GetAllUsersByRole("Agent").Result);

            return(model);
        }
Пример #5
0
        private static List <SystemUserViewModel> GetSystemUserViewModels(int courseId, List <SystemUser> users)
        {
            List <SystemUserViewModel> userViewModels = new List <SystemUserViewModel>();

            foreach (var user in users)
            {
                SystemUserViewModel mv = PopulateSystemUserViewModel(courseId, user);

                userViewModels.Add(mv);
            }

            return(userViewModels);
        }
Пример #6
0
        // GET: SystemUsers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SystemUserViewModel systemUser = Mapper.Map <SystemUserViewModel>(systemUserService.Get(id.Value));

            if (systemUser == null)
            {
                return(HttpNotFound());
            }
            return(View(systemUser));
        }
Пример #7
0
        public ActionResult Post([FromBody] SystemUserViewModel userVM)
        {
            var user = _mapper.Map <SystemUser>(userVM);

            try
            {
                _userService.Create(user, userVM.Password);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Пример #8
0
        private static List <SystemUserViewModel> GetSystemUserViewModels(int?courseId, List <SystemUserCourse> userCourses)
        {
            List <SystemUserViewModel> userViewModels = new List <SystemUserViewModel>();

            foreach (var item in userCourses)
            {
                var user = item.SystemUser;
                SystemUserViewModel mv = PopulateSystemUserViewModel((int)courseId, user);

                userViewModels.Add(mv);
            }

            return(userViewModels);
        }
Пример #9
0
        public IActionResult UsersForCourseEditPartial(IEnumerable <SystemUser> users)
        {
            var result = new List <SystemUserViewModel>();

            foreach (var user in users)
            {
                var model = new SystemUserViewModel
                {
                    Name = user.Name,
                    Id   = user.Id
                };
                result.Add(model);
            }

            return(PartialView(result));
        }
Пример #10
0
        // GET: SystemUsers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SystemUserViewModel systemUser = Mapper.Map <SystemUserViewModel>(systemUserService.Get(id.Value));

            if (systemUser == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId    = new SelectList(companyService.GetAll(), "Id", "Name", systemUser.CompanyId);
            ViewBag.DepartmentId = new SelectList(departmentService.GetAll(), "Id", "Name", systemUser.DepartmentId);
            ViewBag.PositionId   = new SelectList(positionService.GetAll(), "Id", "Name", systemUser.PositionId);
            return(View(systemUser));
        }
Пример #11
0
        public ActionResult Put(int id, [FromBody] SystemUserViewModel userVM)
        {
            // map dto to entity and set id
            var user = _mapper.Map <SystemUser>(userVM);

            user.ID = id;

            try
            {
                // save
                _userService.Update(user, userVM.Password);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Пример #12
0
        public IActionResult PostUser([FromBody] SystemUserViewModel value)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _systemUserAppService.Save(value);
                    return(NoContent());
                }

                return(BadRequest(new { Errors = ModelState }));
            }
            catch (BusisnessException ex)
            {
                return(BadRequest(new { Errors = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex.StackTrace);
                return(BadRequest(new { Errors = $"Erro não catalogado. Entre em contato com Administrador. Erro - {ex.Message}" }));
            }
        }
 public void RegisterUser(SystemUserViewModel OnlineUser)
 {
     NotificationHub.Users.Add(Context.ConnectionId, OnlineUser);
     UpdateUserList();
 }
Пример #14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SystemUser user;

            if (btnAdd.Text == "&CANCEL")   //  ADD NEW
            {
                if (InputsAreValid())
                {
                    user               = new SystemUser(); //  create new User
                    user.LastName      = txtLastName.Text;
                    user.FirstName     = txtFirstName.Text;
                    user.MiddleName    = txtMiddleName.Text;
                    user.Username      = lblUsernameOutput.Text;
                    user.UserLevel     = cboUserLevel.Text;
                    user.Pword         = lblUsernameOutput.Text;
                    user.AccountStatus = true;

                    _userBLL.InsertUser(user);

                    PopulateUserDatagridView();
                    dgvUser.ClearSelection();
                    SetUIProperty(Operation.Clear);

                    lblStatus.Text = "  Successfully added new user";
                }
            }

            if (btnEdit.Text == "&CANCEL")  //  EDIT
            {
                if (InputsAreValid())
                {
                    //  editing so get user from the selected user in the datagridview
                    user = _userViewModelList.Where(u => u.UserId == _userId)
                           .Select(u => new SystemUser
                    {
                        UserId        = u.UserId,                       //  assign user id (Primary Key) so it can be tracked by EF
                        LastName      = u.LastName,
                        FirstName     = u.FirstName,
                        MiddleName    = u.MiddleName,
                        Username      = u.Username,
                        UserLevel     = u.UserLevel,
                        AccountStatus = u.AccountStatus
                    }).SingleOrDefault();

                    user.LastName      = txtLastName.Text;
                    user.FirstName     = txtFirstName.Text;
                    user.MiddleName    = txtMiddleName.Text;
                    user.Username      = lblUsernameOutput.Text;
                    user.UserLevel     = cboUserLevel.Text;
                    user.AccountStatus = chkStatus.Checked;

                    _userBLL.UpdateUser(user);
                    //  update selected user in the list
                    SystemUserViewModel userViewModel = _userViewModelList.Where(u => u.UserId == _userId).SingleOrDefault();
                    userViewModel.LastName      = txtLastName.Text;
                    userViewModel.FirstName     = txtFirstName.Text;
                    userViewModel.MiddleName    = txtMiddleName.Text;
                    userViewModel.Username      = lblUsernameOutput.Text;
                    userViewModel.UserLevel     = cboUserLevel.Text;
                    userViewModel.AccountStatus = chkStatus.Checked;

                    RefreshDataSource();
                    SetUIProperty(Operation.Clear);

                    lblStatus.Text = "  Successfully updated user";
                }
            }
        }