Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Create(Gasto model)
        {
            var result = new AjaxResult();

            try
            {
                Controllers.Seguridad.Seguridad seguridad = new Controllers.Seguridad.Seguridad();
                model.GastoId       = seguridad.generaConsecutivo("Gastos");
                model.GastoLinea    = 1;
                model.GastoFecha    = DateTime.Today;
                model.GastoFechaMod = DateTime.Today;
                model.GastoValor    = Decimal.Parse(model.GastoValor.ToString().Replace(".", ","));
                if (ModelState.IsValid)
                {
                    db.Gasto.Add(model);
                    await db.SaveChangesAsync();

                    AddLog("", model.GastoId, model);

                    return(Ok(result.True("Record saved")));
                }
                else
                {
                    //return InternalServerError(new Exception("Error, All field are required"));
                    string s = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                    return(Ok(result.False(s)));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> RolAplicaciones(RolAplicacionViewModel model)
        {
            try
            {
                if (await DeleteRolAplicaciones(model.rol.RolId))
                {
                    foreach (var apps in model.aplicaciones)
                    {
                        if (apps.Seleccionado)
                        {
                            db.RolAplicaciones.Add(new RolAplicacion {
                                RolId = model.rol.RolId, AplicacionId = apps.Id
                            });
                        }
                    }
                }

                await db.SaveChangesAsync();


                //Inserta Auditoria
                Controllers.Seguridad.Seguridad seguridad = new Controllers.Seguridad.Seguridad();
                Auditoria    auditoria    = new Auditoria();
                Seguridadcll seguridadcll = (Seguridadcll)HttpContext.Current.Session["seguridad"];

                auditoria.AuditoriaFecha  = System.DateTime.Now;
                auditoria.AuditoriaHora   = System.DateTime.Now.TimeOfDay;
                auditoria.usuarioId       = seguridadcll.Usuario.UsuarioId;
                auditoria.AuditoriaEvento = "Add_Apps";
                auditoria.AuditoriaDesc   = "Add_Apps : " + model.rol.RolId;
                auditoria.ObjetoId        = "Roles/RolAplicaciones";

                seguridad.insertAuditoria(auditoria);
                //Inserta Auditoria

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }