Пример #1
0
 /// <summary>
 /// Retrieve a single script
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="scriptId">script id</param>
 /// <returns></returns>
 public IScriptDto GetScript(int performingUserId, int scriptId)
 {
     using (var context = new PrometheusContext())
     {
         var document = context.Scripts.ToList().FirstOrDefault(x => x.Id == scriptId);
         return(ManualMapper.MapScriptToDto(document));
     }
 }
Пример #2
0
 protected override IScriptDto Update(int performingUserId, IScriptDto script)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.Scripts.Any(x => x.Id == script.Id))
         {
             throw new InvalidOperationException(string.Format("Script with ID {0} cannot be updated since it does not exist.", script.Id));
         }
         var updated = ManualMapper.MapDtoToScript(script);
         context.Entry(updated).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapScriptToDto(updated));
     }
 }
Пример #3
0
 protected override IScriptDto Create(int performingUserId, IScriptDto scriptDto)
 {
     using (var context = new PrometheusContext())
     {
         var script = context.Scripts.FirstOrDefault(x => x.ScriptFile == scriptDto.ScriptFile);
         if (script != null)
         {
             throw new InvalidOperationException(string.Format("Service Document with ID {0} already exists.", script.ScriptFile));
         }
         var savedDocument = context.Scripts.Add(ManualMapper.MapDtoToScript(scriptDto));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapScriptToDto(savedDocument));
     }
 }
Пример #4
0
 /// <summary>
 /// Retrieve all scripts
 /// </summary>
 /// <returns></returns>
 public IEnumerable <IScriptDto> GetScripts(int performingUserId)
 {
     using (var context = new PrometheusContext())
     {
         var scripts = context.Scripts;
         if (scripts != null)
         {
             foreach (var script in scripts)
             {
                 yield return(ManualMapper.MapScriptToDto(script));
             }
         }
     }
 }