Example #1
0
        /// <summary>
        /// Busca informacion basica minima de un usuario Con sus accesos.
        /// Se puede buscar Usuario por IdUser o por IdPerson
        /// </summary>
        /// <param optional name="IdUser"></param> <param optional name="Status"></param> <param optional name="IdPerson"></param>
        /// <returns>Objeto de tipo MUser</returns>
        public static MSerUser fnSearchUserSession(int?IdUser = null, bool?Status = null, int?IdPerson = null)
        {
            MSerUser objMUser        = new MSerUser();
            MMEnterprisesEntities db = new MMEnterprisesEntities();

            objMUser = (from result in db.GNListUser(IdUser, Status, IdPerson).ToList()
                        select new MSerUser
            {
                IdUser = result.IdUser,
                Login = result.Login,
                PersonEmployee = (MSerPerson)(from result2 in db.GNListPerson(result.IdPerson, 2, null, null, null).ToList()
                                              select new MSerPerson
                {
                    IdPerson = result2.IdPerson,
                    Name = result2.Name,
                    LastName = result2.LastName,
                    Email = result2.Email
                }).ToList().First(),
                UserAcces = (from result3 in db.GNListRoleUserPermission(result.IdUser, null).ToList()
                             select new MSerAcces
                {
                    IdOption = result3.IdOption,
                    OptionName = result3.OptionName,
                    Visible = result3.Visible == null ? false : (bool)result3.Visible,
                    Create = result3.Create == null ? false : (bool)result3.Create,
                    Search = result3.Search == null ? false : (bool)result3.Search,
                    Edit = result3.Edit == null ? false : (bool)result3.Edit,
                    Delete = result3.Edit == null ? false : (bool)result3.Delete,
                    IdAssociated = result3.IdAssociated,
                    Action = result3.Action,
                    Controller = result3.Controller
                }).ToList(),

                UserAccesPadre = (from result3 in db.GNListRoleUserPermission(null, null).ToList()
                                  select new MSerAcces
                {
                    IdOption = result3.IdOption,
                    OptionName = result3.OptionName,
                    Visible = result3.Visible == null ? false : (bool)result3.Visible,
                    Create = result3.Create == null ? false : (bool)result3.Create,
                    Search = result3.Search == null ? false : (bool)result3.Search,
                    Edit = result3.Edit == null ? false : (bool)result3.Edit,
                    Delete = result3.Edit == null ? false : (bool)result3.Delete,
                    IdAssociated = result3.IdAssociated,
                    Action = result3.Action,
                    Controller = result3.Controller
                }).ToList()
            }).First();

            return(objMUser);
        }
Example #2
0
        public ActionResult Login(MUser objUser)
        {
            //Session.Timeout = 30; //Se coloco en el web config
            try
            {
                //objUser.IdPerson = 1;

                if (string.IsNullOrEmpty(objUser.Login) || string.IsNullOrEmpty(objUser.Password))
                {
                    return(View(objUser));
                }

                MMEnterprisesEntities db = new MMEnterprisesEntities();
                MUser OUser = new MUser();

                int SqlResult;

                SqlParameter paramOutIdUsuario = new SqlParameter();
                paramOutIdUsuario.ParameterName = "@IdUser";
                paramOutIdUsuario.SqlDbType     = System.Data.SqlDbType.Int;
                paramOutIdUsuario.Direction     = System.Data.ParameterDirection.Output;
                paramOutIdUsuario.Value         = objUser.IdUser;

                SqlResult = db.Database.ExecuteSqlCommand("GNAuthenticationUser @strLogin, @strPassword, @IdUser OUT ",
                                                          new SqlParameter[] {
                    new SqlParameter("@strLogin", objUser.Login),
                    new SqlParameter("@strPassword", OUser.Encriptar(objUser.Password)),
                    paramOutIdUsuario
                }
                                                          );

                if (SqlResult != 0)
                {
                    int IdUser = Int32.Parse(paramOutIdUsuario.Value.ToString());
                    if (IdUser != 0)
                    {
                        MSerUser ObjUser = new MSerUser();

                        ObjUser = fnSearchUserSession(IdUser);

                        Session["Usuario"] = ObjUser;

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.ErrorSave = "Error al Autenticar";
                        return(View(objUser));
                    }
                }
                else
                {
                    ViewBag.ErrorSave = "Error al Autenticar";
                    return(View(objUser));
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorSave = e.Message;
                return(View(objUser));
            }
        }