예제 #1
0
 protected override IServiceOptionCategoryDto Create(int performingUserId, IServiceOptionCategoryDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var serviceOption = context.OptionCategories.Find(entity.Id);
         if (serviceOption != null)
         {
             throw new InvalidOperationException(string.Format("Service Option with ID {0} already exists.", entity.Id));
         }
         var savedOption = context.OptionCategories.Add(ManualMapper.MapDtoToOptionCategory(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapOptionCategoryToDto(savedOption));
     }
 }
예제 #2
0
 protected override IServiceOptionCategoryDto Update(int performingUserId, IServiceOptionCategoryDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.OptionCategories.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(string.Format("Service Option Category with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedCategory = ManualMapper.MapDtoToOptionCategory(entity);
         context.OptionCategories.Attach(updatedCategory);
         context.Entry(updatedCategory).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapOptionCategoryToDto(updatedCategory));
     }
 }