Exemple #1
0
        public async Task <CustomResponse <User> > Alterar(User user, AccessManager accessManager, Guid UserId)
        {
            var _response = new CustomResponse <User>();

            try
            {
                if (user.UserId != UserId)
                {
                    var _userHash = new User()
                    {
                        UserId   = user.UserId,
                        Username = user.Username,
                        Email    = user.Email
                    };

                    if (!string.IsNullOrEmpty(user.Password))
                    {
                        _userHash.Password = Convert.ToBase64String(accessManager.HashPassword(user.Password, _rng));
                    }

                    _context.Update <User>(_userHash);

                    await _context.SaveChangesAsync();

                    _response.Message    = "Alteração";
                    _response.StatusCode = StatusCodes.Status200OK;

                    await GerarLog(_response.Message, typeof(User).Name, UserId);
                }
                else
                {
                    _response.Message    = "Não Autorizado";
                    _response.StatusCode = StatusCodes.Status401Unauthorized;
                }
            }
            catch (Exception ex)
            {
                _response.Message = ex.Message;
            }


            return(_response);
        }
Exemple #2
0
        public async Task <CustomResponse <TEntity> > Incluir(TEntity entity, Guid UserId)
        {
            var _response = new CustomResponse <TEntity>();

            _context.Add <TEntity>(entity);

            try
            {
                await _context.SaveChangesAsync();

                _response.Message    = "Inclusão";
                _response.StatusCode = StatusCodes.Status201Created;

                await GerarLog(_response.Message, typeof(TEntity).Name, UserId);
            }
            catch (Exception ex)
            {
                _response.Message = ex.Message;
            }

            return(_response);
        }