Beispiel #1
0
        public ActionResult Ver(int id)
        {
            EmpleadoModel model = new EmpleadoModel();

            try
            {
                EmpleadoDAO CLDAO  = new EmpleadoDAO();
                var         entity = CLDAO.GetById(id, db);

                if (entity == null)
                {
                    return(RedirectToAction("Index"));
                }
                copiarEntidadmodelo(ref model, ref entity);
            }
            catch (Exception e)
            {
                LogUtil.ExceptionLog(e);
            }
            ViewBag.Editar = false;
            return(View(CREAR_EDITAR_ABSOLUTE_PATH, model));
        }
Beispiel #2
0
        public JsonResult Guardar(EmpleadoModel model)
        {
            var rm = new ResponseModel();

            if (!ModelState.IsValid)
            {
                rm.message  = "Hubo un problema verifique sus datos e intente de nuevo.";
                rm.message += ExtensionMethods.GetAllErrorsFromModelState(this);
                return(Json(rm, JsonRequestBehavior.AllowGet));
            }



            try
            {
                EmpleadoDAO dao    = new EmpleadoDAO();
                var         entity = dao.GetById(model.id, db);
                bool        nuevo  = false;

                if (entity == null)
                {
                    entity = new empleado();
                    entity.persona_fisica           = new persona_fisica();
                    entity.persona_fisica.direccion = new direccion();
                    nuevo = true;
                }
                //datos empleado
                entity.ID_AREA_TRABAJO = model.areaTrabajo;
                entity.PUESTO          = model.puesto;
                entity.FECHA_INGRESO   = (model.fechaIngreso != null && model.fechaIngreso != "") ? ExtensionMethods.ToDateFormat(model.fechaIngreso) : entity.FECHA_INGRESO;
                entity.FECHA_BAJA      = (model.fechaBaja != null && model.fechaBaja != "") ? ExtensionMethods.ToDateFormat(model.fechaBaja) : entity.FECHA_BAJA;
                entity.IMSS            = model.nss;
                entity.EMAIL           = model.correoEmpresa;
                entity.SALARIO         = ExtensionMethods.ConverToDecimalFormat(model.salario);
                entity.ACTIVO          = model.activo;

                if (model.areaTrabajo == 1)
                {
                    var tienda = db.tienda.Find(model.sucursal);
                    entity.tienda.Clear();
                    if (tienda != null)
                    {
                        entity.tienda.Add(tienda);
                    }
                }
                else
                {
                    entity.tienda.Clear();
                }
                if (model.activo == false && entity.AspNetUsers != null)
                {
                    AspNetUsers usuario = db.AspNetUsers.FirstOrDefault(m => m.PersonalId == entity.ID);
                    usuario.LockoutEnabled = false;
                }

                //datos persona
                entity.persona_fisica.NOMBRE           = model.nombre;
                entity.persona_fisica.APELLIDO_PATERNO = model.apellidoPaterno;
                entity.persona_fisica.APELLIDO_MATERNO = model.apellidoMaterno;
                entity.persona_fisica.FECHA_NACIMIENTO = ExtensionMethods.ToDateFormat(model.fechaNacimiento);
                entity.persona_fisica.CURP             = model.curp;
                entity.persona_fisica.RFC      = model.rfc;
                entity.persona_fisica.SEXO     = model.sexo;
                entity.persona_fisica.EMAIL    = model.correo;
                entity.persona_fisica.TELEFONO = model.telefono;
                entity.persona_fisica.CELULAR  = model.celular;

                //datos direccion
                entity.persona_fisica.direccion.CALLE        = model.calle;
                entity.persona_fisica.direccion.NUM_INTERIOR = model.numInterior;
                entity.persona_fisica.direccion.NUM_EXTERIOR = model.numExterior;
                entity.persona_fisica.direccion.COLONIA      = model.colonia;
                entity.persona_fisica.direccion.CIUDAD       = model.ciudad;
                entity.persona_fisica.direccion.MUNICIPIO    = model.municipio;
                entity.persona_fisica.direccion.CP           = model.codigoPostal;
                entity.persona_fisica.direccion.ID_ESTADO    = model.estado;
                entity.persona_fisica.direccion.ID_PAIS      = model.pais;


                if (nuevo)
                {
                    db.empleado.Add(entity);
                }


                if (db.SaveChanges() > 0 || db.Entry(entity).State == EntityState.Unchanged)
                {
                    rm.response = true;
                    rm.message  = "Sus datos se guardaron correctamente";
                    rm.href     = "Index";
                }
            }catch (Exception e)
            {
            }



            return(Json(rm, JsonRequestBehavior.AllowGet));
        }