public ActionResult AddEnemy(AddEnemyRequest addEnemyRequest)
        {
            var validation = _validator.ValidateAddEnemy(addEnemyRequest);

            if (!validation.IsValid)
            {
                return(BadRequest(new { error = validation.ErrorMessage }));
            }
            var user = _memberRepo.GetMember(addEnemyRequest.MemberId);

            user.Enemies.Add(addEnemyRequest.EnemyId);

            return(Accepted($"api/members/{user.Id}/enemies", user.Enemies));
        }
Exemple #2
0
        //Validates that a proper member Id and enemyId  were submitted and that the enemy is not already on members enemy list for add enemy request.

        public ValidationResponse ValidateAddEnemy(AddEnemyRequest request)
        {
            if (MemberRepo._Members.Where(member => member.Id == request.MemberId).Count() == 0)
            {
                return(new ValidationResponse(false, "Invalid member Id. No member found with matching Id."));
            }
            else if (MemberRepo._Members.Where(member => member.Id == request.EnemyId).Count() == 0)
            {
                return(new ValidationResponse(false, "Invalid enemy Id. No member found with matching Id."));
            }
            else if (_members.GetMember(request.MemberId).Enemies.Contains(request.EnemyId))
            {
                return(new ValidationResponse(false, "Enemy is already on member's enemy list."));
            }

            return(new ValidationResponse(true));
        }