Exemplo n.º 1
0
        public async Task <FlawViewModel> CreateFlaw([FromBody] FlawViewModel flawVM)
        {
            var domainModel = flawVM.ToDomainModel();

            if (flawVM.FlawId > 0) // editing an existing feature
            {
                //make sure they're the author of this feature
                var existingFlaw = await this.dbCtx.Flaws.FirstOrDefaultAsync(f => f.Player.Id == userSession.Player.Id && f.Id == flawVM.FlawId);

                if (existingFlaw != null)
                {
                    //yep, it's theirs
                    existingFlaw.Delisted = true;
                }
            }

            domainModel.Id = 0;

            dbCtx.Attach(userSession.Player);
            domainModel.Player      = userSession.Player;
            domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            dbCtx.Flaws.Add(domainModel);

            await dbCtx.SaveChangesAsync();

            domainModel.Player = userSession.Player;

            return(domainModel.ToViewModel());
        }
Exemplo n.º 2
0
 public static Flaw ToDomainModel(this FlawViewModel flaw)
 {
     return(new Flaw
     {
         Id = flaw.FlawId,
         Mods = flaw.Mods.Select(sm => sm.ToDomainModel()).ToList(),
         Name = flaw.Name,
         Description = flaw.Description
     });
 }