Example #1
0
        public void UnMapUserTest()
        {
            L_User sampleUserL = new L_User
            {
                UserId      = 100,
                PictureId   = 100,
                FirstName   = "Test First.",
                LastName    = "Test Last.",
                Username    = "******",
                Password    = "******",
                Description = "Test Description.",
                Admin       = false
            };

            D_User sampleUserD = new D_User
            {
                UserId      = 100,
                PictureId   = 100,
                FirstName   = "Test First.",
                LastName    = "Test Last.",
                Username    = "******",
                Password    = "******",
                Description = "Test Description.",
                Admin       = false
            };

            D_User resultUserD = Mapper.UnMapUser(sampleUserL);

            Assert.True(CompareUserD(resultUserD, sampleUserD));
        }
Example #2
0
        /// <summary> Changes all user related to a particular existing user.
        /// <param name="inputUser"> object L_User (name of object) - This is a logic object of type user. </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task UpdateUser(L_User inputUser)
        {
            _logger.LogInformation($"Updating user with ID {inputUser.UserId}");
            D_User currentEntity = await _dbContext.Users.FindAsync(inputUser.UserId);

            D_User newEntity = Mapper.UnMapUser(inputUser);

            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            Save();
        }
Example #3
0
        public async Task <IActionResult> Put(int id, [FromBody] L_User user)
        {
            // successful update for PUT returns 204 No Content with empty body, or 200 OK
            if (await _userRepository.GetUserById(id) is L_User oldUser)
            {
                await _userRepository.UpdateUser(user);

                return(NoContent());
                //return StatusCode(204);
            }
            return(NotFound());
        }
Example #4
0
 public static D_User UnMapUser(L_User user)
 {
     return(new D_User
     {
         UserId = user.UserId,
         PictureId = user.PictureId,
         FirstName = user.FirstName,
         LastName = user.LastName,
         Username = user.Username,
         Password = user.Password,
         Description = user.Description,
         Admin = user.Admin
     });
 }
Example #5
0
        /// <summary> Adds a new user to the database.
        /// <param name="inputUser"> object L_User (name of object) - This is a logic object of type user. </param>
        /// <returns> void </returns>
        /// </summary>
        public void AddUser(L_User inputUser)
        {
            if (inputUser.UserId != 0)
            {
                _logger.LogWarning($"User to be added has an ID ({inputUser.UserId}) already!");
                throw new ArgumentException("Id already exists when trying to add a new user!", $"{inputUser.UserId}");
            }

            _logger.LogInformation("Adding user.");

            D_User entity = Mapper.UnMapUser(inputUser);

            entity.UserId = 0;
            _dbContext.Add(entity);
            Save();
        }
Example #6
0
 private bool CompareUserL(L_User x, L_User y)
 {
     if (
         x.Admin != y.Admin ||
         x.Description != y.Description ||
         x.FirstName != y.FirstName ||
         x.LastName != y.LastName ||
         x.Password != y.Password ||
         x.PictureId != y.PictureId ||
         x.Reviews.Count != y.Reviews.Count ||
         x.Scores.Count != y.Scores.Count
         )
     {
         return(false);
     }
     return(true);
 }
Example #7
0
        public void MapUserTest()
        {
            D_User sampleUserD = new D_User
            {
                UserId      = 100,
                PictureId   = 100,
                FirstName   = "Test First.",
                LastName    = "Test Last.",
                Username    = "******",
                Password    = "******",
                Description = "Test Description.",
                Admin       = false,
                Scores      = new List <D_Score> {
                },
                Reviews     = new List <D_Review> {
                }
            };

            L_User sampleUserL = new L_User
            {
                UserId      = 100,
                PictureId   = 100,
                FirstName   = "Test First.",
                LastName    = "Test Last.",
                Username    = "******",
                Password    = "******",
                Description = "Test Description.",
                Admin       = false,
                Scores      = new List <L_Score> {
                },
                Reviews     = new List <L_Review> {
                }
            };

            L_User resultUserL = Mapper.MapUser(sampleUserD);

            Assert.True(CompareUserL(resultUserL, sampleUserL));
        }
Example #8
0
 public IActionResult Post(L_User user)
 {
     _userRepository.AddUser(user);
     return(CreatedAtAction(nameof(GetById), new { id = user.UserId }, user));
 }