Ejemplo n.º 1
0
 public SearchDetailsVM(SearchDetailsDTO row)
 {
     Id       = row.Id;
     SearchId = row.SearchId;
     Site     = row.Site;
     Ping     = row.Ping;
 }
Ejemplo n.º 2
0
        // POST: Sitemap/Delete/5
        public ActionResult Delete(int id)
        {
            using (Db db = new Db())
            {
                SearchDTO dto = db.Searches.Find(id);
                db.Searches.Remove(dto);
                db.SaveChanges();

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

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Create(SearchVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                // Checks whether the input is correct url
                Uri baseURI = new Uri(model.WebsiteAddress);     // Сделать принудительную очистку

                List <string> addressList = GetAllSiteFromSitemap(model.WebsiteAddress);

                if (addressList.Count == 0)
                {
                    throw new Exception();
                }

                List <ushort> pingList = GetResponseTime(addressList);

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

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

                    int numberOfSearch = db.Searches.ToArray().Select(x => x.Id).Last();

                    for (int i = 0; i < addressList.Count; ++i)
                    {
                        SearchDetailsDTO detailsDTO = new SearchDetailsDTO()
                        {
                            SearchId = numberOfSearch,
                            Site     = addressList[i],
                            Ping     = pingList[i]
                        };

                        db.SearchDetails.Add(detailsDTO);
                    }

                    db.SaveChanges();
                }

                TempData["SM"] = "You have added a new search query!";

                return(RedirectToAction("Index"));
            }
            catch (UriFormatException)
            {
                TempData["DM"] = "The address is wrong, follow the advice!";
                return(View());
            }
            catch (Exception)
            {
                TempData["DM"] = "There are no links in sitemap.xml or the site has no sitemap.xml!";
                return(View());
            }
        }