Пример #1
0
        public JsonResult LoginUser(User objUserModel)
        {
            ResponseModel objModel = new ResponseModel();

            try
            {
                if (ModelState.IsValid)
                {
                    LoginBAL objBAL     = new LoginBAL();
                    var      dataResult = objBAL.LoginUser(objUserModel);
                    if (dataResult != null)
                    {
                        Session["Role"]    = dataResult.Role_Id;
                        Session["User_ID"] = dataResult.User_ID;
                        objModel.Success   = true;
                        objModel.Message   = Convert.ToString(dataResult.Role_Id);
                    }
                    else
                    {
                        objModel.Success = false;
                        objModel.Message = "Invalid Username/Password";
                    }
                }
                else
                {
                    objModel.Success = false;
                    objModel.Message = string.Join("<br/> ", ModelState.Values
                                                   .SelectMany(x => x.Errors)
                                                   .Select(x => x.ErrorMessage));
                }
            }
            catch (Exception cc)
            {
                objModel.Success = false;
                objModel.Message = cc.Message.ToString();
            }

            return(Json(objModel));
        }