public override void OnActionExecuting(ActionExecutingContext filterContext) { var token = HttpContext.Current.Session["token"]; if (token == null) { filterContext.Result = new RedirectToRouteResult(routeValuesRedirect()); return; } WSRequest request = new WSRequest("accounts/me"); request.AddAuthorization(token.ToString()); var response = request.Get(); if (response.Code != 200) { filterContext.Result = new RedirectToRouteResult(routeValuesRedirect()); return; } var body = response.Body; Models.ViewModels.UserViewModel user = new Models.ViewModels.UserViewModel { IdUser = (int)body.GetValue("id_user"), Email = body.GetValue("email").ToString(), Name = body.GetValue("name").ToString(), IdPlan = (int?)body.GetValue("id_plan"), Permission = (int)body.GetValue("permission") }; HttpContext.Current.Session["CurrentUser"] = user; }
public ActionResult Show(int idPlan) { WSRequest request = new WSRequest("plans/" + idPlan); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse plano" })); } var body = response.Body; //var js = new Newtonsoft.Json.JsonSerializer(); //var mod=js.Deserialize(new System.IO.StringReader(body.ToString()), typeof(PlanViewModel)); var model = new PlanViewModel { IdPlan = (int)body["id_plan"], Name = body["name"].ToString(), Left = (int)body["left"], Price_cents = (int)body["price_cents"], Rewards = body["rewards"].ToString(), }; return(View(model)); }
public ActionResult Index(int page = 1) { WSRequest request = new WSRequest("posts?page=" + page); var response = request.Get(); var model = new BlogViewModel { }; if (response.Code == 200) { var body = response.Body; model.Posts = new List <PostViewModel>(); foreach (var post in body.GetValue("posts")) { model.Posts.Add(new PostViewModel { IdPost = (int)post["id_post"], Title = post["title"].ToString(), Content = post["content"].ToString(), PublishedAt = post["published_at"].ToString(), IdUser = (int)post["id_user"], UserName = post["user_name"].ToString() }); } var pagination = body.GetValue("pagination"); model.Pagination = new PaginationViewModel { NextPage = (bool)pagination["next_page"], PreviousPage = (bool)pagination["previous_page"], CurrentPage = (int)pagination["current_page"], TotalNumberPages = (int)pagination["total_number_pages"], }; } return(View(model)); }
public ActionResult Edit(int idUser, int idDevice) { WSRequest request = new WSRequest("/users/" + idUser + "/devices/" + idDevice); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar o device" })); } var body = response.Body; var model = new DeviceViewModel { IdDevice = (int)body["id_device"], Alias = body["alias"].ToString(), Color = body["color"].ToString(), FrequencyUpdate = (int)body["frequency_update"], IdUser = (int)body["id_user"] }; return(View(model)); }
public ActionResult Show(int idComment, int idPost) { WSRequest request = new WSRequest("/posts/" + idPost + "/comments/" + idComment); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Comment", new { message = "Não foi possível exibir o comentário" })); } var body = response.Body; CommentViewModel model = new CommentViewModel { IdComment = idComment, IdPost = idPost, Content = body.GetValue("content").ToString(), CreatedAt = body.GetValue("created_at").ToString(), ApprovedAt = body.GetValue("approved_at").ToString() }; return(View(model)); }
public ActionResult Edit(int idPlan) { WSRequest request = new WSRequest("plans/" + idPlan); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { ModelState.AddModelError("", "Não foi possível buscar esse plano"); return(RedirectToAction("Index", "Plan")); } var body = response.Body; var model = new PlanViewModel { IdPlan = (int)body["id_plan"], Name = body["name"].ToString(), Left = (int)body["left"], Price_cents = (int)body["price_cents"], Rewards = body["rewards"].ToString(), }; return(View(model)); }
public ActionResult Index() { var user = (UserViewModel)Session["CurrentUser"]; if (user != null && user.Permission == 4) { WSRequest request = new WSRequest("plans/"); var response = request.Get(); if (response.Code != 200) { ModelState.AddModelError("", "Não foi possível buscar esse plano"); return(RedirectToAction("Index", "Home", "ERRO")); } var body = response.Body; List <PlanViewModel> list = new List <PlanViewModel>(); foreach (var item in body.GetValue("plans")) { list.Add( new PlanViewModel { IdPlan = (int)item["id_plan"], Left = (int)item["left"], Name = item["name"].ToString(), Price_cents = (int)item["price_cents"], Rewards = item["rewards"].ToString(), QntTotal = (int?)item["sold"] } ); } ViewBag.plans = list; } return(View()); }
public ActionResult Edit(int idUser) { WSRequest request = new WSRequest("users/" + idUser); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "User")); } var body = response.Body; var model = new UserViewModel { IdUser = (int)body["id_user"], Name = body["name"].ToString(), Email = body["email"].ToString(), Permission = (int)body["permission"], Address = body["address"].ToString(), District = body["district"].ToString(), City = body["city"].ToString(), State = body["state"].ToString(), ZipCode = body["zipcode"].ToString(), }; return(View(model)); }
public ActionResult Render(string key) { WSRequest request = new WSRequest("infos/" + key); var response = request.Get(); var body = response.Body; var info = new InformationViewModel { Key = body.GetValue("key").ToString(), Value = body.GetValue("value").ToString() }; return(View(info)); }
public ActionResult Index(int page = 1) { WSRequest request = new WSRequest("users/?page=" + page); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Show", "Profile")); } var body = response.Body; UserListViewModel model = new UserListViewModel(); var pagination = body.GetValue("pagination"); model.Pagination = new PaginationViewModel { NextPage = (bool)pagination["next_page"], PreviousPage = (bool)pagination["previous_page"], CurrentPage = (int)pagination["current_page"], TotalNumberPages = (int)pagination["total_number_pages"], }; model.Users = new List <UserViewModel>(); foreach (var user in body["users"]) { model.Users.Add( new UserViewModel { IdUser = (int)user["id_user"], Name = user["name"].ToString(), Email = user["email"].ToString(), Permission = (int)user["permission"], Address = user["address"].ToString(), District = user["district"].ToString(), City = user["city"].ToString(), State = user["state"].ToString(), ZipCode = user["zipcode"].ToString(), } ); } ; return(View(model)); }
public ActionResult Edit() { var user = ((UserViewModel)Session["CurrentUser"]); var request = new WSRequest("users/" + user.IdUser); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code == 200) { var userModel = response.Body.ToObject <UserViewModel>(); userModel.IdUser = (int)response.Body.GetValue("id_user"); return(View(userModel)); } return(View()); }
public ActionResult Index(int page = 1) { var user = (UserViewModel)Session["CurrentUser"]; WSRequest request = null; request = new WSRequest("/plans?page=" + page); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); ListViewModel <PlanViewModel> model = new ListViewModel <PlanViewModel>(); if (response.Code == 200) { var body = response.Body; var pagination = body.GetValue("pagination"); if (pagination != null) { model.Pagination = new PaginationViewModel { NextPage = (bool)pagination["next_page"], PreviousPage = (bool)pagination["previous_page"], CurrentPage = (int)pagination["current_page"], TotalNumberPages = (int)pagination["total_number_pages"], ControllerName = "Plan" }; } foreach (var plan in body["plans"]) { model.ListModel.Add( new PlanViewModel { IdPlan = (int)plan["id_plan"], Name = plan["name"].ToString(), Left = (int)plan["left"], Price_cents = (int)plan["price_cents"], Rewards = plan["rewards"].ToString(), } ); } ; } return(View(model)); }
public ActionResult Report(ReportViewModel filter) { var user = (UserViewModel)Session["CurrentUser"]; ListViewModel <ReportViewModel> model = new ListViewModel <ReportViewModel>(); model.Filter = filter; WSRequest request = null; request = new WSRequest("/plans/reports?id_plan=" + filter.IdPlan + "&id_plan2=" + filter.IdPlan + "&name=" + filter.Name + "&plan_left=" + filter.PlanLeft + "&plan_left2=" + filter.PlanLeft2 + "&plan_sold=" + filter.PlanSold + "&plan_sold2=" + filter.PlanSold2); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code == 200) { var body = response.Body; var report = body["report"]; foreach (var plan in report) { model.ListModel.Add( new ReportViewModel { IdPlan = (int)plan["id_plan"], Name = plan["name_plan"].ToString(), PlanLeft = (int)plan["plan_left"], PriceCents = (int)plan["price_cents"], PlanSold = (int)plan["plan_solds"], } ); } ; return(View(model)); } else { ModelState.AddModelError("", response.Code + " - " + response.Body["Message"]); return(View(model)); } }
public ActionResult Index(int page = 1) { var user = (UserViewModel)Session["CurrentUser"]; WSRequest request = new WSRequest("users/" + user.IdUser + "/posts/comments?page=" + page); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" })); } var body = response.Body; CommentListViewModel model = new CommentListViewModel(); var pagination = body.GetValue("pagination"); model.Pagination = new PaginationViewModel { NextPage = (bool)pagination["next_page"], PreviousPage = (bool)pagination["previous_page"], CurrentPage = (int)pagination["current_page"], TotalNumberPages = (int)pagination["total_number_pages"], }; model.Comments = new List <CommentViewModel>(); foreach (var comment in body.GetValue("comments")) { model.Comments.Add( new CommentViewModel { IdComment = (int)comment["id_comment"], IdPost = (int)comment["id_post"], Content = comment["content"].ToString(), IdUser = (int)comment["id_user"], ApprovedAt = comment["approved_at"].ToString(), CreatedAt = comment["created_at"].ToString() } ); } return(View(model)); }
public ActionResult Index(int page = 1) { WSRequest request = new WSRequest("devices/?page=" + page); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Profile", new { message = "Não foi possível buscar os devices" })); } var body = response.Body; DeviceListViewModel model = new DeviceListViewModel(); var pagination = body.GetValue("pagination"); model.Pagination = new PaginationViewModel { NextPage = (bool)pagination["next_page"], PreviousPage = (bool)pagination["previous_page"], CurrentPage = (int)pagination["current_page"], TotalNumberPages = (int)pagination["total_number_pages"], }; model.Devices = new List <DeviceViewModel>(); foreach (var device in body["devices"]) { model.Devices.Add(new DeviceViewModel { IdDevice = (int)device["id_device"], //Alarm = (bool)device["alarm"], Alias = device["alias"].ToString(), Color = device["color"].ToString(), FrequencyUpdate = (int)device["frequency_update"], IdUser = (int)device["id_user"] }); } ; return(View(model)); }
public ActionResult Edit(string key) { WSRequest request = new WSRequest("infos/" + key); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Information", new { message = "Não foi possível buscar esse post" })); } var body = response.Body; var info = new InformationViewModel { Key = body.GetValue("key").ToString(), Value = body.GetValue("value").ToString() }; return(View(info)); }
public ActionResult NewSponsor(int idPlan) { WSRequest request = new WSRequest("plans/" + idPlan); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { idPlan = idPlan, message = "Não foi possível buscar esse plano" })); } var body = response.Body; var model = new SponsorPlanViewModel { PlanName = body["name"].ToString(), QntLeft = (int)body["left"] }; return(View(model)); }
public ActionResult Edit(int idPost) { WSRequest request = new WSRequest("posts/" + idPost); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" })); } var body = response.Body; var model = new PostViewModel { Content = body["content"].ToString(), PublishedAt = body["published_at"].ToString(), IdPost = (int)body["id_post"], IdUser = (int)body["id_user"], Title = body["title"].ToString() }; return(View(model)); }
public ActionResult ShowPost(int idPost) { WSRequest request = new WSRequest("posts/" + idPost); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" })); } var body = response.Body; List <CommentViewModel> comments = new List <CommentViewModel>(); foreach (var comment in body["comments"]) { comments.Add( new CommentViewModel { IdPost = (int)comment["id_post"], Content = comment["content"].ToString(), UserName = comment["user_name"].ToString() } ); } var model = new PostViewModel { Content = body["content"].ToString(), PublishedAt = body["published_at"].ToString(), IdPost = (int)body["id_post"], IdUser = (int)body["id_user"], UserName = body["user_name"].ToString(), Title = body["title"].ToString(), Comments = comments }; return(View(model)); }
public ActionResult Index() { WSRequest request = new WSRequest("infos/"); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Information", new { message = "Não foi possível buscar esse post" })); } var body = response.Body.GetValue("infos"); var model = new List <InformationViewModel>(); foreach (var item in body) { model.Add(new InformationViewModel { Key = item["key"].ToString(), Value = item["value"].ToString() }); } return(View(model)); }
public ActionResult Show() { var user = ((UserViewModel)Session["CurrentUser"]); var request = new WSRequest("users/" + user.IdUser); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code == 200) { var userModel = response.Body.ToObject <UserViewModel>(); userModel.Plan = new PlanViewModel { }; if (userModel.Permission == 4 && userModel.IdPlan != null) { var PlanRequest = new WSRequest("plans/" + userModel.IdPlan); PlanRequest.AddAuthorization(Session["token"].ToString()); var PlanResponse = PlanRequest.Get(); if (PlanResponse.Code == 200) { var PBody = PlanResponse.Body; userModel.Plan = new PlanViewModel { Name = PBody.GetValue("name").ToString(), Price_cents = (int)PBody.GetValue("price_cents"), Rewards = PBody.GetValue("rewards").ToString() }; } } return(View(userModel)); } return(View()); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var token = HttpContext.Current.Session["token"]; if (token == null) { if (HttpContext.Current.Request.Cookies["qoala_token"] != null) { token = HttpContext.Current.Request.Cookies["qoala_token"].Value; HttpContext.Current.Session["token"] = token; WSRequest request = new WSRequest("accounts/me"); request.AddAuthorization(token.ToString()); var response = request.Get(); if (response.Code != 200) { HttpContext.Current.Session["token"] = null; HttpContext.Current.Session["CurrentUser"] = null; var cookie = new HttpCookie("qoala_token"); cookie.Expires = DateTime.Now.AddDays(-1d); HttpContext.Current.Response.Cookies.Add(cookie); return; } var body = response.Body; Models.ViewModels.UserViewModel user = new Models.ViewModels.UserViewModel { IdUser = (int)body.GetValue("id_user"), Email = body.GetValue("email").ToString(), Name = body.GetValue("name").ToString(), IdPlan = (int?)body.GetValue("id_plan"), Permission = (int)body.GetValue("permission") }; HttpContext.Current.Session["CurrentUser"] = user; } } else { if (HttpContext.Current.Request.Cookies["qoala_token"] != null) { token = HttpContext.Current.Request.Cookies["qoala_token"].Value; } else { token = HttpContext.Current.Session["token"].ToString(); } WSRequest request = new WSRequest("accounts/me"); request.AddAuthorization(token.ToString()); var response = request.Get(); if (response.Code != 200) { HttpContext.Current.Session["token"] = null; HttpContext.Current.Session["CurrentUser"] = null; var cookie = new HttpCookie("qoala_token"); cookie.Expires = DateTime.Now.AddDays(-1d); HttpContext.Current.Response.Cookies.Add(cookie); return; } var body = response.Body; Models.ViewModels.UserViewModel user = new Models.ViewModels.UserViewModel { IdUser = (int)body.GetValue("id_user"), Email = body.GetValue("email").ToString(), Name = body.GetValue("name").ToString(), IdPlan = (int?)body.GetValue("id_plan"), Permission = (int)body.GetValue("permission") }; HttpContext.Current.Session["CurrentUser"] = user; } }