public async Task <OathViewModel> CreateOath([FromBody] OathViewModel oathVM) { var domainModel = oathVM.ToDomainModel(); if (oathVM.OathId > 0) // editing an existing feature { //make sure they're the author of this feature var existingOath = await this.dbCtx.Oaths.FirstOrDefaultAsync(f => f.Player.Id == userSession.Player.Id && f.Id == oathVM.OathId); if (existingOath != null) { //yep, it's theirs existingOath.Delisted = true; } } domainModel.Id = 0; dbCtx.Attach(userSession.Player); domainModel.Player = userSession.Player; domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); dbCtx.Oaths.Add(domainModel); await dbCtx.SaveChangesAsync(); domainModel.Player = userSession.Player; return(domainModel.ToViewModel()); }
public static Oath ToDomainModel(this OathViewModel oathVM) { return(new Oath { Name = oathVM.Name, Description = oathVM.Description, Mods = oathVM.Mods.Select(o => o.ToDomainModel()).ToList(), Id = oathVM.OathId }); }