コード例 #1
0
 /// <summary>
 /// Finds service Contract with identifier provided and returns its DTO
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="serviceContractId"></param>
 /// <returns></returns>
 public IServiceContractDto GetServiceContract(int performingUserId, int serviceContractId)
 {
     using (var context = new PrometheusContext())
     {
         return(ManualMapper.MapServiceContractToDto(context.ServiceContracts.Find(serviceContractId)));
     }
 }
コード例 #2
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));
     }
 }
コード例 #3
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));
     }
 }