コード例 #1
0
 public IdiomaController()
 {
     repositorio = new IdiomaRepositorio();
 }
コード例 #2
0
        public ActionResult Create(Publicacion p,FormCollection collection)
        {
            //Empresa
            var nombreEmpresa = collection[0];
            var repoEmp = new EmpresaRepositorio();
            var listaEmp = repoEmp.GetAll();
            foreach (var empresa in listaEmp.Where(empresa => empresa.Nombre == nombreEmpresa))
            {
                p.IdEmpresa = empresa.IdEmpresa;
            }
            if (String.IsNullOrEmpty(nombreEmpresa) || p.IdEmpresa == 0)
            {
                ModelState.AddModelError("NombreE", "Nombre Empresa es Necesario");
                return View(p);
            }
            if (String.IsNullOrEmpty(p.Pais) || p.Pais.CompareTo("--Seleccione--")==0)
            {
                ModelState.AddModelError("Pais", "Pais es Necesario");
                return View(p);
            }
            if (String.IsNullOrEmpty(p.Estado) || p.Estado.CompareTo("--Seleccione--") == 0)
            {
                ModelState.AddModelError("Estado", "Estado es Necesario");
                return View(p);
            }
            if (String.IsNullOrEmpty(p.Ciudad) || p.Ciudad.CompareTo("--Seleccione--") == 0)
            {
                ModelState.AddModelError("Ciudad", "Ciudad es Necesario");
                return View(p);
            }

            //fin Empresa
            //Sub Categoria
            var repoSub = new SubCategoriumRepositorio();
            var listaSub = repoSub.GetAll();
            var subCategorias = p.SubCategorium.Nombre.Split('-');
            var subCategoria = "";
            subCategoria = subCategorias[1].Substring(1);
            p.SubCategorium = new SubCategorium();
            foreach (var subCategorium in listaSub.Where(subCategorium => subCategorium.Nombre == subCategoria))
            {
                p.IdSubCategoria = subCategorium.IdSubCategoria;
            }
            //fin Sub Categoria
            var repoPubli = new PublicacionRepositorio();
            IList<Idioma> myIdiomas = p.Idioma;
            p.Idioma = null;
            var repoLug = new LugarRepositorio();
            p.Ciudad = repoLug.GetById(Convert.ToInt32(p.Ciudad)).Nombre;
            p.Estado = repoLug.GetById(Convert.ToInt32(p.Estado)).Nombre;
            var idPublicacion = repoPubli.Save(p);

            //Precios
            IList<Precio> listaPrecios = p.Precios;
            var repoPrecios = new PrecioRepositorio();
            foreach (var precio in listaPrecios)
            {
                precio.IdPublicacion = idPublicacion;
                repoPrecios.Save(precio);
            }

            //fin Precios
            p.Idioma = myIdiomas;
            //Servicios
            if (p.Servicios != null){
                var misServicios = new List<Servicio>(p.Servicios);
                foreach (var misServicio in misServicios)
                {
                    if (misServicio.IdServicio == 0) continue;
                    var pB = new PublicacionServicio
                                 {
                                     IdPublicacion = idPublicacion,
                                     IdServicio = misServicio.IdServicio
                                 };
                    var repoPubSer = new PublicacionServicioRepositorio();
                    repoPubSer.Save(pB);
                }
            }

            //fin Servicios
            //Idioma
            var repoIdioma = new IdiomaRepositorio();
            var idioma = p.Idioma[0];
            idioma.IdPublicacion = idPublicacion;
            if(p.Idioma[0].Categoria != "Otra")
            {
                p.Idioma[0].Categoria.Substring(0, 1);
               repoIdioma.Save(idioma);
            }
            else
            {
                idioma.Categoria = p.Idioma[1].Categoria;
                repoIdioma.Save(idioma);
            }
            //fin Idioma
            //Session para las fotos
            Session["IdPublicacion"] = idPublicacion;

               return RedirectToAction("Upload");
        }
