Esempio n. 1
0
 /// <summary>
 /// Finds option category with identifier provided and returns its DTO
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="optionCategoryId"></param>
 /// <returns></returns>
 public IServiceOptionCategoryDto GetServiceOptionCategory(int performingUserId, int optionCategoryId)
 {
     using (var context = new PrometheusContext())
     {
         var serviceOption = context.OptionCategories.Find(optionCategoryId);
         if (serviceOption != null)
         {
             return(ManualMapper.MapOptionCategoryToDto(serviceOption));
         }
         return(null);
     }
 }
Esempio n. 2
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));
     }
 }
Esempio n. 3
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));
     }
 }