Esempio n. 1
0
 protected override IServiceProcessDto Create(int performingUserId, IServiceProcessDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var serviceProcess = context.ServiceProcesses.Find(entity.Id);
         if (serviceProcess != null)
         {
             throw new InvalidOperationException(string.Format("Service Process with ID {0} already exists.", entity.Id));
         }
         var savedProcess = context.ServiceProcesses.Add(ManualMapper.MapDtoToServiceProcess(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceProcessToDto(savedProcess));
     }
 }
Esempio n. 2
0
 protected override IServiceProcessDto Update(int performingUserId, IServiceProcessDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceProcesses.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(string.Format("Service Process with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedProcess = ManualMapper.MapDtoToServiceProcess(entity);
         context.ServiceProcesses.Attach(updatedProcess);
         context.Entry(updatedProcess).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceProcessToDto(updatedProcess));
     }
 }