コード例 #3
0
        public ActionResult Edit(int id)
        {
            var repoPubli = new PublicacionRepositorio();
            var repoIdioma = new IdiomaRepositorio();
            var repoSer = new ServicioRepositorio();
            var publi = repoPubli.GetById(id);
            var servicios = repoSer.GetAll();
            var itemsCategoria = new List<string>();
            var itemsCategoria2 = new List<string>();
            foreach (var servicio in servicios)
            {
                if(servicio.Idioma.CompareTo("es-MX")==0){
                    itemsCategoria.Add(servicio.Nombre);
                    itemsCategoria2.Add(servicio.IdServicio.ToString());
                }
            }

            ViewData["Servicios-Es"] = itemsCategoria;
            ViewData["Servicios-Es-id"] = itemsCategoria2;

            itemsCategoria = new List<string>();
            itemsCategoria2 = new List<string>();
            foreach (var servicio in servicios)
            {
                if (servicio.Idioma.CompareTo("en-US") == 0){
                    itemsCategoria.Add(servicio.Nombre);
                    itemsCategoria2.Add(servicio.IdServicio.ToString());
                }
            }

            ViewData["Servicios-En"] = itemsCategoria;
            ViewData["Servicios-En-id"] = itemsCategoria2;

            var repoServiPubli = new PublicacionServicioRepositorio();
            var listaSerPub = repoServiPubli.GetAll();
            var listaPubSer = new List<PublicacionServicio>();
            foreach (var publicacionServicio in listaSerPub)
            {
                if(publicacionServicio.IdPublicacion==publi.IdPublicacion)
                    listaPubSer.Add(publicacionServicio);
            }
            var listaSer= listaPubSer.Select(publicacionServicio => repoSer.GetById(publicacionServicio.IdServicio)).ToList();

            publi.Servicios = listaSer;
            var listIdioma = repoIdioma.GetAll();
            publi.Idioma=new List<Idioma>();
            foreach (var idioma in listIdioma.Where(idioma => idioma.IdPublicacion == publi.IdPublicacion))
            {
                publi.Idioma.Add(idioma);
            }

            var repoPrecios = new PrecioRepositorio();
            var listaPre = repoPrecios.GetAll();
            var listaPre2 = new List<Precio>();
            foreach (var precio in listaPre)
            {
                if(precio.IdPublicacion== publi.IdPublicacion)
                    listaPre2.Add(precio);
            }
            publi.Precios = listaPre2;
             /*   var repoImg = new ImageneRepositorio();
            var listaImg = repoImg.GetAll();
            var listaImg2 = new List<Imagene>();
            foreach (var imagene in listaImg)
            {
                if(imagene.IdPublicacion==id)
                    listaImg2.Add(imagene);
            }
            publi.Imagenes = listaImg2;*/
            return View(publi);
        }
