public ITeamMemberModel Update(ITeamMemberModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = TeamMembersRepository.Get(model.Id.Value);

            // Check if we would be applying identical information, if we are, just return the original
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (TeamMemberMapper.AreEqual(model, existingEntity))
            {
                return(TeamMemberMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            TeamMemberMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            TeamMembersRepository.Update(TeamMemberMapper.MapToEntity(model));
            // Try to Save Changes
            TeamMembersRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
        private TeamMember GetMemberInfo(int teamMemberId)
        {
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(CONNECTION_DATA_STRING))
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandText = GET_MEMBER_INFO;

                        sqlCommand.Parameters.Add("@idmember", SqlDbType.Int, 6);
                        sqlCommand.Parameters["@idmember"].Value = teamMemberId;

                        sqlConnection.Open();


                        SqlDataReader reader = sqlCommand.ExecuteReader();
                        while (reader.Read())
                        {
                            return(TeamMemberMapper.MapToTeamMember(reader));
                        }
                        reader.Close();
                    }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }
        public ITeamMemberModel Create(ITeamMemberModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateIDIsNull(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Search for an Existing Record (Don't allow Duplicates
            var results = Search(TeamMemberMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = TeamMemberMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            TeamMembersRepository.Add(newEntity);
            // Try to Save Changes
            TeamMembersRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
Beispiel #4
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new TeamMemberMapper();
            var model  = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel(1);
            var entity = TeamMembersMockingSetup.DoMockingSetupForTeamMember(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
Beispiel #5
0
        public void Verify_MapToModelLite_AssignsLiteOnlyTeamMemberProperties()
        {
            // Arrange
            var mapper = new TeamMemberMapper();
            var entity = TeamMembersMockingSetup.DoMockingSetupForTeamMember();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(entity.Object.TeamId, model.TeamId);
            Assert.Equal(entity.Object.CharacterId, model.CharacterId);
        }
Beispiel #6
0
        public void Verify_MapToEntity_AssignsTeamMemberProperties()
        {
            // Arrange
            var mapper = new TeamMemberMapper();
            var model  = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(model.Object.TeamId, entity.TeamId);
            Assert.Equal(model.Object.CharacterId, entity.CharacterId);
            // Associated Objects
            // <None>
        }
Beispiel #7
0
        public void Verify_MapToSearchModel_AssignsTeamMemberSearchProperties()
        {
            // Arrange
            var mapper = new TeamMemberMapper();
            var model  = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.TeamId, searchModel.TeamId);
            Assert.Equal(model.Object.Team?.CustomKey, searchModel.TeamCustomKey);
            Assert.Equal(model.Object.Team?.ApiDetailUrl, searchModel.TeamApiDetailUrl);
            Assert.Equal(model.Object.Team?.SiteDetailUrl, searchModel.TeamSiteDetailUrl);
            Assert.Equal(model.Object.Team?.Name, searchModel.TeamName);
            Assert.Equal(model.Object.Team?.ShortDescription, searchModel.TeamShortDescription);
            Assert.Equal(model.Object.Team?.Description, searchModel.TeamDescription);
            Assert.Equal(model.Object.CharacterId, searchModel.CharacterId);
            Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey);
            Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl);
            Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl);
            Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName);
            Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription);
            Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription);
        }
 public void Verify_MapToSearchModel_AssignsTeamMemberSearchProperties()
 {
     // Arrange
     var mapper = new TeamMemberMapper();
     var model = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     Assert.Equal(model.Object.TeamId, searchModel.TeamId);
     Assert.Equal(model.Object.Team?.CustomKey, searchModel.TeamCustomKey);
     Assert.Equal(model.Object.Team?.ApiDetailUrl, searchModel.TeamApiDetailUrl);
     Assert.Equal(model.Object.Team?.SiteDetailUrl, searchModel.TeamSiteDetailUrl);
     Assert.Equal(model.Object.Team?.Name, searchModel.TeamName);
     Assert.Equal(model.Object.Team?.ShortDescription, searchModel.TeamShortDescription);
     Assert.Equal(model.Object.Team?.Description, searchModel.TeamDescription);
     Assert.Equal(model.Object.CharacterId, searchModel.CharacterId);
     Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey);
     Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl);
     Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl);
     Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName);
     Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription);
     Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription);
 }
 public void Verify_MapToModel_AssignsTeamMemberProperties()
 {
     // Arrange
     var mapper = new TeamMemberMapper();
     var entity = TeamMembersMockingSetup.DoMockingSetupForTeamMember();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(entity.Object.TeamId, model.TeamId);
     Assert.Equal(entity.Object.CharacterId, model.CharacterId);
     // Associated Objects
     // <None>
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsTeamMemberProperties()
 {
     // Arrange
     var mapper = new TeamMemberMapper();
     var model = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel();
     // Act
     ITeamMember existingEntity = new TeamMember { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(model.Object.TeamId, existingEntity.TeamId);
     Assert.Equal(model.Object.CharacterId, existingEntity.CharacterId);
     // Associated Objects
     // <None>
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new TeamMemberMapper();
     var model = TeamMembersMockingSetup.DoMockingSetupForTeamMemberModel(1);
     var entity = TeamMembersMockingSetup.DoMockingSetupForTeamMember(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
 public ITeamMemberModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(TeamMemberMapper.MapToModel(TeamMembersRepository.Get(key)));
 }
 public ITeamMemberModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(TeamMemberMapper.MapToModel(TeamMembersRepository.Get(id)));
 }