public void changeStatus(Cluster sCluster, string user)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         foreach (FactReport report in sCluster.Reports)
         {
             var data = entities.FactReports.FirstOrDefault(x => x.ReportID == report.ReportID);
             if (data != null)
             {
                 if (data.StatusID < entities.DimStatus.Max(x => x.StatusID))
                 {
                     string oldStat = data.DimStatu.StatusName;
                     data.StatusID++;
                     Change c = new Change()
                     {
                         ReportID = data.ReportID,
                         UserName = user,
                         Data = "Status Changed From " + oldStat + " To " + entities.DimStatus.First(x=>x.StatusID==data.StatusID+1).StatusName,
                         Time = DateTime.Now
                     };
                     entities.Changes.Add(c);
                 }
                 entities.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 2
0
 public void changeStatus(List<int> sCluster, string user)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         foreach (int reportID in sCluster)
         {
             var data = entities.FactReports.FirstOrDefault(x => x.ReportID == reportID);
             if (data != null)
             {
                 if (data.StatusID < entities.DimStatus.Max(x => x.StatusID))
                 {
                     string oldStat = data.DimStatu.StatusName;
                     data.StatusID++;
                     Change c = new Change()
                     {
                         ReportID = data.ReportID,
                         UserName = user,
                         Data = "Status Changed From " + oldStat + " To " +
                         entities.DimStatus.First(x => x.StatusID == data.StatusID).StatusName,
                         Time = DateTime.Now
                     };
                     entities.Changes.Add(c);
                 }
                 try
                 {
                     entities.SaveChanges();
                 }
                 catch (Exception ex)
                 {
                     Console.Write(ex.Message);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public string RegisterUser(string username, string password, string permissions)
 {
     try
     {
         using (DGGuardEntities entities = new DGGuardEntities())
         {
             var data = entities.DimUsers.FirstOrDefault(x => x.UserName == username);
             //check for exisiting username
             if (data != null)
                 return JsonConvert.SerializeObject(false);
             string s = StringCipher.CreateHash(password);
             DimUser u = new DimUser
             {
                 UserName = username,
                 Password = s.Split(':')[1],
                 Salt = s.Split(':')[0],
                 Permisssions = permissions
             };
             entities.DimUsers.Add(u);
             entities.SaveChanges();
             Logger.GetInstance.Log(LogType.Info, "New User Registerd");
             return JsonConvert.SerializeObject(true);
         }
     }
     catch (Exception ex)
     {
         Logger.GetInstance.Log(LogType.Error, "Registration Failed: " + ex.Message);
         return JsonConvert.SerializeObject(false);
     }
 }
Exemplo n.º 4
0
 public void Log(LogType type, string message)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         Log l = new Log { TimeStamp = DateTime.Now, Data = message, Type = type };
         entities.Logs.Add(l);
         entities.SaveChanges();
     }
 }
 public string AuthenticateUser(string username, string password)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         var data = entities.DimUsers.FirstOrDefault(x => x.UserName == username && x.Password == password);
         if (data != null)
             return JsonConvert.SerializeObject(true);
         return JsonConvert.SerializeObject(false);
     }
 }
Exemplo n.º 6
0
 public string PostReport(string url, string img, string dom = "", int category = -1,
     string name = "", string lName = "", string phone = "", string email = "",
     string description = "", string location = "")
 {
     try
     {
         using (DGGuardEntities entities = new DGGuardEntities())
         {
             genPath = Server.MapPath("/UploadImage/");
             ;
             string fileName = (DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".png").Replace(" ", "");
             try
             {
                 byte[] data = Convert.FromBase64String(img);
                 var fs =
                     new BinaryWriter(new FileStream(Path.Combine(genPath, fileName), FileMode.Append,
                         FileAccess.Write));
                 fs.Write(data);
                 fs.Close();
             }
             catch (Exception ex)
             {
                 Logger.GetInstance.Log(LogType.Error, "Unable to save Image: " + ex.Message);
             }
             FactReport f = new FactReport
             {
                 URL = url,
                 TimeStamp = DateTime.Now,
                 Location = location,
                 Description = description,
                 Name = name,
                 LastName = lName,
                 Email = email,
                 Phone = phone,
                 ScreenShot = genPath + fileName,
                 DimCategory = entities.DimCategories.FirstOrDefault(x => x.CategoryId == category),
                 DimStatu = entities.DimStatus.FirstOrDefault(x => x.StatusID == 0)
             };
             entities.FactReports.Add(f);
             entities.SaveChanges();
         }
         return "Success";
     }
     catch (Exception ex)
     {
         Logger.GetInstance.Log(LogType.Error, "PostReport Failed: "+ ex.Message);
         return "fail";
     }
 }
Exemplo n.º 7
0
 public string AuthenticateUser(string username, string password)
 {
     try
     {
         using (DGGuardEntities entities = new DGGuardEntities())
         {
             var data = entities.DimUsers.FirstOrDefault(x => x.UserName == username);
             if (data != null)
             {
                 return
                     JsonConvert.SerializeObject(StringCipher.ValidatePassword(password, data.Password, data.Salt));
             }
             return JsonConvert.SerializeObject(false);
         }
     }
     catch (Exception ex)
     {
         Logger.GetInstance.Log(LogType.Error, "Authentication Failed: " + ex.Message);
         return JsonConvert.SerializeObject(false);
     }
 }
Exemplo n.º 8
0
 public string PostReportImage(string img)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         string fileName = DateTime.Now + ".png";
         byte[] data = Convert.FromBase64String(img);
         var fs =
             new BinaryWriter(new FileStream(genPath + fileName, FileMode.Append,
                 FileAccess.Write));
         fs.Write(data);
         fs.Close();
     }
     return "sucess";
 }
 public string GetCategories()
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         var data = entities.DimCategories.ToList();
         JsonSerializerSettings settings = new JsonSerializerSettings
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         };
         return JsonConvert.SerializeObject(data, settings);
     }
 }