コード例 #4
0
        public ActionResult Edit(Publicacion p, FormCollection collection)
        {
            int idPublicacion = p.IdPublicacion;
            //Precios
            IList<Precio> listaPrecios = p.Precios;
            var repoPrecios = new PrecioRepositorio();
            foreach (var precio in listaPrecios)
            {
                precio.IdPublicacion = idPublicacion;
                bool update = repoPrecios.Update(precio);
            }

            //fin Precios
            //Servicios

            var misServicios = new List<Servicio>(p.Servicios);
            var repoPubSer = new PublicacionServicioRepositorio();
            var repoSer = new ServicioRepositorio();
            var listaPubServ = repoPubSer.GetAll();
            bool flag = false;
            bool flag2 = false;
            foreach (var misServicio in misServicios)
            {
                if (misServicio.IdServicio != 0)
                {
                    foreach (var publicacionServicio in listaPubServ)
                    {
                        if(publicacionServicio.IdPublicacion==idPublicacion)
                        {
                            if(publicacionServicio.IdServicio==misServicio.IdServicio)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if(!flag)
                    {
                        var pB = new PublicacionServicio
                        {
                            IdPublicacion = idPublicacion,
                            IdServicio = misServicio.IdServicio

                        };
                        repoPubSer.Save(pB);
                    }
                    flag = false;
                }else
                {
                    foreach (var publicacionServicio in listaPubServ)
                    {
                        if (publicacionServicio.IdPublicacion == idPublicacion)
                        {
                            if (publicacionServicio.IdServicio==misServicio.FkIdServicio)
                            {
                                flag2 = true;
                                misServicio.IdServicio = publicacionServicio.IdServicio;
                                break;
                            }
                        }
                    }
                    if (flag2)
                    {
                        var pB = new PublicacionServicio
                        {
                            IdPublicacion = idPublicacion,
                            IdServicio = misServicio.IdServicio

                        };
                        repoPubSer.Delete(pB);
                    }
                    flag2 = false;

                }

            }
            Idioma i = p.Idioma[0];
            var repoIdioma = new IdiomaRepositorio();
            i.IdPublicacion = p.IdPublicacion;
            repoIdioma.Update(i);

            var repoPubli = new PublicacionRepositorio();
            var b = repoPubli.Update(p);
            Session["IdPublicacion"] = idPublicacion;
            return RedirectToAction("EditForPublicacion","Imagene", new {idPubli = idPublicacion});
        }
コード例 #5
0
        //
        // GET: /Publicacion/Details/5
        public ActionResult Details(int id)
        {
            var myRepoPublicacion = new PublicacionRepositorio();
            var myRepoImagene = new ImageneRepositorio();
            var myRepoServicioP = new PublicacionServicioRepositorio();
            var myRepoCat = new CategoriumRepositorio();
            var myRepoSubCat = new SubCategoriumRepositorio();
            var myRepoEmpresa = new EmpresaRepositorio();
            var myRepoServicio = new ServicioRepositorio();
            var myRepoIdioma = new IdiomaRepositorio();
            var myRepoPrecio = new PrecioRepositorio();
            var p = myRepoPublicacion.GetById(id);
            if (p != null)
            {
                var listaImagenes = myRepoImagene.GetAll();
                var listaImagenesAux = listaImagenes.Where(imagene => imagene.IdPublicacion == id).ToList();
                p.Imagenes = listaImagenesAux;
                var listaIdioma = myRepoIdioma.GetAll();
                if (listaIdioma!=null)
                {
                    p.Idioma = new List<Idioma>();
                    foreach (var idioma in listaIdioma.Where(idioma => idioma.IdPublicacion == id))
                    {
                        p.Idioma.Add(idioma);
                    }
                }

                var listaServicio = myRepoServicioP.GetAll();
                if (listaServicio != null)
                {
                    p.Servicios = new List<Servicio>();
                    foreach (var servicio in listaServicio.Where(servicio => servicio.IdPublicacion == id))
                    {
                        p.Servicios.Add(myRepoServicio.GetById(servicio.IdServicio));
                    }
                }
                p.Empresa = myRepoEmpresa.GetById(p.IdEmpresa);
                p.SubCategorium = myRepoSubCat.GetById(p.IdSubCategoria);
                p.Categorium = myRepoCat.GetById(p.SubCategorium.IdCategoria);
                var listaPrecios = myRepoPrecio.GetAll();
                p.Precios = listaPrecios.Where(listaPrecio => listaPrecio.IdPublicacion == id).ToList();
                p.Reservacion = p.Reservacion == "S" ? "Si" : "No";
                if (p.Idioma[0].Categoria.CompareTo("1 Estrella") == 0 || p.Idioma[0].Categoria.CompareTo("2 Estrellas") == 0 || p.Idioma[0].Categoria.CompareTo("3 Estrellas") == 0 || p.Idioma[0].Categoria.CompareTo("4 Estrellas") == 0 || p.Idioma[0].Categoria.CompareTo("5 Estrellas") == 0)
                {
                    p.Idioma[0].Categoria = p.Idioma[0].Categoria.Substring(0, 1);

                }else
                {
                    p.Idioma.Add(new Idioma { Categoria = p.Idioma[0].Categoria });
                    p.Idioma[0].Categoria = "0";
                }

                return View(p);
            }
            return RedirectToAction("Index");
        }