예제 #1
0
 /// <summary>
 /// Finds service bundle with identifier provided and returns its DTO
 /// </summary>
 /// <param name="serviceBundleId"></param>
 /// <returns></returns>
 public IServiceBundleDto GetServiceBundle(int serviceBundleId)
 {
     using (var context = new PrometheusContext())
     {
         var serviceBundle = context.ServiceBundles.Find(serviceBundleId);
         return(ManualMapper.MapServiceBundleToDto(serviceBundle));
     }
 }
예제 #2
0
 /// <summary>
 /// Returns all service bundles
 /// </summary>
 /// <returns></returns>
 public IEnumerable <IServiceBundleDto> GetServiceBundles()
 {
     using (var context = new PrometheusContext())
     {
         foreach (var bundle in context.ServiceBundles)
         {
             yield return(ManualMapper.MapServiceBundleToDto(bundle));
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Creates the entity in the database
 /// </summary>
 /// <param name="performingUserId">User creating the entity</param>
 /// <param name="entity">Entity to be created</param>
 /// <returns>Created entity DTO</returns>
 protected override IServiceBundleDto Create(int performingUserId, IServiceBundleDto serviceBundle)
 {
     using (var context = new PrometheusContext())
     {
         var bundle = context.ServiceBundles.Find(serviceBundle.Id);
         if (bundle != null)
         {
             throw new InvalidOperationException(string.Format("Service Bundle with ID {0} already exists.", serviceBundle.Id));
         }
         var savedBundle = context.ServiceBundles.Add(ManualMapper.MapDtoToServiceBundle(serviceBundle));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceBundleToDto(savedBundle));
     }
 }
예제 #4
0
 /// <summary>
 /// Updates the entity in the database
 /// </summary>
 /// <param name="performingUserId">User updating the entity</param>
 /// <param name="entity">Entity to be updated</param>
 /// <returns>Updated entity DTO</returns>
 protected override IServiceBundleDto Update(int performingUserId, IServiceBundleDto serviceBundle)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceBundles.Any(x => x.Id == serviceBundle.Id))
         {
             throw new InvalidOperationException("Service Bundle must exist in order to be updated.");
         }
         var updatedServiceBundle = ManualMapper.MapDtoToServiceBundle(serviceBundle);
         context.ServiceBundles.Attach(updatedServiceBundle);
         context.Entry(updatedServiceBundle).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceBundleToDto(updatedServiceBundle));
     }
 }