public ActionResult Index(HomeViewModel model) { var tempSearchString = model.SearchString; CreateModel(ref model); ViewBag.SearchString = tempSearchString; return View(model); }
public ActionResult Index() { // construct HTTP REST client, configured with Basic authentication var client = new RestSharp.RestClient(vsoBaseUrl) { Authenticator = new HttpBasicAuthenticator( Security.Authentication.Username, Security.Authentication.Password) }; // construct query for top 10 (most recent) changesets var request = new RestRequest("tfvc/changesets", Method.GET); request.AddQueryParameter("api-version", "1.0"); request.AddQueryParameter("$top", "10"); // execute query and parse into strongly-typed viewModel var response = client.Execute(request); var model = new HomeViewModel() { ChangesetResult = JsonConvert.DeserializeObject<ChangesetResult>(response.Content) }; return View(model); }
private void ModelAndUserIdSetUp(ref HomeViewModel model, int id) { if (!HomeViewModelSessionExist() && !UserIdSessionExist()) { SetUserId(id); SetHomeViewModel(out model, id); } else if (!HomeViewModelSessionExist() && UserIdSessionExist() && ((id == -1 && UserIdSession != -1) || (id != -1 && UserIdSession != id))) { if (UserIdSession != -1) SetId(out id); else if (UserIdSession != id) SetUserId(id); SetHomeViewModel(out model, id); } else if (HomeViewModelSessionExist() && !UserIdSessionExist()) { SetHomeViewModelAs(out model, id); SetUserId(model.CustomerId); } else if (HomeViewModelSessionExist() && UserIdSessionExist()) { SetHomeViewModelAs(out model, id); if (id == -1) { if (UserIdSession != -1) SetId(out id); model.CustomerId = id; } else { if (UserIdSession != id) SetUserId(id); if (model.CustomerId <= 0) model.CustomerId = UserIdSession; } } }
private void CreateModel(ref HomeViewModel model, int id = -1) { ModelAndUserIdSetUp(ref model, id); SetContentInModel(model); }
private void SetModelProducts(HomeViewModel model, IEnumerable<IProduct> products, IEnumerable<IProductsCustomers> productsCustomers) { var innerJoinQuery = from prod in products join prodCust in productsCustomers on prod.Id equals prodCust.ProductId where prodCust.Count > 0 orderby prod.Id descending select prod; model.Products = new List<IProduct>(); foreach (var product in innerJoinQuery) model.Products.Add(product); }
private void SetModelPopularProducts(HomeViewModel model) { var innerJoinQuery = _dataManager.Products.GetPopularProducts(); var joinQuery = innerJoinQuery.Distinct(); model.PopularProducts = new List<IProduct>(); try { foreach (var product in joinQuery) model.PopularProducts.Add(product); } catch (Exception) {} }
private void SetHomeViewModelAs(out HomeViewModel model, int id) { model = Session["HomeViewModel"] as HomeViewModel ?? new HomeViewModel { CustomerId = id }; }
private void SetHomeViewModel(out HomeViewModel model, int id) { model = new HomeViewModel {CustomerId = id}; Session["HomeViewModel"] = model; }
private void SetContentInModel(HomeViewModel model) { var productsCustomers = _dataManager.ProductsCustomers.GetProductsCustomers(); var products = _dataManager.Products.GetProducts(); var orders = _dataManager.Orders.GetOrders(); if (productsCustomers != null && products != null) { SetModelProducts(model, products, productsCustomers); if (orders != null) SetModelPopularProducts(model); } }