Example #1
0
        public async Task<Dnd35CharacterViewModel> AddCharacter(Dnd35CharacterViewModel character, string userName)
        {
            var bsonCharacter = _mapper.MapViewModelToDocument(character);
            bsonCharacter.Add(new BsonElement("owner", userName));

            var addedCharacter = await _characterRepository.AddCharacter(bsonCharacter);

            return _mapper.MapDocumentToViewModel(addedCharacter);
        }
Example #2
0
        public BsonDocument MapViewModelToDocument(Dnd35CharacterViewModel character)
        {
            var bsonCharacter = new BsonDocument
            {
                { characterName, character.CharacterName },
                { isShared, character.IsShared },
                { system, character.System.ToString() }
            };

            var classesArray = new BsonArray();
            foreach (var classLevel in character.Classes)
            {
                classesArray.Add(new BsonDocument
                {
                    {className, classLevel.ClassName},
                    {level, classLevel.Level }
                });
            }
            bsonCharacter.Add(new BsonElement(classes, classesArray));

            MapValue(character.Ecl, bsonCharacter, ecl);
            MapValue(character.Race, bsonCharacter, race);
            MapValue(character.Alignment, bsonCharacter, alignment);
            MapValue(character.Diety, bsonCharacter, diety);
            MapValue(character.Size, bsonCharacter, size);
            MapValue(character.Age, bsonCharacter, age);
            MapValue(character.Gender, bsonCharacter, gender);
            MapValue(character.Height, bsonCharacter, height);
            MapValue(character.Weight, bsonCharacter, weight);
            MapValue(character.Eyes, bsonCharacter, eyes);
            MapValue(character.Hair, bsonCharacter, hair);
            MapValue(character.Skin, bsonCharacter, skin);
            MapValue(character.Strength, bsonCharacter, strength);
            MapValue(character.Dexterity, bsonCharacter, dexterity);
            MapValue(character.Constitution, bsonCharacter, constitution);
            MapValue(character.Intelligence, bsonCharacter, intelligence);
            MapValue(character.Wisdom, bsonCharacter, wisdom);
            MapValue(character.Charisma, bsonCharacter, charisma);

            if (character.CharacterID != null)
            {
                var objectId = ObjectId.Parse(character.CharacterID);
                bsonCharacter.Add(new BsonElement("_id", objectId));
            }

            return bsonCharacter;
        }
Example #3
0
        public Dnd35CharacterViewModel MapDocumentToViewModel(BsonDocument character)
        {
            var newModel = new Dnd35CharacterViewModel
            {
                System = GameSystem.Dnd35,
                CharacterID = character.GetValue("_id").AsObjectId.ToString(),
                CharacterName = character.GetValue(characterName).AsString,
                IsShared = character.GetValue(isShared).AsBoolean
            };
            BsonValue classesArray;
            if (character.TryGetValue(classes, out classesArray))
            {
                foreach (var bsonValue in (BsonArray)classesArray)
                {
                    var classLevel = (BsonDocument) bsonValue;
                    newModel.Classes.Add(new Dnd35CharacterViewModel.ClassLevel
                    {
                        ClassName = classLevel.GetValue(className).AsString,
                        Level = classLevel.GetValue(level).AsNullableInt32
                    });
                }
            }
            newModel.Ecl = MapValue(character, ecl, newModel.Ecl);
            newModel.Race = MapValue(character, race, newModel.Race);
            newModel.Alignment = MapValue(character, alignment, newModel.Alignment);
            newModel.Diety = MapValue(character, diety, newModel.Diety);
            newModel.Size = MapValue(character, size, newModel.Size);
            newModel.Age = MapValue(character, age, newModel.Age);
            newModel.Gender = MapValue(character, gender, newModel.Gender);
            newModel.Height = MapValue(character, height, newModel.Height);
            newModel.Weight = MapValue(character, weight, newModel.Weight);
            newModel.Eyes = MapValue(character, eyes, newModel.Eyes);
            newModel.Hair = MapValue(character, hair, newModel.Hair);
            newModel.Skin = MapValue(character, skin, newModel.Skin);
            newModel.Strength = MapValue(character, strength, newModel.Strength);
            newModel.Dexterity = MapValue(character, dexterity, newModel.Dexterity);
            newModel.Constitution = MapValue(character, constitution, newModel.Constitution);
            newModel.Intelligence = MapValue(character, intelligence, newModel.Intelligence);
            newModel.Wisdom = MapValue(character, wisdom, newModel.Wisdom);
            newModel.Charisma = MapValue(character, charisma, newModel.Charisma);

            return newModel;
        }
        public async Task<IHttpActionResult> Put(string id, Dnd35CharacterViewModel character)
        {
            await _dnd35Service.UpdateCharacter(id, character, User.Identity.Name);

            return Ok();
        }
        public async Task<IHttpActionResult> Post(Dnd35CharacterViewModel character)
        {
            var addedCharacter = await _dnd35Service.AddCharacter(character, User.Identity.Name);

            return CreatedAtRoute("GetById", new { id = addedCharacter.CharacterID }, addedCharacter);
        }
Example #6
0
 private void MapValue(Dnd35CharacterViewModel.Ability ability, BsonDocument bsonDocument, string field)
 {
     bsonDocument.Add(field, () => new BsonDocument(new Dictionary<string, object>
     {
         {score, ability.Score},
         {modifier, ability.Modifier}
     }), ability != null);
 }
Example #7
0
 protected Dnd35CharacterViewModel.Ability MapValue(BsonDocument document, string field, Dnd35CharacterViewModel.Ability dontCare)
 {
     Dnd35CharacterViewModel.Ability ability = null;
     BsonValue bsonValue;
     if (document.TryGetValue(field, out bsonValue) && bsonValue.IsBsonDocument)
     {
         var abilityDocument = bsonValue.AsBsonDocument;
         ability = new Dnd35CharacterViewModel.Ability
         {
             Score = MapValue(abilityDocument, score, 0),
             Modifier = MapValue(abilityDocument, modifier, 0)
         };
     }
     return ability;
 }
Example #8
0
 public Task UpdateCharacter(string id, Dnd35CharacterViewModel character, string userName)
 {
     throw new System.NotImplementedException();
 }