Exemple #1
0
        public IActionResult InsertRole(InsertRoleDto input)
        {
            try
            {
                #region Validation
                var validator = new ParamValidator();
                validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان"))
                .Throw(General.Results_.FieldNullErrorCode());

                #endregion

                var role = new Role
                {
                    Cdate   = DateTime.Now.Ticks,
                    CuserId = ClaimPrincipalFactory.GetUserId(User),
                    Name    = input.Name,
                    Rkey    = input.Rkey
                };
                _repository.Role.Create(role);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), role.Id, null, input);
                return(Ok(role.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), input);
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
        public IActionResult UpdatetRole([FromBody] InsertRoleDto input, [FromQuery] long roleId)
        {
            try
            {
                var role = _repository.Role.FindByCondition(c => c.Id == roleId).FirstOrDefault();
                #region Validation
                var validator = new ParamValidator();
                validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان"))
                .Throw(General.Results_.FieldNullErrorCode());

                if (role == null)
                {
                    throw new BusinessException(XError.GetDataErrors.NotFound());
                }
                #endregion


                role.Mdate   = DateTime.Now.Ticks;
                role.MuserId = ClaimPrincipalFactory.GetUserId(User);
                role.Name    = input.Name;
                role.Rkey    = input.Rkey;

                _repository.Role.Update(role);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input, roleId);
                return(Ok(General.Results_.SuccessMessage()));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), input, roleId);
                return(BadRequest(e.Message));
            }
        }