Exemplo n.º 10
0
 public string GetUserActions(string user)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         var data = entities.Changes.Where(x => x.UserName == user).ToList();
         JsonSerializerSettings settings = new JsonSerializerSettings
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         };
         return JsonConvert.SerializeObject(data, settings);
     }
 }
Exemplo n.º 11
0
 public string GetSubReports(string url)
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         var data = entities.FactReports.Where(x => x.URL == url);
         JsonSerializerSettings settings = new JsonSerializerSettings
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         };
         return JsonConvert.SerializeObject(data, settings);
     }
 }
Exemplo n.º 12
0
        public string GetReports()
        {
            using (DGGuardEntities entities = new DGGuardEntities())
            {
                var data = entities.FactReports.Where(x => x.StatusID != 2).ToList();
                List<Cluster> list = new List<Cluster>();
                foreach (FactReport report in data)
                {
                    Cluster c = list.FirstOrDefault(x => String.Equals(x.URL, report.URL));
                    if (c == null)
                    {
                        c = new Cluster() { URL = report.URL, status = report.DimStatu };
                        list.Add(c);
                    }
                    c.Amount++;
                    c.Reports.Add(report);

                }
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                };
                return JsonConvert.SerializeObject(list, settings);
            }
        }
Exemplo n.º 13
0
 public string GetStatistics()
 {
     using (DGGuardEntities entities = new DGGuardEntities())
     {
         string stat = "{";
         var data = entities.FactReports.ToList();
         stat += "\"Reports\":{\"NumberofPending\":" + data.Count(x => x.StatusID == 0) + "," +
                 "\"NumberofInProgress\":" + data.Count(x => x.StatusID == 1) + "," +
                 "\"NumberofDone\":" + data.Count(x => x.StatusID == 2) + "}";
         stat += ",\"Categories\":[";
         foreach (DimCategory category in entities.DimCategories.ToList())
         {
             stat += "{\"Name\":\"" + category.Category +
                 "\",\"AmountOfReports\":" + category.FactReports.Count + "},";
         }
         stat = stat.Substring(0, stat.Length - 1) + "]";
         return stat + "}";
     }
 }
Exemplo n.º 14
0
        public string GetReports()
        {
            List<Cluster> list = new List<Cluster>();
            try
            {
                using (DGGuardEntities entities = new DGGuardEntities())
                {
                    var data = entities.FactReports.Where(x => x.StatusID < 2).ToList();
                    foreach (FactReport report in data)
                    {
                        Cluster c = list.FirstOrDefault(x => String.Equals(x.URL, report.URL));
                        if (c == null)
                        {
                            c = new Cluster
                            {
                                URL = report.URL,
                                status = new DimStatuPrivate(report.DimStatu.StatusID, report.DimStatu.StatusName)
                            };
                            if (report.TimeStamp > c.Time)
                                c.Time = report.TimeStamp;
                            list.Add(c);
                        }
                        c.Amount++;
                        c.Reports.Add(new FaceReportPrivate(report));

                    }

                }
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                };
                return JsonConvert.SerializeObject(list, settings);

            }
            catch (Exception e)
            {
                Logger.GetInstance.Log(LogType.Error, "GetRerpots Failed: " + e.Message);
                return "";
            }
        }
Exemplo n.º 15
0
 public string GetAllReports()
 {
     try
     {
         using (DGGuardEntities entities = new DGGuardEntities())
         {
             var data = entities.FactReports.ToList();
             List<FaceReportPrivate> list = data.Select(factReport => new FaceReportPrivate(factReport)).ToList();
             JsonSerializerSettings settings = new JsonSerializerSettings
             {
                 ReferenceLoopHandling = ReferenceLoopHandling.Ignore
             };
             return JsonConvert.SerializeObject(list, settings);
         }
     }
     catch (Exception ex)
     {
         Logger.GetInstance.Log(LogType.Error, "GetAllReports Failed: " + ex.Message);
         return JsonConvert.SerializeObject(false);
     }
 }