/// <summary>
 /// Return all the CommonFilter
 /// </summary>
 /// <param name="bypassCache">Option to go directly to the DB default false</param>
 /// <returns>Return all the CommonFilter</returns>
 public IHttpActionResult Get(bool bypassCache = false)
 {
     try
     {
         var response = new List<CommonFilter>();
         var memCache = MemoryCache.Default.Get("CommonFilters");
         if ((bypassCache) || (memCache == null))
         {
             using (var context = new DbModel())
             {
                 response = context.CommonFilters.ToList();
             }
             var policy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromHours(1) };
             MemoryCache.Default.Add("CommonFilters", response, policy);
         }
         else
         {
             response = (List<CommonFilter>)memCache;
         }
         return Ok(response);
     }
     catch (Exception e)
     {
         logger.Error(e);
         return InternalServerError(e);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets all the calls associated to a ListView
 /// </summary>
 /// <param name="id">The id of the ListView to retrives</param>
 /// <returns>The ListView and all the calls the match the filters</returns>
 public IHttpActionResult Get(int id)
 {
     try
     {
         var cv = new CallsView();
         using (var context = new DbModel())
         {
             var lv = context.ListViews
                 .Include(x => x.Filters)
                 .Where(x => x.Id == id)
                 .FirstOrDefault();
             if (lv == null)
                 return NotFound();
             cv.ListView = lv;
             var calls = context.Calls.Where("ID>0");
             foreach (var filter in lv.Filters)
             {
                 calls = calls.Where(filter.Where);
             }
             cv.Calls = calls.ToList();
         }
         return Ok(cv);
     }
     catch (Exception e)
     {
         logger.Error(e);
         return InternalServerError(e);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add Demo data to the database (10 random calls will be added)
 /// </summary>
 /// <param name="count">The count of calls to add (default = 10)</param>
 /// <returns>Returns a list of those calls added</returns>        
 public IHttpActionResult Get(int count = 10)
 {
     try
     {
         var calls = new List<Call>();
         using (var context = new DbModel())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             for (int i = 0; i < count; i++)
             {
                 string name = RandomName;
                 int temp = rnd.Next(28, 45);
                 long randNum = rnd.Next(1112222, 9998888);
                 long randAreaCode = rnd.Next(111, 999);
                 var newCall = new Call
                 {
                     Name = RandomName,
                     PhoneNumber = (randAreaCode * 10000000 + randNum).ToString() ,
                     Duration = temp * rnd.Next(1, 10),
                     StartTime = DateTime.Now.AddDays(-rnd.Next(500, (temp - 22) * 300)),
                 };
                 context.Calls.Add(newCall);
                 calls.Add(newCall);
             }
             context.SaveChanges();
         }
         return Ok(calls);
     }
     catch (Exception e)
     {
         logger.Error(e);
         return InternalServerError(e);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns all ListViews
 /// </summary>
 /// <returns></returns>
 public IHttpActionResult Get()
 {
     try
     {
         using (var context = new DbModel())
         {
             return Ok(context.ListViews.Where(x => x.Name != null).ToList());
         }
     }
     catch (Exception e)
     {
         logger.Error(e);
         return InternalServerError(e);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Get one call by id
 /// </summary>
 /// <param name="id">The id of the call</param>
 /// <returns>Returns the call that matches the given id</returns>
 public IHttpActionResult Get(int id)
 {
     try
     {
         Call call = null;
         using (var context = new DbModel())
         {
             call = context.Calls.Where(x => x.Id == id).FirstOrDefault();
         }
         if (call != null)
             return Ok(call);
         return NotFound();
     }
     catch (Exception e)
     {
         logger.Error(e);
         return InternalServerError(e);
     }
 }