public List <ListUserOutputModel> EnabledDisabledUser(UserEnableDisabledInputModel data) { UserRepository userRepo = new UserRepository(db); bool isActive = false; if (data.IsActive) { isActive = false; } else { isActive = true; } var res = userRepo.EnableDisabled(data.CurrentUserIDLogin, data.UserID, isActive); List <ListUserOutputModel> newList = new List <ListUserOutputModel>(); if (res.Result) { ListUserInputModel input = new ListUserInputModel(); input.PageNumber = 1; input.PageSize = 5; newList = GetListUser(input); } return(newList); }
// 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"); } }
public JsonResult GetUser(DataTableAjaxPostModel model) { int filteredResultsCount = 0; int totalResultsCount = 0; List <ListUserOutputModel> user = new List <ListUserOutputModel>(); 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 userTask = client.PostAsync("GetUserList", null); // userTask.Wait(); // var results = userTask.Result; // if (results.IsSuccessStatusCode) // { // var content = results.Content.ReadAsStringAsync(); // ListUserResponseModel userResponse = JsonConvert.DeserializeObject<ListUserResponseModel>(content.Result); // user = userResponse.data.OrderBy(x => x.UserID).ToList(); // } // else // { // user = null; // ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); // } } var result = new List <JsonUser>(); foreach (var x in user) { result.Add(new JsonUser { UserID = x.UserID, FirstName = x.FirstName.ToString(), LastName = x.LastName.ToString() }); } totalResultsCount = result.Count(); return(Json(new { draw = model.draw, recordsTotal = totalResultsCount, recordsFiltered = filteredResultsCount, data = result })); }
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); } }
public List <ListUserOutputModel> GetListUser(ListUserInputModel data) { var baseQuery = (from u in db.User join ur in db.UserRole on u.ID equals ur.UserID join r in db.Role on ur.RoleID equals r.ID from c in db.Company.Where(x => x.UserID == u.ID).DefaultIfEmpty() select new ListUserOutputModel { UserID = u.ID, CompanyName = c.CompanyName, FirstName = u.FirstName, LastName = u.LastName, UserName = u.UserName, RoleID = r.ID, RoleName = r.NormalizedName, IsActive = u.IsActive, Address = c.Alamat, Website = c.Website, EmailPerusahaan = c.Email, Kategory = c.Kategory, NPWP = c.NPWP, Note = c.Note, CompanyPhone = u.PhoneNumber, }); if (data.UserName != null && data.UserName != string.Empty) { baseQuery = (from fu in baseQuery where fu.UserName.Contains(data.UserName) select new ListUserOutputModel { UserID = fu.UserID, CompanyName = fu.CompanyName, FirstName = fu.FirstName, LastName = fu.LastName, UserName = fu.UserName, RoleID = fu.RoleID, RoleName = fu.RoleName, IsActive = fu.IsActive, Address = fu.Address, Website = fu.Website, EmailPerusahaan = fu.EmailPerusahaan, Kategory = fu.Kategory, NPWP = fu.NPWP, Note = fu.Note, CompanyPhone = fu.CompanyPhone, }); } if (data.CompanyName != null && data.CompanyName != string.Empty) { baseQuery = (from fu in baseQuery where fu.CompanyName.Contains(data.CompanyName) select new ListUserOutputModel { UserID = fu.UserID, CompanyName = fu.CompanyName, FirstName = fu.FirstName, LastName = fu.LastName, UserName = fu.UserName, RoleID = fu.RoleID, RoleName = fu.RoleName, IsActive = fu.IsActive, Address = fu.Address, Website = fu.Website, EmailPerusahaan = fu.EmailPerusahaan, Kategory = fu.Kategory, NPWP = fu.NPWP, Note = fu.Note, CompanyPhone = fu.CompanyPhone, }); } if (data.RoleName != null && data.RoleName != string.Empty) { baseQuery = (from fu in baseQuery where fu.RoleName.Contains(data.RoleName) select new ListUserOutputModel { UserID = fu.UserID, CompanyName = fu.CompanyName, FirstName = fu.FirstName, LastName = fu.LastName, UserName = fu.UserName, RoleID = fu.RoleID, RoleName = fu.RoleName, IsActive = fu.IsActive, Address = fu.Address, Website = fu.Website, EmailPerusahaan = fu.EmailPerusahaan, Kategory = fu.Kategory, NPWP = fu.NPWP, Note = fu.Note, CompanyPhone = fu.CompanyPhone, }); } if (data.PageSize == 0) { data.PageSize = 5; } if (data.PageNumber == 0) { data.PageNumber = 1; } int pageNumber = data.PageNumber - 1; baseQuery = baseQuery.Skip(pageNumber * data.PageSize).Take(data.PageSize); return(baseQuery.ToList()); }