Esempio n. 1
0
 public static void LogError(Exception e)
 {
     using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
     {
         if (db.Database.Exists())
         {
             Error error = new Error();
             error.Errors = e.ToString();
             db.errors.Add(error);
         }
     }
 }
Esempio n. 2
0
 public static bool CheckForUser(string email)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 Users ui = db.users.First(e => e.Email == email);
             }
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 3
0
 public static void UpdateUser(Users u, EntityState Modified)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 db.Entry(u).State = Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 4
0
 public static void DeleteUserInputs60Hz(int?id)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 UserInputs60Hz ui = db.userInputs60Hz.Find(id);
                 db.userInputs60Hz.Remove(ui);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 5
0
 public static void CreateUser(Users u)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 u.DateCreated = DateTime.Now;
                 db.users.Add(u);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 6
0
 public static void CreateUserInputs60Hz(UserInputs60Hz ui)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 ui.date      = DateTime.Now;
                 ui.IPAddress = HttpContext.Current.Request.UserHostAddress;
                 db.userInputs60Hz.Add(ui);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 7
0
 public static List <UserInputsDC> GetAllUserInputsDC()
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 List <UserInputsDC> uiList = db.userInputsDC.ToList();
                 return(uiList);
             }
             else
             {
                 List <UserInputsDC> uiList = new List <UserInputsDC>();
                 return(uiList);
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 8
0
 public static Users GetUser(string email)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 Users ui = db.users.First(e => e.Email == email);
                 return(ui);
             }
             else
             {
                 Users ui = new Users();
                 return(ui);
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
Esempio n. 9
0
 public static Users GetUser(int?id)
 {
     try
     {
         using (ArcCalculatorDbContext db = new ArcCalculatorDbContext())
         {
             if (db.Database.Exists())
             {
                 Users ui = db.users.Find(id);
                 return(ui);
             }
             else
             {
                 Users ui = new Users();
                 return(ui);
             }
         }
     }
     catch (Exception e)
     {
         LogError(e);
         throw;
     }
 }
        public IEnumerable <UserInputs60Hz> GetData(out int totalRecords, string globalSearch, int?limitOffset, int?limitRowCount, string orderBy, bool desc)
        {
            using (var db = new ArcCalculatorDbContext())
            {
                var query = db.userInputs60Hz.AsQueryable();

                if (!String.IsNullOrWhiteSpace(globalSearch))
                {
                    query = query.Where(p => (p.TransSize.ToString() + " " + p.Impedance.ToString() + " " + p.SCC.ToString() + " "
                                              + p.FaultClearing.ToString() + " " + p.Voltage.ToString() + " " + p.FreeAir.ToString() + " "
                                              + p.IPAddress + " " + p.date.ToString()).Contains(globalSearch));
                }

                totalRecords = query.Count();

                if (!String.IsNullOrWhiteSpace(orderBy))
                {
                    switch (orderBy.ToLower())
                    {
                    case "transsize":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.TransSize);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.TransSize);
                        }
                        break;

                    case "impedance":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Impedance);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Impedance);
                        }
                        break;

                    case "scc":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.SCC);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.SCC);
                        }
                        break;

                    case "faultclearing":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.FaultClearing);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.FaultClearing);
                        }
                        break;

                    case "voltage":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Voltage);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Voltage);
                        }
                        break;

                    case "FreeAir":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.FreeAir);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.FreeAir);
                        }
                        break;

                    case "ipaddress":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.IPAddress);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.IPAddress);
                        }
                        break;

                    case "date":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.date);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.date);
                        }
                        break;

                    case "id":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Id);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Id);
                        }
                        break;
                    }
                }



                if (limitOffset.HasValue)
                {
                    query = query.Skip(limitOffset.Value).Take(limitRowCount.Value);
                }

                return(query.ToList());
            }
        }