示例#1
0
 protected override IServiceWorkUnitDto Create(int performingUserId, IServiceWorkUnitDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var workUnit = context.ServiceWorkUnits.Find(entity.Id);
         if (workUnit != null)
         {
             throw new InvalidOperationException(string.Format("Service WorkUnit with ID {0} already exists.", entity.Id));
         }
         var savedWorkUnit = context.ServiceWorkUnits.Add(ManualMapper.MapDtoToServiceWorkUnit(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceWorkUnitToDto(savedWorkUnit));
     }
 }
示例#2
0
 protected override IServiceWorkUnitDto Update(int performingUserId, IServiceWorkUnitDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceWorkUnits.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(
                       string.Format("Service WorkUnit with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedServiceWorkUnit = ManualMapper.MapDtoToServiceWorkUnit(entity);
         context.ServiceWorkUnits.Attach(updatedServiceWorkUnit);
         context.Entry(updatedServiceWorkUnit).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceWorkUnitToDto(updatedServiceWorkUnit));
     }
 }