Exemplo n.º 1
0
 protected override IServiceContractDto Create(int performingUserId, IServiceContractDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var contract = context.ServiceContracts.Find(entity.Id);
         if (contract != null)
         {
             throw new InvalidOperationException(string.Format("Service Contract with ID {0} already exists.", entity.Id));
         }
         var savedContract = context.ServiceContracts.Add(ManualMapper.MapDtoToServiceContract(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceContractToDto(savedContract));
     }
 }
Exemplo n.º 2
0
 protected override IServiceContractDto Update(int performingUserId, IServiceContractDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceContracts.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(
                       string.Format("Service Contract with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedServiceContract = ManualMapper.MapDtoToServiceContract(entity);
         context.ServiceContracts.Attach(updatedServiceContract);
         context.Entry(updatedServiceContract).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceContractToDto(updatedServiceContract));
     }
 }