Ejemplo n.º 1
0
        public async Task <IActionResult> SetAll([FromBody] FiveEModel dynamic, [FromRoute] string id = null)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            dynamic.OwnerID = userId;
            if (string.IsNullOrEmpty(id) || !ObjectId.TryParse(id, out _))
            {
                id = ObjectId.GenerateNewId().ToString();
            }
            dynamic.Id           = id.ToString();
            dynamic._created     = new BsonDateTime(System.DateTime.UtcNow);
            dynamic._lastUpdated = new BsonDateTime(System.DateTime.UtcNow);

            var collection = MongoDb.GetCollection <FiveEModel>("RpgCharModels");
            await collection.InsertOneAsync(dynamic);

            return(new JsonResult(dynamic.Id));
        }
Ejemplo n.º 2
0
        public async Task <string> NewChar([FromRoute] string id = null)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrEmpty(id) || !ObjectId.TryParse(id, out _))
            {
                id = ObjectId.GenerateNewId().ToString();
            }

            var newChar = new FiveEModel
            {
                AbilityScores       = new List <AbilityScore>(),
                CharacterAppearance = new List <CharacterAppearance>(),
                DeathSave           = new List <DeathSave>(),
                Equipment           = new Equipment(),
                Feats          = new List <Feat>(),
                FeaturesTraits = new List <FeaturesTrait>(),
                Health         = new Health(),
                HitDice        = new List <HitDice>(),
                HitDiceType    = new List <HitDiceTypeModel>(),
                Id             = id.ToString(),
                Items          = new List <Item>(),
                MagicItems     = new List <MagicItem>(),
                Notes          = new List <Note>(),
                OwnerID        = userId,
                Profile        = new Profile(),
                SavingThrows   = new List <SavingThrow>(),
                Skills         = new List <Skill>(),
                Spells         = new Spells(),
                Status         = new List <Status>(),
                Traits         = new List <Trait>(),
                Treasure       = new List <Treasure>(),
                _created       = new BsonDateTime(System.DateTime.UtcNow),
                _lastUpdated   = new BsonDateTime(System.DateTime.UtcNow)
            };

            var collection = MongoDb.GetCollection <FiveEModel>("RpgCharModels");
            await collection.InsertOneAsync(newChar);

            return(id);
        }