Пример #1
0
        private ChangeResult Validate(List <ITeamCategory> teamCategories, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            Category = new CategoryService();
            Team     = new TeamService();

            foreach (var item in teamCategories)
            {
                var existingCombo = GetTeamCategory(item.TeamId, item.CategoryId);
                if (isAddNew)
                {
                    if (existingCombo != null)
                    {
                        var teamNameCategoryName = GetTeamNameCategoryName(item.TeamId, item.CategoryId);

                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"Team: {teamNameCategoryName.Item1} already belongs to Category: {teamNameCategoryName.Item2}");
                    }
                }
                else
                {
                    if (item.TeamCategoryId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid TeamCategoryId");
                    }

                    if (existingCombo != null && existingCombo.TeamCategoryId != item.TeamCategoryId)
                    {
                        var teamNameCategoryName = GetTeamNameCategoryName(item.TeamId, item.CategoryId);

                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"Team: {teamNameCategoryName.Item1} already belongs to Category: {teamNameCategoryName.Item2}");
                    }
                }

                if (item.TeamId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid TeamId");
                }
                else
                {
                    var team = Team.GetTeam(item.TeamId);
                    if (team == null)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"Team: {item.TeamId} does not exist");
                    }
                }

                if (item.CategoryId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid CategoryId");
                }
                else
                {
                    var cat = Category.GetCategory(item.CategoryId);
                    if (cat == null)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"Category: {item.CategoryId} does not exist");
                    }
                }
            }
            return(result);
        }