Esempio n. 1
0
        public async Task <IActionResult> Edit(string id, [Bind("Name,Description,Price,Category,Image,Id,CreatedAt")] Prodotti prodotti)
        {
            if (id != prodotti.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(prodotti);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProdottiExists(prodotti.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(prodotti));
        }
        public ActionResult ProdottoTest(string collezione = "", string categoria = "", string prodotto = "")
        {
            string lang = "it";

            if (!string.IsNullOrEmpty(prodotto))
            {
                //PAGINA PRODOTTO
                Collezioni coll = db.Collezioni.Where(x => x.lang == lang && x.urlname == collezione).FirstOrDefault();
                Categorie  cat  = db.Categorie.Where(x => x.lang == lang && x.urlname == categoria).FirstOrDefault();

                string listacollezioniurl  = (lang == "it" ? "/collezioni" : "/collections");
                string listacollezionitext = (lang == "it" ? "Collezioni" : "Collections");

                string collezioneig = coll.itemgroup.ToString();
                string categoriaig  = cat.itemgroup.ToString();

                Prodotti p = db.Prodotti.Where(x => x.collezione.StartsWith(collezioneig + "|") && x.categoria.StartsWith(categoriaig + "|") && x.lang == lang && x.visibile == true && x.codice == prodotto).FirstOrDefault();

                if (p == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni"));
                }

                string link = "<a href=\"" + LanguageSetting.GetLangNavigation() + "{0}\">{1}</a>";



                ProdottoPage pp = new ProdottoPage();
                pp.Prodotto = p;

                //TODO - RIMUOVERE modifica temporanea in attesa del listino it a marzo 2020
                if (lang == "it")
                {
                    pp.Finiture = p.ListaFiniture == null ? new List <Finiture>() : p.ListaFiniture;
                }
                else
                {
                    pp.Finiture = p.ListaFinitureEstero == null ? new List <Finiture>() : p.ListaFinitureEstero;
                }

                string[] igfiniture = pp.Finiture.Select(f => f.gruppoitemgroup).ToArray();
                pp.GruppiFiniture = db.FinitureGruppi.Where(x => x.lang == lang && igfiniture.Contains(x.itemgroup.ToString())).OrderBy(x => x.ordinamento).ToList();


                pp.Accessori = p.ListaAccessori;

                pp.breadcrumb = string.Format(link, "/", "Ceramica Globo") + " | " +
                                string.Format(link, listacollezioniurl, listacollezionitext) + " | " +
                                string.Format(link, listacollezioniurl + "/" + coll.urlname, coll.titolo) + " | " +
                                string.Format(link, listacollezioniurl + "/" + coll.urlname + "/" + cat.urlname, cat.titolo) + " | " +
                                "<span>" + p.titolo + " " + p.codice + "</span>";

                pp.backurl = listacollezioniurl + "/" + coll.urlname + "/" + cat.urlname + "?p=" + prodotto;

                pp.isLogged = HttpContext.User.Identity.IsAuthenticated;
                return(View("ProdottoTest", pp));
            }

            return(View("ProdottoTest", null));
        }
Esempio n. 3
0
        private static void SalvaProdottiInFile(Prodotti product)
        {
            //Assicuriamoci che esista la folder per il file di archivio
            var archiveFolder = FunzioniFileSystem.AssicuratiCheEsistaCartellaDiArchivio();
            //** Arrivo a questo punto e sono sicuro al 100% che la cartella dove
            //** sarà conservato il file database esiste: ne ottengo il percorso

            string datiDellaPersonaInFormatoStringa = ConvertiPersonaInStringa(product);

            //Aggiungi testo a file
            FunzioniFileSystem.AggiungiTestoAFileDatabase(datiDellaPersonaInFormatoStringa, archiveFolder);
        }
Esempio n. 4
0
        /// <summary>
        /// Ricerca di un prodotto esistente
        /// </summary>
        /// <param name="codiceProdotto"></param>
        /// <returns></returns>
        public Prodotto RicercaProdotto(string codiceProdotto)
        {
            DB.Prodotto pr;

            try
            {
                pr = Prodotti.Include(i => i.Produttore)
                     .Single(n => n.CodiceArticolo == codiceProdotto);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(pr);
        }
Esempio n. 5
0
        public Prodotto RicercaProdotto(int id)
        {
            DB.Prodotto pr;
            try
            {
                pr = Prodotti.Include(i => i.Produttore).Include(i => i.Storici)
                     .Single(n => n.Id == id);
            }
            catch (Exception ex)
            {
                return(null);
            }


            return(pr);
        }
Esempio n. 6
0
        /// <summary>
        /// Rimozione Prodotto
        /// </summary>
        /// <param name="id"></param>
        /// <param name="numero"></param>
        /// <returns></returns>
        public int RimuoviProdotto(int id, int numero)
        {
            bool exist = Prodotti.Any(p => p.Id == id);

            if (exist)
            {
                List <DB.Storico> s = Storici.Where(pr => pr.ProdottoId == id).Take(numero).ToList();
                if (s != null)
                {
                    Storici.RemoveRange(s);
                }
                return(SaveChanges());
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 7
0
        public int[] CreaNuovoProdotto(Prodotto p, int pezzi = 0)
        {
            int[] ret   = new int[2];
            bool  exist = Prodotti.Any(pr => pr.CodiceArticolo == p.CodiceArticolo);

            if (!exist)
            {
                Prodotti.Add(p);
                ret[0] = SaveChanges();
                AggiungiProdotto(p.Id, pezzi);
                ret[1] = SaveChanges();
                return(ret);
            }
            else
            {
                return(new int[] { -1, -1 });
            }
        }
Esempio n. 8
0
        private static void AggiungiPersonaARubricaInPosizione(List <Prodotti> elenco)
        {
            // Richiedo il codice e il nome
            Console.Write("CodiceAlfanumerico: ");
            var code = Console.ReadLine();

            Console.Write("NomeProdotto: ");
            var name = Console.ReadLine();

            //Creo oggetto PRodotto da inserire in Elenco
            Prodotti product = new Prodotti
            {
                CodiceAlfanumerico = code,
                NomeProdotto       = name
            };

            //7) Aggiungo prodotto a elenco
            elenco.Add(product);
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("Name,Description,Price,Category,ImageFile,Id,CreatedAt")] Prodotti prodotti)
        {
            if (ModelState.IsValid)
            {
                string wwwRootPath = _hostingEnvironment.WebRootPath;
                string fileName    = Path.GetFileName(prodotti.ImageFile.FileName);

                string path = Path.Combine(wwwRootPath + "/Images/", fileName);
                using (var fileSteam = new FileStream(path, FileMode.Create))
                {
                    await prodotti.ImageFile.CopyToAsync(fileSteam);
                }


                _context.Add(prodotti);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prodotti));
        }
Esempio n. 10
0
        public int AggiungiProdotto(string codice, int numero)
        {
            bool exist = Prodotti.Any(p => p.CodiceArticolo == codice);

            if (exist)
            {
                DB.Prodotto p = Prodotti.Single(i => i.CodiceArticolo == codice);
                for (int i = 0; i < numero; i++)
                {
                    Storici.Add(new DB.Storico()
                    {
                        ProdottoId      = p.Id,
                        DataInserimento = DateTime.Now,
                    });
                }
                return(SaveChanges());
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 11
0
        public int[] CreaNuovoProdotto(string codice, int produttoreId, int pezzi = 0, decimal costoAquisto = 0, decimal prezzoVendita = 0)
        {
            int[] ret   = new int[2];
            bool  exist = Prodotti.Any(p => p.CodiceArticolo == codice);

            if (!exist)
            {
                DB.Prodotto p = new DB.Prodotto()
                {
                    ProduttoreId   = produttoreId,
                    CodiceArticolo = codice.Trim().ToUpper()
                };
                Prodotti.Add(p);
                ret[0] = SaveChanges();
                AggiungiProdotto(p.Id, pezzi);
                ret[1] = SaveChanges();
                return(ret);
            }
            else
            {
                return(new int[] { -1, -1 });
            }
        }
Esempio n. 12
0
 public List <Prodotto> GetProdotti(string codice)
 {
     return(Prodotti.Include(i => i.Storici).Include(i => i.Produttore).Where(i => i.CodiceArticolo.Contains(codice) || i.Nome.Contains(codice)).ToList());
 }
Esempio n. 13
0
 /// <summary>
 /// 	Restituisce l'url del prodotto
 /// </summary>
 /// <param name = "prodotti"></param>
 /// <returns></returns>
 public string GetUrlItem(Prodotti prodotti)
 {
     return GetRouteUrl(RouteNameEnum.Item.ToString(), new {
                                                             lang = Languages.IsoCode,
                                                             item = prodotti.Url
                                                           }).ToLower();
 }
Esempio n. 14
0
 /// <summary>
 /// Restituisce tutti i prodotti salvati in memoria
 /// </summary>
 /// <returns></returns>
 public List <Prodotto> GetProdotti()
 {
     return(Prodotti.Include(i => i.Storici).Include(i => i.Produttore).ToList());
 }
        private void saveAdd(resourceDetail resource)
        {
            //db.Database.ExecuteSqlCommand(sb.ToString());'
            StringBuilder sb = new StringBuilder();

            switch (resource.rname.ToLower())
            {
            case "collezioni":
                string collezioneit = db.Collezioni.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();
                // aggiorno i prodotti
                sb.AppendLine("update prodotti set collezione='" + resource.itemgroup + "|" + collezioneit + "' where collezione like '" + resource.itemgroup + "|%';");
                break;

            case "categorie":
                string categoriait = db.Categorie.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();
                // aggiorno i prodotti
                sb.AppendLine("update prodotti set categoria='" + resource.itemgroup + "|" + categoriait + "' where categoria like '" + resource.itemgroup + "|%';");
                // aggiorno le sottocategorie
                sb.AppendLine("update sottocategorie set categoria='" + resource.itemgroup + "|" + categoriait + "' where categoria like '" + resource.itemgroup + "|%';");
                break;

            case "tipologiemenu":
                string tipologiait = db.TipologieMenu.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();
                // aggiorno i prodotti
                sb.AppendLine("update prodotti set tipologiamenu='" + resource.itemgroup + "|" + tipologiait + "' where tipologiamenu like '" + resource.itemgroup + "|%';");
                break;

            case "sottocategorie":
                string sottocategoriait = db.Sottocategorie.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();
                // aggiorno i prodotti
                sb.AppendLine("update prodotti set sottocategoria='" + resource.itemgroup + "|" + sottocategoriait + "' where sottocategoria like '" + resource.itemgroup + "|%';");
                break;

            case "finituregruppi":
                //152|Salice|11|Finiture Disponibili;8|Betulla|11|Finiture Disponibili;153|Smoke|11|Finiture Disponibili;68|Desert|11|Finiture Disponibili
                //igfinitura|finiturait|igfinituragruppo|finituragruppoit
                string finituragruppoit = db.FinitureGruppi.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();

                List <Prodotti> lp1 = db.Prodotti.Where(x => x.lang == "it" && x.finiture.Contains("|" + resource.itemgroup.ToString() + "|")).ToList();
                foreach (Prodotti p in lp1)
                {
                    string   newfiniture = "";
                    string[] finiture    = p.finiture.Split(';');
                    foreach (string f in finiture)
                    {
                        if (f.Split('|')[2] == resource.itemgroup.ToString())
                        {
                            // aggiorno finitura
                            newfiniture += f[0] + "|" + f[1] + "|" + f[2] + "|" + finituragruppoit + ";";
                        }
                        else
                        {
                            newfiniture += f + ";";
                        }
                    }

                    if (!string.IsNullOrEmpty(newfiniture))
                    {
                        sb.AppendLine("update prodotti set finiture=\"" + newfiniture.TrimEnd(';') + "\" where itemgroup=" + p.itemgroup + ";");
                    }
                }

                break;

            case "finiture":
                string          finiturait = db.Finiture.Where(x => x.itemgroup == resource.itemgroup && x.lang == "it").Select(x => x.titolo).FirstOrDefault();
                List <Prodotti> lp2        = db.Prodotti.Where(x => x.finiture.Contains(";" + resource.itemgroup.ToString() + "|") | x.finiture.StartsWith(resource.itemgroup.ToString() + "|")).ToList();
                foreach (Prodotti p in lp2)
                {
                    string   newfiniture = "";
                    string[] finiture    = p.finiture.Split(';');
                    foreach (string f in finiture)
                    {
                        if (f.Split('|')[0] == resource.itemgroup.ToString())
                        {
                            // aggiorno finitura
                            newfiniture += f[0] + "|" + finiturait + "|" + f[2] + "|" + f[3] + ";";
                        }
                        else
                        {
                            newfiniture += f + ";";
                        }
                    }

                    if (!string.IsNullOrEmpty(newfiniture))
                    {
                        sb.AppendLine("update prodotti set finiture=\"" + newfiniture.TrimEnd(';') + "\" where itemgroup=" + p.itemgroup + ";");
                    }
                }
                break;

            case "prodotti":
                Prodotti accessorio = db.Prodotti.Where(x => x.itemgroup == resource.itemgroup && x.tipologiaprodotto != "prodotto" && x.lang == "it").DefaultIfEmpty(null).FirstOrDefault();
                if (!(accessorio == null))
                {
                    // è un accessorio
                    //igprodotto|codice|titolo

                    List <Prodotti> lp = db.Prodotti.Where(x => x.accessori.Contains(";" + resource.itemgroup.ToString() + "|") | x.accessori.StartsWith(resource.itemgroup.ToString() + "|")).ToList();

                    foreach (Prodotti p in lp)
                    {
                        string   newaccessori = "";
                        string[] oldaccessori = p.accessori.Split(';');
                        foreach (string a in oldaccessori)
                        {
                            if (a.Split('|')[0] == resource.itemgroup.ToString())
                            {
                                // aggiorno finitura
                                newaccessori += a[0] + "|" + accessorio.codice + "|" + accessorio.titolo + ";";
                            }
                            else
                            {
                                newaccessori += a + ";";
                            }
                        }

                        if (!string.IsNullOrEmpty(newaccessori))
                        {
                            sb.AppendLine("update prodotti set accessori=\"" + newaccessori.TrimEnd(';') + "\" where itemgroup=" + p.itemgroup + ";");
                        }
                    }
                }
                break;
            }
            if (!string.IsNullOrEmpty(sb.ToString()))
            {
                db.Database.ExecuteSqlCommand(sb.ToString());
            }
        }
Esempio n. 16
0
 private static string ConvertiPersonaInStringa(Prodotti person)
 {
     return($"{person.CodiceAlfanumerico},{person.NomeProdotto}");
 }
Esempio n. 17
0
        public ActionResult Download(string lang, string igprodotto, string ftype)
        {
            // return Redirect(LanguageSetting.GetLangNavigation() + "/login");

            bool mustlogged = true;

            Prodotti p = db.Prodotti.Where(x => x.lang == lang && x.itemgroup.ToString() == igprodotto).FirstOrDefault();

            if (p == null)
            {
                return(Redirect(LanguageSetting.GetLangNavigation() + "/"));
            }
            string fname = "";

            switch (ftype)
            {
            case "scheda":
                mustlogged = false;
                fname      = p.scheda;
                break;

            case "istruzioni":
                mustlogged = false;
                fname      = p.istruzioni;
                break;

            case "scassi":
                mustlogged = false;
                fname      = p.scassi;
                break;

            case "capitolato":
                mustlogged = false;
                fname      = p.capitolato;
                break;

            case "dop":
                mustlogged = false;
                fname      = p.prestazione;
                break;

            case "cad":
                mustlogged = true;
                fname      = p.cad;
                break;

            case "3ds":
                mustlogged = true;
                fname      = p.f3ds;
                break;

            case "revit":
                mustlogged = true;
                fname      = p.revit;
                break;

            case "archicad":
                mustlogged = true;
                fname      = p.archicad;
                break;

            case "sketchup":
                mustlogged = true;
                fname      = p.sketchup;
                break;
            }

            if (string.IsNullOrEmpty(fname))
            {
                return(Redirect(LanguageSetting.GetLangNavigation() + "/"));
            }


            if (mustlogged == true && !HttpContext.User.Identity.IsAuthenticated)
            {
                return(Redirect(LanguageSetting.GetLangNavigation() + "/"));
            }

            byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(fname));
            string fileName  = System.IO.Path.GetFileName(fname);

            return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
        }
Esempio n. 18
0
        // GET: Default
        public ActionResult Index()
        {
            Prodotti p = new Prodotti("FileDati.txt");

            return(View(p));
        }
        public ActionResult Collezioni(string lang = "it", string collezione = "", string categoria = "", string prodotto = "")
        {
            if (!string.IsNullOrEmpty(prodotto))
            {
                //PAGINA PRODOTTO
                Collezioni coll = db.Collezioni.Where(x => x.lang == lang && x.urlname == collezione).FirstOrDefault();
                Categorie  cat  = db.Categorie.Where(x => x.lang == lang && x.urlname == categoria).FirstOrDefault();

                string listacollezioniurl  = (lang == "it" ? "/collezioni" : "/collections");
                string listacollezionitext = (lang == "it" ? "Collezioni" : "Collections");

                string collezioneig = coll.itemgroup.ToString();
                string categoriaig  = cat.itemgroup.ToString();

                Prodotti p = db.Prodotti.Where(x => x.collezione.StartsWith(collezioneig + "|") && x.categoria.StartsWith(categoriaig + "|") && x.lang == lang && x.visibile == true && x.codice == prodotto).FirstOrDefault();

                if (p == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni"));
                }

                string link = "<a href=\"" + LanguageSetting.GetLangNavigation() + "{0}\">{1}</a>";


                ProdottoPage pp = new ProdottoPage();
                pp.Prodotto = p;

                //TODO - RIMUOVERE modifica temporanea in attesa del listino it a marzo 2020
                //if (lang == "it" || lang=="de")
                //{
                //    pp.Finiture = p.ListaFiniture == null ? new List<Finiture>() : p.ListaFiniture;
                //}
                //else
                //{
                //    pp.Finiture = p.ListaFinitureEstero == null ? new List<Finiture>() : p.ListaFinitureEstero;
                //}

                pp.Finiture = p.ListaFiniture == null ? new List <Finiture>() : p.ListaFiniture;


                string[] igfiniture = pp.Finiture.Select(f => f.gruppoitemgroup).ToArray();
                pp.GruppiFiniture = db.FinitureGruppi.Where(x => x.lang == lang && igfiniture.Contains(x.itemgroup.ToString())).OrderBy(x => x.ordinamento).ToList();

                pp.Accessori = p.ListaAccessori;

                pp.breadcrumb = string.Format(link, "/", "Ceramica Globo") + " | " +
                                string.Format(link, listacollezioniurl, listacollezionitext) + " | " +
                                string.Format(link, listacollezioniurl + "/" + coll.urlname, coll.titolo) + " | " +
                                string.Format(link, listacollezioniurl + "/" + coll.urlname + "/" + cat.urlname, cat.titolo) + " | " +
                                "<span>" + p.titolo + " " + p.codice + "</span>";

                pp.backurl = listacollezioniurl + "/" + coll.urlname + "/" + cat.urlname + "?p=" + prodotto;

                pp.isLogged = HttpContext.User.Identity.IsAuthenticated;

                return(View("Prodotto", pp));
            }
            else if (!string.IsNullOrEmpty(categoria))
            {
                // COLLEZIONE CATEGORIA (INVIO I PRODOTTI DI UNA SPECIFICA CATEGORIA)

                Collezioni c = db.Collezioni.Where(x => x.urlname == collezione && x.lang == lang).DefaultIfEmpty(null).FirstOrDefault();
                if (c == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni"));
                }

                CollezioneProdotti cp = new CollezioneProdotti();
                cp.Collezione     = c;
                cp.Prodotti       = new List <Prodotti>();
                cp.Sottocategorie = new Dictionary <int, string>();

                string igcat = db.Categorie.Where(x => x.urlname == categoria && x.lang == lang).Select(x => x.itemgroup).FirstOrDefault().ToString();

                // ECCEZIONE VASI E BIDET 4ALL
                cp.Prodotti = db.Prodotti
                              .Where(x => x.collezione.StartsWith(c.itemgroup.ToString() + "|") && x.lang == lang && x.visibile == true && x.tipologiaprodotto == "prodotto" && x.categoria.StartsWith(igcat + "|"))
                              //.OrderBy(x => x.codice).ToList();
                              .OrderByDescending(x => x.basecm).ThenByDescending(x => x.altezzacm).ThenByDescending(x => x.profonditacm).ThenBy(x => x.codice)
                              .ToList();



                string[] igsubcat = cp.Prodotti.GroupBy(x => x.sottocategoria).Select(x => x.FirstOrDefault()).ToList().Select(x => x.sottocategoriaitemgroup).ToArray();

                List <Sottocategorie> sc = db.Sottocategorie.Where(x => x.lang == lang && igsubcat.Contains(x.itemgroup.ToString())).OrderBy(x => x.ordinamento).ToList();
                sc.ForEach(x =>
                {
                    cp.Sottocategorie.Add(x.itemgroup, x.titolo);
                });

                cp.CategoriaName    = db.Categorie.Where(x => x.itemgroup.ToString() == igcat && x.lang == lang).Select(x => x.titolo).FirstOrDefault();
                cp.CollezioneLink   = (lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni") + "/" + c.urlname;
                cp.CategoriaUrlName = categoria;

                return(View("CollezioneCategoria", cp));
            }
            else if (!string.IsNullOrEmpty(collezione))
            {
                // COLLEZIONE SPECIFICA
                Collezioni c = db.Collezioni.Where(x => x.urlname == collezione && x.lang == lang).DefaultIfEmpty(null).FirstOrDefault();
                if (c == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni"));
                }

                CollezioneCategorie cat = new CollezioneCategorie();
                cat.Collezione = c;
                cat.Categorie  = new List <CategoriaLink>();

                // categorie
                List <Prodotti> prodotti             = db.Prodotti.Where(x => x.collezione.StartsWith(c.itemgroup.ToString() + "|") && x.lang == lang && x.visibile == true && x.tipologiaprodotto == "prodotto").GroupBy(x => x.categoria).Select(x => x.FirstOrDefault()).ToList();
                string          collezioneurlnameita = db.Collezioni.Where(x => x.lang == "it" && x.itemgroup == c.itemgroup).Select(x => x.urlname).FirstOrDefault();
                string[]        igcat;


                igcat = prodotti.Select(x => x.categoriaitemgroup).ToArray();

                List <Categorie> cc = db.Categorie.Where(x => igcat.Contains(x.itemgroup.ToString()) && x.lang == lang).OrderBy(x => x.ordinamento).ToList();
                cc.ForEach(x =>
                {
                    string urlinvariant = db.Categorie.Where(coll => coll.itemgroup == x.itemgroup && coll.lang == "it").Select(coll => coll.urlname).FirstOrDefault();

                    string imgcat = "/public/resource/prodotti/imgcategorie/" + urlinvariant + "/" + collezioneurlnameita + ".jpg";

                    if (!System.IO.File.Exists(Server.MapPath(imgcat)))
                    {
                        imgcat = prodotti.Where(p => p.categoria.StartsWith(x.itemgroup.ToString() + "|")).Select(p => p.imgmain).FirstOrDefault();
                    }
                    // se non ci sono prodotti non visualizzo la categoria|
                    if (db.Prodotti.Where(j => j.collezione.StartsWith(c.itemgroup + "|") && j.categoria.StartsWith(x.itemgroup + "|") && j.visibile == true && j.lang == lang && j.tipologiaprodotto != "accessorio").Count() > 0)
                    {
                        cat.Categorie.Add(new CategoriaLink
                        {
                            Categoria = x.titolo,
                            img       = imgcat,
                            link      = x.urlname
                        });
                    }
                });

                return(View("CollezioniDettaglio", cat));
            }
            else
            {
                // LISTA COLLEZIONI
                PageInfo p = db.PageInfo.Where(x => x.pname == "collezioni" && x.lang == lang)?.FirstOrDefault();
                return(View(p));
            }
        }
        public ActionResult Tipologie(string lang = "it", string tipologia = "", string prodotto = "", string collezione = "")
        {
            if (!string.IsNullOrEmpty(prodotto))
            {
                // PRODOTTO
                Collezioni    coll = db.Collezioni.Where(x => x.lang == lang && x.urlname == collezione).FirstOrDefault();
                TipologieMenu tip  = db.TipologieMenu.Where(x => x.lang == lang && x.urlname == tipologia).FirstOrDefault();

                string listatipologieurl  = (lang == "it" ? "/tipologie" : "/typologies");
                string listatipologietext = (lang == "it" ? "Tipologie" : "Typologies");
                string listacollezioniurl = (lang == "it" ? "/collezioni" : "/collections");

                string collezioneig = coll.itemgroup.ToString();
                string tipologiaig  = tip.itemgroup.ToString();

                Prodotti p = db.Prodotti.Where(x => x.collezione.StartsWith(collezioneig + "|") && x.tipologiamenu.StartsWith(tipologiaig + "|") && x.lang == lang && x.visibile == true && x.codice == prodotto).FirstOrDefault();

                if (p == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "collections" : "collezioni"));
                }

                string link = "<a href=\"" + LanguageSetting.GetLangNavigation() + "{0}\">{1}</a>";


                ProdottoPage pp = new ProdottoPage();
                pp.Prodotto = p;
                pp.Finiture = p.ListaFiniture == null ? new List <Finiture>() : p.ListaFiniture;
                string[] igfiniture = pp.Finiture.Select(f => f.gruppoitemgroup).ToArray();
                pp.GruppiFiniture = db.FinitureGruppi.Where(x => x.lang == lang && igfiniture.Contains(x.itemgroup.ToString())).OrderBy(x => x.ordinamento).ToList();
                pp.Accessori      = p.ListaAccessori;

                pp.breadcrumb = string.Format(link, "/", "Ceramica Globo") + " | " +
                                string.Format(link, listatipologieurl, listatipologietext) + " | " +
                                string.Format(link, listatipologieurl + "/" + tip.urlname, tip.titolo) + " | " +
                                string.Format(link, listacollezioniurl + "/" + coll.urlname, coll.titolo) + " | " +
                                "<span>" + p.titolo + " " + p.codice + "</span>";

                // pp.backurl = listacollezioniurl + "/" + coll.urlname;
                pp.backurl = listatipologieurl + "/" + tip.urlname + "?p=" + prodotto;


                pp.isLogged = HttpContext.User.Identity.IsAuthenticated;

                return(View("Prodotto", pp));
            }
            else if (!string.IsNullOrEmpty(collezione))
            {
                // REDIRECT TO COLLEZIONE
                return(Redirect(lang == "it" ? "/collezioni/" + collezione : "/collections/" + collezione));
            }
            else if (!string.IsNullOrEmpty(tipologia))
            {
                // DETTAGLIO TIPOLOGIA
                // lista prodotti per tipologia
                TipologieProdotti tp = new TipologieProdotti();

                TipologieMenu c = db.TipologieMenu.Where(x => x.urlname == tipologia && x.lang == lang).DefaultIfEmpty(null).FirstOrDefault();
                if (c == null)
                {
                    Response.Redirect((lang != "it" ? "/" + lang : "") + "/" + (lang != "it" ? "typologies" : "tipologie"));
                }

                tp.Metatitle        = c.metatitle;
                tp.Metadescription  = c.metadescription;
                tp.TipologiaName    = c.titolo;
                tp.TipologieLink    = (lang == "it" ? "/tipologie" : ("/" + lang + "/typologies"));
                tp.TipologiaUrlname = tipologia;

                List <Prodotti> lp = db.Prodotti
                                     .Where(x => x.tipologiamenu.StartsWith(c.itemgroup + "|") && x.lang == lang && x.visibile == true)
                                     .OrderByDescending(x => x.basecm).ThenByDescending(x => x.altezzacm).ThenByDescending(x => x.profonditacm).ThenBy(x => x.codice)
                                     .ToList();

                tp.Prodotti = lp;

                return(View("TipologieDettaglio", tp));
            }
            else
            {
                // LISTA TIPOLOGIE
                PageInfo p = db.PageInfo.Where(x => x.pname == "tipologie" && x.lang == lang)?.FirstOrDefault();
                return(View(p));
            }
        }
Esempio n. 21
0
        public ActionResult Sitemap(string lang = "it")
        {
            StringBuilder oBuilder = new StringBuilder();

            oBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            oBuilder.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml =\"http://www.w3.org/1999/xhtml\">");

            string[] langs      = db.Language.Where(x => x.abilitata == true).Select(x => x.lang).ToArray();
            string   langsuffix = lang == "it" ? "" : lang + "/";

            //return this.Content(xmlString, "text/xml");
            string datastr = DateTime.Now.AddDays(-3).Year + "-" + string.Format("{0:00}", DateTime.Now.AddDays(-3).Month) + "-" + string.Format("{0:00}", DateTime.Now.AddDays(-3).Day) + "T09:00:00+00:00";

            string baseurl = "https://www.ceramicaglobo.com/" + (lang == "it" ? "" : lang) + "/";
            string domain  = "https://www.ceramicaglobo.com";

            oBuilder.AppendLine("<url>");
            //current
            oBuilder.AppendLine("<loc>" + domain + (lang == "it" ? "" : "/" + lang) + "</loc>");
            // italiano
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"it\" href=\"" + domain + "\" />");
            // inglese
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"en\" href=\"" + domain + "/en\" />");
            // francese
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"fr\" href=\"" + domain + "/fr\" />");
            // spagnolo
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"es\" href=\"" + domain + "/es\" />");
            // tedesco
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"de\" href=\"" + domain + "/de\" />");
            // russo
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"ru\" href=\"" + domain + "/ru\" />");
            // cinese
            oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"ch\" href=\"" + domain + "/ch\" />");

            oBuilder.AppendLine("<lastmod>" + datastr + "</lastmod>");
            oBuilder.AppendLine("<changefreq>monthly</changefreq>");
            oBuilder.AppendLine("</url>");


            string collcontraint = lang == "it" ? "collezioni" : "collections";

            List <Collezioni> allcoll = db.Collezioni.Where(x => x.visibile == true).ToList();
            List <Categorie>  allcat  = db.Categorie.ToList();

            int[] igcoll = allcoll.Select(x => x.itemgroup).Distinct().ToArray();

            foreach (int ig in igcoll)
            {
                oBuilder.AppendLine("<url>");
                oBuilder.AppendLine("<loc>" + domain + (lang == "it" ? "" : "/" + lang) + "/" + collcontraint + "/" + allcoll.Where(x => x.itemgroup == ig && x.lang == lang).Select(x => x.urlname).FirstOrDefault() + "</loc>");

                foreach (string l in langs)
                {
                    collcontraint = l == "it" ? "collezioni" : "collections";
                    oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"" + l + "\" href=\"" + domain + (l == "it" ? "" : "/" + l) + "/" + collcontraint + "/" + allcoll.Where(x => x.itemgroup == ig && x.lang == l).Select(x => x.urlname).FirstOrDefault() + "\" />");
                }

                oBuilder.AppendLine("<lastmod>" + datastr + "</lastmod>");
                oBuilder.AppendLine("<changefreq>monthly</changefreq>");
                oBuilder.AppendLine("</url>");

                // categorie annesse
                List <String> allprodcat = db.Prodotti.Where(x => x.collezione.StartsWith(ig.ToString() + "|")).Select(x => x.categoria).Distinct().ToList();


                collcontraint = lang == "it" ? "collezioni" : "collections";
                foreach (string catstr in allprodcat)
                {
                    string igcat = catstr.Split('|')[0];

                    oBuilder.AppendLine("<url>");
                    oBuilder.AppendLine("<loc>" + domain + (lang == "it" ? "" : "/" + lang) + "/" + collcontraint + "/" + allcoll.Where(x => x.itemgroup == ig && x.lang == lang).Select(x => x.urlname).FirstOrDefault() + "/" + allcat.Where(x => x.lang == lang && x.itemgroup.ToString() == igcat).Select(x => x.urlname).FirstOrDefault() + "</loc>");

                    foreach (string l in langs)
                    {
                        collcontraint = l == "it" ? "collezioni" : "collections";
                        oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"" + l + "\" href=\"" + domain + (l == "it" ? "" : "/" + l) + "/" + collcontraint + "/" + allcoll.Where(x => x.itemgroup == ig && x.lang == l).Select(x => x.urlname).FirstOrDefault() + "/" + allcat.Where(x => x.lang == lang && x.itemgroup.ToString() == igcat).Select(x => x.urlname).FirstOrDefault() + "\" />");
                    }

                    oBuilder.AppendLine("<lastmod>" + datastr + "</lastmod>");
                    oBuilder.AppendLine("<changefreq>monthly</changefreq>");
                    oBuilder.AppendLine("</url>");
                }
            }



            // prodotti
            int[]           igprod  = db.Prodotti.Where(x => x.visibile == true && x.tipologiaprodotto == "prodotto").Select(x => x.itemgroup).Distinct().ToArray();
            List <Prodotti> allprod = db.Prodotti.Where(x => x.visibile == true && x.tipologiaprodotto == "prodotto" && x.lang == "it").ToList();

            foreach (int ig in igprod)
            {
                collcontraint = lang == "it" ? "collezioni" : "collections";
                Prodotti p = allprod.Where(x => x.itemgroup == ig).FirstOrDefault();

                string igcollezione = p.collezioneitemgroup;
                string igcategoria  = p.categoriaitemgroup;

                string urlnamecollezione = allcoll.Where(x => x.lang == lang && x.itemgroup.ToString() == igcollezione).Select(x => x.urlname).FirstOrDefault();
                string urlnamecategoria  = allcat.Where(x => x.lang == lang && x.itemgroup.ToString() == igcategoria).Select(x => x.urlname).FirstOrDefault();


                string codiceprodotto = p.codice;


                oBuilder.AppendLine("<url>");
                oBuilder.AppendLine("<loc>" + domain + "/" + collcontraint + "/" + urlnamecollezione + "/" + urlnamecategoria + "/" + codiceprodotto + "</loc>");

                foreach (string l in langs)
                {
                    collcontraint = l == "it" ? "collezioni" : "collections";

                    urlnamecollezione = allcoll.Where(x => x.lang == l && x.itemgroup.ToString() == igcollezione).Select(x => x.urlname).FirstOrDefault();
                    urlnamecategoria  = allcat.Where(x => x.lang == l && x.itemgroup.ToString() == igcategoria).Select(x => x.urlname).FirstOrDefault();

                    //  p = db.Prodotti.Where(x => x.lang == l && x.itemgroup == ig).FirstOrDefault();


                    //   urlnamecat = db.Categorie.Where(x => x.lang == l && x.itemgroup.ToString() == p.categoriaitemgroup).Select(x => x.urlname).FirstOrDefault();

                    oBuilder.AppendLine("<xhtml:link rel=\"alternate\" hreflang=\"" + l + "\" href=\"" + domain + (l == "it" ? "" : "/" + l) + "/" + collcontraint + "/" + urlnamecollezione + "/" + urlnamecategoria + "/" + codiceprodotto + "\" />");
                }

                oBuilder.AppendLine("<lastmod>" + datastr + "</lastmod>");
                oBuilder.AppendLine("<changefreq>monthly</changefreq>");
                oBuilder.AppendLine("</url>");
            }


            oBuilder.AppendLine("</urlset>");


            //var ms = new System.IO.MemoryStream(Encoding.ASCII.GetBytes(oBuilder.ToString()));
            //Response.AppendHeader("Content-Disposition", "inline;filename=sitemapindex.xml");
            //return new FileStreamResult(ms, "text/xml");

            return(Content(oBuilder.ToString(), "text/xml"));
        }