Exemple #1
0
        public virtual ActionResult Edit(Entity entity, FormCollection formCollection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Validator != null)
                    {
                        ValidationResult result = Validator.Validate(entity);

                        if (result.IsValid)
                        {
                            EntityService.SaveOrUpdate(entity);

                            return(RedirectToAction("Index", new { msg = "Proceso guardado exitosamente", TipoMensaje = TipoMensaje.Correcto }));
                        }
                        else
                        {
                            foreach (ValidationFailure failer in result.Errors)
                            {
                                ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
                            }
                        }
                    }
                    else
                    {
                        EntityService.SaveOrUpdate(entity);

                        return(RedirectToAction("Index", new { msg = "Proceso guardado exitosamente", TipoMensaje = TipoMensaje.Correcto }));
                    }
                }
            }
            catch (Exception ex)
            {
                var result = ManejadorExcepciones.HandleException(ex);
                ModelState.AddModelError("", result.Message);
            }


            var modelView = new FormModelView();

            modelView.Model = entity;

            var view     = ViewService.Get(typeof(Entity), typeof(Form));
            var formView = view.Layout as Form;

            modelView.View = formView;

            //3. Metadata
            modelView.Metadata = GenerateMetadataView.Generate(formView, view.ModelType);

            return(View(modelView));
        }
Exemple #2
0
        /// <summary>
        /// Generic Create
        /// </summary>
        /// <returns></returns>
        public virtual ActionResult Create()
        {
            var modelView = new FormModelView();
            //1. View
            var view     = ViewService.Get(typeof(Entity), typeof(Form));
            var formView = view.Layout as Form;

            modelView.View = formView;

            //2. Model
            modelView.Model = Initialize(CreateObject.CreateInstance <Entity>());

            //3. Metadata
            modelView.Metadata = GenerateMetadataView.Generate(formView, view.ModelType);



            return(View(modelView));
        }
Exemple #3
0
        /// <summary>
        /// Generic Edit
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult Edit(int?id)
        {
            //TODO: Si la vista (tree) no tiene la opcion edit, permitir editar??

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var entity = EntityService.Get(id.Value);

            if (entity == null)
            {
                var msg = string.Format("El Registro de {0} con identificacion {1} no existe, o sus datos asociados no existen",
                                        typeof(Entity).GetDescription(), id.Value);

                return(HttpNotFound(msg));
            }


            //Verificar si se puede eliminar.
            var check = CanEdited(entity);

            if (!check.Item1)
            {
                return(RedirectToAction("Index", new { msg = string.Format("El registro no se puede editar : {0}", check.Item2), TipoMensaje = TipoMensaje.Alerta }));
            }

            var modelView = new FormModelView();

            modelView.Model = entity;

            var view     = ViewService.Get(typeof(Entity), typeof(Form));
            var formView = view.Layout as Form;

            modelView.View = formView;

            //3. Metadata
            modelView.Metadata = GenerateMetadataView.Generate(formView, view.ModelType);

            return(View(modelView));
        }