Exemple #1
0
        public ActionResult Register(string identidad, string nombre, string Apellido, DateTime FechaNacimiento, string sexo, string Telefono, string correo, string password)
        {
            string UserName = nombre + Apellido;

            IEnumerable <object> listCategoria = null;
            string MensajeError = "";

            try
            {
                listCategoria = db.UDP_Acce_tbUsuario_Insert(UserName, password);


                foreach (UDP_Acce_tbUsuario_Insert_Result Resultado in listCategoria)
                {
                    MensajeError = Resultado.MensajeError;
                }
                if (MensajeError.StartsWith("-1"))
                {
                    ViewBag.Error("Error al registrase, contacte al administrador.");
                    return(View());
                }
                else
                {
                    tbCliente objCliente = new tbCliente();
                    objCliente.clte_Identidad       = identidad;
                    objCliente.clte_Nombre          = nombre;
                    objCliente.clte_Apellido        = Apellido;
                    objCliente.clte_FechaNacimiento = FechaNacimiento;
                    objCliente.clte_Sexo            = sexo;
                    objCliente.clte_Telefono        = Telefono;
                    objCliente.clte_Correo          = correo;
                    objCliente.usu_Id           = Convert.ToInt16(MensajeError);
                    objCliente.clte_UsuarioCrea = 3;
                    objCliente.clte_FechaCrea   = DateTime.Now;

                    db.tbCliente.Add(objCliente);
                    db.SaveChanges();

                    Usuario_Rol usuarioRol = new Usuario_Rol();
                    usuarioRol.id_Rol = 2;
                    usuarioRol.usu_Id = Convert.ToInt16(MensajeError);
                    db.Usuario_Rol.Add(usuarioRol);
                    db.SaveChanges();
                }
            }
            catch (Exception Ex)
            {
                ViewBag.Error = "Se produjo un error al registrar, contacte al administrador";
                return(View());
            }
            ViewBag.Message = "Usuario registrado correctamente, inicie sesión";
            return(RedirectToAction("Index"));
        }