// GET: MENU_SUB/Create
        public ActionResult Create()
        {
            using (ODAO Menu = new ODAO())
            {
                ViewBag.SUB = new SelectList(Menu.MENU.Include("TIPO_ROL").ToList(), "MENU_ID", "TEXTO", "TIPO_ROL.NOMBRE_ROL", 1);
            }

            ViewBag.MENU_ID_P = new SelectList(db.MENU, "MENU_ID", "TEXTO", "");
            ViewBag.ID_ROL    = new SelectList(db.TIPO_ROL, "ID_ROL", "NOMBRE_ROL");
            return(View());
        }
示例#2
0
        public ActionResult Login(USUARIOS _login)
        {
            try
            {
                TIPO_ROL Rol = new TIPO_ROL();
                using (ODAO Menu = new ODAO())
                {
                    ViewBag.Rol = new SelectList(Menu.TIPO_ROL.ToList(), "ID_ROL", "NOMBRE_ROL", "CATEGORIA", 1);
                }

                if (ModelState.IsValid) //validating the user inputs
                {
                    string cualquira = Request["LoginType"];
                    string hash      = ConfigurationManager.AppSettings["Encryption"];
                    bool   isExist   = false;

                    _login.TIMESTAMP = DateTime.Now;

                    _login.IP = System.Web.HttpContext.Current.Request.UserHostAddress;

                    if (cualquira != null)
                    {
                        switch (Request["LoginType"].ToString())
                        {
                        case ("Login"):
                            using (ODAO _entity = new ODAO())      // out Entity name is "SampleMenuMasterDBEntites"
                            {
                                string passEncriptado = Encrypt.EncryptString(_login.PASS, hash);
                                isExist = _entity.USUARIOS.Where(x => x.USER.Trim().ToLower() == _login.USER.Trim().ToLower() && x.PASS.ToString() == passEncriptado.ToString()).Any();     //validating the user name in tblLogin table whether the user name is exist or not
                                if (isExist)
                                {
                                    USUARIOS _loginCredentials = _entity.USUARIOS.Where(x => x.USER.Trim().ToLower() == _login.USER.Trim().ToLower()).FirstOrDefault(); // Get the login user details and bind it to LoginModels class

                                    FormsAuthentication.SetAuthCookie(_loginCredentials.USER, false);                                                                   // set the formauthentication cookie
                                    Session["LoginCredentials"] = _loginCredentials;                                                                                    // Bind the _logincredentials details to "LoginCredentials" session
                                    Session["MenuMaster"]       = db.MENU.Include("MENU_SUB").Where(w => w.ID_ROL == _loginCredentials.ID_ROL).ToList();                //Bind the _menus list to MenuMaster session
                                    Session["UserName"]         = _loginCredentials.USER;
                                    Session["Binary_File"]      = _login.BINARY_IMAGE;
                                    ViewBag.USUARIO_LOG         = _loginCredentials;


                                    var asd = _entity.ASISTENTES.Where(x => x.ID_USUARIO == _loginCredentials.ID_USUARIO).FirstOrDefault();

                                    if (_entity.CLIENTES.Where(x => x.ID_USUARIO == _loginCredentials.ID_USUARIO).FirstOrDefault() == null && _loginCredentials.ID_ROL == 41)
                                    {
                                        ViewBag.Message = "Debe Competar Su Perfil de Cliente";     // personas
                                        return(RedirectToAction("CompletarPerfil", "CLIENTES"));
                                    }
                                    else if (_entity.CLIENTES.Where(x => x.ID_USUARIO == _loginCredentials.ID_USUARIO).FirstOrDefault() == null && _loginCredentials.ID_ROL == 61)
                                    {
                                        ViewBag.Message = "Debe Competar Su Perfil de Cliente";    // empresas
                                        return(RedirectToAction("CompletarPerfil", "CLIENTES"));
                                    }
                                    else if (_entity.ASISTENTES.Where(x => x.ID_USUARIO == _loginCredentials.ID_USUARIO).FirstOrDefault() == null && _loginCredentials.ID_ROL != 41 && _loginCredentials.ID_ROL != 61)
                                    {
                                        ViewBag.Message = "Debe Competar Su Perfil de ASISTENTE";    // ASISTENTE
                                        return(RedirectToAction("CompletarPerfil", "ASISTENTES"));
                                    }
                                    else
                                    {
                                        if (_loginCredentials.ID_ROL == 41 | _loginCredentials.ID_ROL == 61)
                                        {
                                            Session["PerfilCliente"] = _entity.CLIENTES.Where(x => x.ID_USUARIO == _loginCredentials.ID_USUARIO).FirstOrDefault();
                                            return(RedirectToAction("Index", "CLIENTES"));
                                        }
                                        else
                                        {
                                            return(RedirectToAction("Index", "ASISTENTES"));
                                        }
                                    }
                                }
                                else
                                {
                                    ViewBag.Message = "Las credenciales no son validas!...";
                                    return(View());
                                }
                            }

                        case ("Register"):
                            using (ODAO _entity = new ODAO())
                            {
                                isExist = _entity.USUARIOS.Where(x => x.USER.Trim().ToLower() == _login.USER.Trim().ToLower()).Any();
                                if (isExist)
                                {
                                    ViewBag.Message = "Este usuario ya existe en nuestros sistemas";
                                    return(View());
                                }
                                else
                                {
                                    HttpPostedFileBase File = Request.Files["IMG_PROFILE"];
                                    _login.IMG_PROFILE  = File.FileName;
                                    _login.BINARY_IMAGE = ConvertToByte(File);
                                    _login.PASS         = Encrypt.EncryptString(_login.PASS.ToString(), hash);
                                    db.USUARIOS.Add(_login);
                                    db.SaveChanges();

                                    return(View());
                                }
                            }

                        default:
                            return(View());
                        }
                    }
                }

                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View());
            }
        }