Exemple #1
0
 protected override IServiceGoalDto Create(int performingUserId, IServiceGoalDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var goal = context.ServiceGoals.Find(entity.Id);
         if (goal != null)
         {
             throw new InvalidOperationException(string.Format("Service Goal with ID {0} already exists.", entity.Id));
         }
         var savedGoal = context.ServiceGoals.Add(ManualMapper.MapDtoToServiceGoal(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceGoalToDto(savedGoal));
     }
 }
Exemple #2
0
 protected override IServiceGoalDto Update(int performingUserId, IServiceGoalDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceGoals.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(
                       string.Format("Service Goal with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedServiceGoal = ManualMapper.MapDtoToServiceGoal(entity);
         context.ServiceGoals.Attach(updatedServiceGoal);
         context.Entry(updatedServiceGoal).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceGoalToDto(updatedServiceGoal));
     }
 }