示例#1
0
        public async Task <Int32> CreateAsync(Models.Policy newPolicy)
        {
            Entities.Policy model = newPolicy.ToEntity();

            _context.Policies.Add(model);

            await _context.SaveChangesAsync();

            return(model.Id);
        }
示例#2
0
        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);
        }
示例#3
0
        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();
        }
示例#4
0
        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));
 }