Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            using (Db db = new Db())
            {
                SearchesHistoryDTO dto = db.SearchesHistory.Find(id);
                db.SearchesHistory.Remove(dto);
                db.SaveChanges();

                int traceDetailsCount = db.TraceDetails.ToArray().Where(x => x.SearchId == id).Count();
                for (int i = 0; i < traceDetailsCount; i++)
                {
                    TraceDetailsDTO detailsDTO = db.TraceDetails.FirstOrDefault(x => x.SearchId == id);
                    db.TraceDetails.Remove(detailsDTO);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult SearchQuery(SearchHistoryVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                SearchesHistoryDTO dto = new SearchesHistoryDTO
                {
                    WebsiteAddress = model.WebsiteAddress.ToLower()
                };

                db.SearchesHistory.Add(dto);
                db.SaveChanges();

                #region Fill tblTraceDetails

                int numberOfSearch = db.SearchesHistory.ToArray().Select(x => x.Id).Last();
                Dictionary <IPAddress, ushort> pairs = GetTraceRoute(model.WebsiteAddress);

                foreach (var pair in pairs)
                {
                    TraceDetailsDTO detailsDTO = new TraceDetailsDTO()
                    {
                        SearchId = numberOfSearch,
                        Ip       = pair.Key.ToString(),
                        Ping     = pair.Value
                    };

                    db.TraceDetails.Add(detailsDTO);
                }

                db.SaveChanges();

                #endregion
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
 public SearchHistoryVM(SearchesHistoryDTO row)
 {
     Id             = row.Id;
     WebsiteAddress = row.WebsiteAddress;
 }