コード例 #1
0
 protected override ITextInputDto Create(int performingUserId, ITextInputDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var measure = context.TextInputs.Find(entity.Id);
         if (measure != null)
         {
             throw new InvalidOperationException(string.Format("Service Measure with ID {0} already exists.", entity.Id));
         }
         var savedMeasure = context.TextInputs.Add(ManualMapper.MapDtoToTextInput(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapTextInputToDto(savedMeasure));
     }
 }
コード例 #2
0
 protected override ITextInputDto Update(int performingUserId, ITextInputDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.TextInputs.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(
                       string.Format("Service Measure with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedTextInput = ManualMapper.MapDtoToTextInput(entity);
         context.TextInputs.Attach(updatedTextInput);
         context.Entry(updatedTextInput).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapTextInputToDto(updatedTextInput));
     }
 }