Example #1
0
        public ActionResult Crear(RegataViewModel regataVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Regata.Negocio.Regata regata = regataVM.Mapear();
                    new RegataRepositorio().Guardar(regata);
                    //Inicializador.regatas.Add(regata);
                }
                catch (Exception ex)
                {

                }   
            }
            return RedirectToAction("Index");
        }     
Example #2
0
        public ActionResult Editar(RegataViewModel regataVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Regata.Negocio.Regata regata = regataVM.Mapear();
                    Regata.Negocio.Regata indice = new RegataRepositorio().ObtenerPorNombre(regataVM.NombreAnterior).FirstOrDefault();
                    if (indice !=null)
                    {
                        regata.RegatasClase = indice.RegatasClase;
                        new RegataRepositorio().Eliminar(indice);
                        //Inicializador.regatas.Remove(indice);
                    }
                    foreach (var clase in regataVM.ListaClases)
                    {
                        Clase oClase = Inicializador.clases.Find(c2 => c2.Nombre == clase.Nombre);
                        if (clase.Seleccionado)
                        {
                            if (!regata.Clases.Exists(c => c.Nombre == clase.Nombre))
                            {
                                regata.RegatasClase.Add(oClase, new RegataClase(oClase));
                            }
                        }
                        else if(regata.Clases.Exists(c => c.Nombre == clase.Nombre))
                        {
                            regata.RegatasClase.Remove(oClase);
                        }
                    }
                    Inicializador.regatas.Add(regata);
                }
                catch (Exception ex)
                {

                }
            }
            return RedirectToAction("Index");
        }