예제 #1
0
        public async Task<ActionResult> RetrieveCharacterAsync(RetrieveCharacterCmd cmd)
        {
            var cmdValidation = new CommandValidation();

            cmdValidation.validate(() => cmd.Id == Guid.Empty, "idCharacter cannot be empty");

            if (!cmdValidation.IsValid())
                //todo give back some 4/5xx love?
                return Json( cmdValidation.ToResponse());
            else
            {
                var currentUser = _serviceUser.getCurrentUser();
                var result = await _serviceAccount.RetrieveCharacterAsync(currentUser.Id, cmd.Id);

                var executionResult = new ExecutionValidation(result);
                //todo give back some 4/5xx love if it failed?
                return Json( executionResult.ToResponse());
            }
        }
예제 #2
0
        public async Task<ActionResult> AddNewCharacterAsync(CreateCharacterCmd cmd)
        {
            var cmdValidation = new CommandValidation();

            Domain.Model.Faction faction = null;
            Domain.Model.Race race = null;
            Domain.Model.Class @class = null;

            cmdValidation.validate(() => cmd.Id == Guid.Empty, "id cannot be empty");
            cmdValidation.validate(() => string.IsNullOrEmpty(cmd.Name), "name cannot be empty");
            cmdValidation.validate(() => !Domain.Model.ClassFactory.TryParse(cmd.Class, out @class), "class is not known");
            cmdValidation.validate(() => !Domain.Model.FactionFactory.TryParse(cmd.Faction, out faction), "faction is not known");
            cmdValidation.validate(() => !Domain.Model.RaceFactory.TryParse(cmd.Race, out race), "race is not known");
            //cmdValidation.validate(() => cmd.Level<1 || cmd.Level>100, "level is not available"); not in the rules.. :)

            if (!cmdValidation.IsValid())
                //todo give back some 4/5xx love?
                return Json(cmdValidation.ToResponse());
            else
            {
                var currentUser = _serviceUser.getCurrentUser();
                var result = await _serviceAccount.CreateCharacterAsync(currentUser.Id, cmd.Id, cmd.Name, cmd.Level, race, faction, @class);
                var executionResult = new ExecutionValidation(result );
                //todo give back some 4/5xx love if it failed?
                return Json(executionResult.ToResponse());
            }
                
        }