public async Task <Int32> CreateAsync(Models.Policy newPolicy) { Entities.Policy model = newPolicy.ToEntity(); _context.Policies.Add(model); await _context.SaveChangesAsync(); return(model.Id); }
public async Task <Models.Policy> GetAsync(Int32 policyId) { Entities.Policy policy = await _context.Policies .AsNoTracking() .FirstOrDefaultAsync(p => p.Id == policyId); Models.Policy model = policy?.ToModel(); _logger.LogDebug($"{policyId} found in database: {model != null}"); return(model); }
public async Task RemoveAsync(Int32 policyId) { Entities.Policy model = await _context.Policies.SingleOrDefaultAsync(p => p.Id == policyId); if (model == null) { throw new ArgumentException(nameof(model)); } _context.Policies.Remove(model); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(Int32 policyId, Models.Policy policy) { if (policyId != policy.Id) { throw new ArgumentException(nameof(policyId)); } Entities.Policy model = await _context.Policies.SingleOrDefaultAsync(p => p.Id == policyId); model = policy.ToEntity(model); model.Updated = DateTime.UtcNow; await _context.SaveChangesAsync(); }
public static Entities.Policy ToEntity(this Models.Policy model, Entities.Policy entity) { return(Mapper.Map(model, entity)); }
public static Models.Policy ToModel(this Entities.Policy entity) { return(Mapper.Map <Models.Policy>(entity)); }