Exemple #1
0
 protected override IServiceSwotDto Create(int performingUserId, IServiceSwotDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var serviceSwot = context.ServiceSwots.Find(entity.Id);
         if (serviceSwot != null)
         {
             throw new InvalidOperationException(string.Format("Service SWOT with ID {0} already exists.", entity.Id));
         }
         var savedSwot = context.ServiceSwots.Add(ManualMapper.MapDtoToServiceSwot(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceSwotToDto(savedSwot));
     }
 }
Exemple #2
0
 protected override IServiceSwotDto Update(int performingUserId, IServiceSwotDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceSwots.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(string.Format("Service SWOT with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedSwot = ManualMapper.MapDtoToServiceSwot(entity);
         context.ServiceSwots.Attach(updatedSwot);
         context.Entry(updatedSwot).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceSwotToDto(updatedSwot));
     }
 }