Ejemplo n.º 1
0
 // GET: Requests
 public ActionResult Index()
 {
     var id = Session["userID"];
     if (id == null)
     {
         return RedirectToAction("Login", "AccountController");
     }
     ViewBag.currentUser = (string)id;
     ViewBag.myRequests = false;
     //var requests = db.Requests.Where(r => r.UserId ==);
     RequestViewModel model = new RequestViewModel(db.Requests.ToList());
     return View(model);
 }
Ejemplo n.º 2
0
        // GET: Requests
        public ActionResult MyRequests()
        {
            var id = Session["userID"];
            if (id == null)
            {
                return RedirectToAction("Login", "AccountController");
            }
            ViewBag.currentUser = (string)id;
            ViewBag.myRequests = true;

            RequestViewModel model = new RequestViewModel(db.UserInfo.Find(id).requests);

            return View("Index", model);
        }
Ejemplo n.º 3
0
        public ActionResult FilterResult(
            FormCollection collection)
        {
            Request request = new Request();
            request.AmountMax = double.Parse(collection["Query.AmountMax"]);
            request.AmountMin = double.Parse(collection["Query.AmountMin"]);
            request.CloseToZipcode = int.Parse(collection["Query.CloseToZipcode"]);
            request.Currency = (CurrencyType)Enum.Parse(typeof(CurrencyType), collection["Query.Currency"]);
            request.CompanyDomain = collection["Query.CompanyDomain"];

            if (ModelState.IsValid)
            {
                var userId = Session["userID"];
                if (userId == null)
                {
                    return RedirectToAction("Login", "AccountController");
                }
                var query = db.Requests.Where(r =>
                    r.Currency == request.Currency &&
                    !(r.AmountMax < request.AmountMin || r.AmountMin > request.AmountMax));
                if (request.CompanyDomain != null)
                {
                    query = query.Where(r => r.UserId.Contains(request.CompanyDomain));
                }
                if (request.CloseToZipcode != 0)
                {
                    query = query.Where(r => Math.Abs(r.User.Zip - request.CloseToZipcode) < 100);
                }

                ViewBag.myRequests = false;
                ViewBag.currentUser = (string)userId;
                RequestViewModel model = new RequestViewModel(query.ToList(), request);
                return View("Index", model);
            }

            return View(request);
        }