Esempio n. 1
0
        public int Post([FromBody] Models.UserModel user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "User cannot be null");
            }

            var newUser = _userRepository.Create(user.ToDomain());

            return(newUser.UserID);
        }
Esempio n. 2
0
        public void Put(int id, [FromBody] Models.UserModel user)
        {
            //Guard against invalid Id
            if (id <= 0)
            {
                throw new ArgumentNullException(nameof(id), "User id not provided");
            }

            //Guard against empty model
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "User cannot be null");
            }

            //Guard against inconsistent ID
            if (user.Id != 0 && user.Id != id)
            {
                _logger.LogWarning($"id ({id}) and user.id {user.Id} are not equals. user.id will be used");
            }

            _userRepository.Update(id, user.ToDomain());
        }