Esempio n. 1
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            SeoFirmaListele list = new SeoFirmaListele();

            foreach (var item in list.firmaGetir())
            {
                routes.MapRoute(
                    name: AdGetir.LinkAd(item.SeoName).ToString(),
                    url: AdGetir.LinkAd(item.SeoName).ToString(),
                    defaults: new { controller = "Firma", action = "DetayGetir", id = item.ID }
                    );
            }


            //routes.MapRoute(
            //      name: "Anasayfa",
            //      url: "Anasayfa",
            //      defaults: new { controller = "Home", action = "Index" }
            //  );
            routes.MapRoute(
                name: "Login",
                url: "Login",
                defaults: new { controller = "Home", action = "Login" }
                );
            routes.MapRoute(
                name: "HataSayfasi",
                url: "HataSayfasi",
                defaults: new { controller = "Home", action = "AccessDenied" }
                );
            routes.MapRoute(
                name: "Iletisim",
                url: "iletisim",
                defaults: new { controller = "Iletisim", action = "Index" }
                );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
            routes.MapRoute(
                name: "Default2",
                url: "{controller}/{action}/{Aciklama}/{id}",
                defaults: new { controller = "Home", action = "Index", Aciklama = "TOSS", id = UrlParameter.Optional }
                );
        }
        public ActionResult Ekle(KategoriFirmaViewModel model, HttpPostedFileBase FirmaLogo, IEnumerable <HttpPostedFileBase> FirmaResimler)
        {
            //ModelState.Remove("FirmaAdi");
            //ModelState.Remove("FirmaTel");
            //ModelState.Remove("Adres");
            ModelState.Clear();
            //ModelState.Remove("KategoriAdi");
            //ModelState.Remove("KategoriAciklama");

            if (ModelState.IsValid)
            {
                int i = KontrolEt(model);

                if (i == 1)
                {
                    //model.FirmaKategoriler = _managerFirmaKategori.List();
                    //ViewBag.FirmaKategoriID = new SelectList(_managerFirmaKategori.List(), "ID", "KategoriAdi");
                    model.FirmaKategoriler = _managerFirmaKategori.List();
                    return(View(model));
                }

                //FirmaKategori kat = _managerFirmaKategori.Find(x => x.ID == FirmaKategoriID);
                //model.Firma.Kategori = kat;

                #region Firma Logo Ekleme
                if (FirmaLogo != null &&
                    (FirmaLogo.ContentType == "image/jpeg" ||
                     FirmaLogo.ContentType == "image/jpg" ||
                     FirmaLogo.ContentType == "image/png"))
                {
                    try
                    {
                        string filename = $"{AdGetir.LinkAd(model.Firma.FirmaAdi)}.{FirmaLogo.ContentType.Split('/')[1]}";
                        FirmaLogo.SaveAs(Server.MapPath($"~/img/Firma/{filename}"));
                        model.Firma.Logo = filename;
                    }
                    catch (Exception exp)
                    {
                        ModelState.AddModelError("", exp.Message);
                    }
                }
                #endregion
                int res = _managerFirma.Insert(model.Firma);
                if (res == 0)
                {
                    ModelState.AddModelError("", "Firma Eklenemedi");
                    //model.FirmaKategoriler = _managerFirmaKategori.List();
                    //ViewBag.FirmaKategoriID = new SelectList(_managerFirmaKategori.List(), "ID", "KategoriAdi");
                    return(View(model));
                }
                foreach (FirmaKategori item in model.FirmaKategoriler)
                {
                    if (item.Secili)
                    {
                        Firma_Kategori1 fk = new Firma_Kategori1();
                        fk.FirmaKategori = _managerFirmaKategori.Find(x => x.ID == item.ID);
                        fk.Firma         = _managerFirma.Find(x => x.ID == model.Firma.ID);

                        _managerFirmaKategoriBag.Add(fk);
                    }
                }
                _managerFirmaKategoriBag.Save();

                #region Firma Resimler Ekleme
                if (FirmaResimler != null && FirmaResimler.Count() > 0)
                {
                    foreach (HttpPostedFileBase file in FirmaResimler)
                    {
                        if (file != null &&
                            (file.ContentType == "image/jpeg" ||
                             file.ContentType == "image/jpg" ||
                             file.ContentType == "image/png"))
                        {
                            try
                            {
                                FirmaResim rsm      = new FirmaResim();
                                string     filename = $"{AdGetir.ResimAd(model.Firma.FirmaAdi)}.{file.ContentType.Split('/')[1]}";
                                file.SaveAs(Server.MapPath($"~/img/Firma/{filename}"));

                                rsm.ResimYol = filename;
                                rsm.FirmaID  = model.Firma.ID;
                                _managerFirmaResim.Add(rsm);
                            }
                            catch (Exception exp)
                            {
                                ModelState.AddModelError("", exp.Message);
                            }
                        }
                    }
                    _managerFirmaResim.Save();
                }
                #endregion
                return(RedirectToAction("Index"));
            }
            model.FirmaKategoriler = _managerFirmaKategori.List();
            //ViewBag.FirmaKategoriID = new SelectList(_managerFirmaKategori.List(), "ID", "KategoriAdi");
            return(View(model));
        }
        public ActionResult SiteMapOlustur()
        {
            DatabaseContext Veri = new DatabaseContext();

            Response.Clear();
            //Response.ContentTpye ile bu Action'ın View'ını XML tabanlı olarak ayarlıyoruz.
            Response.ContentType = "text/xml";
            string xmlPath = Server.MapPath("~/sitemap.xml");
            //Response.OutputStream
            XmlTextWriter xr = new XmlTextWriter(xmlPath, Encoding.UTF8);

            xr.Formatting = Formatting.Indented;

            xr.WriteStartDocument();
            xr.WriteStartElement("urlset");//urlset etiketi açıyoruz
            xr.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
            xr.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xr.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd");
            /* sitemap dosyamızın olmazsa olmazını ekledik. Şeması bu dedik buraya kadar.  */

            xr.WriteStartElement("url");
            xr.WriteElementString("loc", "http://teknikotosanayi.com/");
            xr.WriteElementString("changefreq", "daily");
            xr.WriteElementString("priority", "1.00");
            xr.WriteEndElement();

            xr.WriteStartElement("url");
            xr.WriteElementString("loc", "http://teknikotosanayi.com/iletisim");
            xr.WriteElementString("changefreq", "daily");
            xr.WriteElementString("priority", "0.90");
            xr.WriteEndElement();

            //Burada veritabanımızdaki Firmaları SiteMap'e ekliyoruz.
            var s = Veri.Firmalar.ToList();

            foreach (var a in s)
            {
                xr.WriteStartElement("url");
                xr.WriteElementString("loc", "http://teknikotosanayi.com/" + AdGetir.LinkAd(a.SeoName));
                xr.WriteElementString("priority", "0.90");
                xr.WriteElementString("changefreq", "daily");
                xr.WriteEndElement();
            }

            //Aynı şekilde burada da Haberleri SiteMap'e ekliyoruz.
            var k = Veri.Haberler;

            foreach (var b in k)
            {
                xr.WriteStartElement("url");
                xr.WriteElementString("loc", "http://teknikotosanayi.com//Haber/DetayGetir/" + @AdGetir.LinkAd(b.HaberBaslik) + "/" + b.ID);
                xr.WriteElementString("priority", "0.90");
                xr.WriteElementString("changefreq", "daily");
                xr.WriteEndElement();
            }


            //Aynı şekilde burada da Kurumsal'ı Sitemap'e ekliyoruz.
            var kurumsal = Veri.KurumsalKategoriler.ToList();

            foreach (var kurum in kurumsal)
            {
                xr.WriteStartElement("url");
                xr.WriteElementString("loc", "http://teknikotosanayi.com//Kurumsal/DetayGetir/" + @AdGetir.LinkAd(kurum.KategoriAdi) + "/" + kurum.ID);
                xr.WriteElementString("priority", "0.90");
                xr.WriteElementString("changefreq", "daily");
                xr.WriteEndElement();
            }

            xr.WriteEndDocument();

            //urlset etiketini kapattık
            xr.Flush();
            xr.Close();
            Response.End();

            return(View("Index"));
        }