コード例 #1
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                IEnumerable <ListUserOutputModel> users = null;
                if (TempData["CustomError"] != null)
                {
                    ModelState.AddModelError(string.Empty, TempData["CustomError"].ToString());
                }
                else
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(BaseAPI + "Admin/");
                        ListUserInputModel filter = new ListUserInputModel();
                        filter.UserName    = "";
                        filter.CompanyName = "";
                        filter.RoleName    = "";
                        filter.PageNumber  = 1;
                        filter.PageSize    = 1000;
                        var responseTask = client.PostAsJsonAsync <ListUserInputModel>("GetUserList", filter);
                        responseTask.Wait();

                        var result = responseTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var content = result.Content.ReadAsStringAsync();
                            ListUserResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <ListUserResponseModel>(content.Result);
                            users = resutl.data;
                        }
                        else                         //web api sent error response
                        {
                            //log response status here..
                            users = Enumerable.Empty <ListUserOutputModel>();
                            ModelState.AddModelError(string.Empty, "Fail to get data. Please contact administrator.");
                        }
                    }
                }
                return(View(users));
            }
            else
            {
                TempData["CustomError"] = "Please login before using the web.";
                if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                {
                    return(RedirectToAction("AdminLogon", "Login"));
                }
                else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                {
                    return(RedirectToAction("OwnerLogon", "Login"));
                }
                else
                {
                    return(RedirectToAction("BuyerLogon", "Login"));
                }
                //return RedirectToAction("Logon", "Login");
            }
        }
コード例 #2
0
        public ActionResult <ListUserResponseModel> GetUserList([FromBody] ListUserInputModel data)
        {
            ListUserResponseModel res = new ListUserResponseModel();

            try
            {
                UserBL bl   = new UserBL(DbContext);
                var    temp = bl.GetListUser(data);

                res.data     = temp;
                res.Message  = "Success";
                res.Response = true;

                return(res);
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;

                return(res);
            }
        }