public ActionResult Update(PlanViewModel plan) { WSRequest request = new WSRequest("/plans/" + plan.IdPlan); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("name", plan.Name), new KeyValuePair <string, string>("left", plan.Left.ToString()), new KeyValuePair <string, string>("price_cents", plan.Price_cents.ToString()), new KeyValuePair <string, string>("rewards", plan.Rewards), }; request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "Plan", plan)); } return(RedirectToAction("Show", "Plan", new { idPlan = plan.IdPlan, message = string.Format("O plano {0} - {1} foi atualizado", plan.IdPlan, plan.Name) })); }
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 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 Create(PlanViewModel plan) { if (ModelState.IsValid) { WSRequest request = new WSRequest("/plans"); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("name", plan.Name), //new KeyValuePair<string, string>("id_plan", plan.IdPlan.ToString()), new KeyValuePair <string, string>("left", plan.Left.ToString()), new KeyValuePair <string, string>("price_cents", plan.Price_cents.ToString()), new KeyValuePair <string, string>("rewards", plan.Rewards), }; request.AddJsonParameter(parameters); var response = request.Post(); if (response.Code != 201) { ModelState.AddModelError("", response.Code + ":" + response.Body.GetValue("Message").ToString()); } else { //return RedirectToAction("Show", "Plan", new { idPlan = response.Body.GetValue("id_plan") }); return(RedirectToAction("Index", "Plan", new { idPlan = plan.IdPlan })); } } return(View("New", plan)); //RedirectToAction("New", "Plan", new { error = "Não foi possivel cadastrar" }); }
public ActionResult Update(string returnUrl, CommentViewModel comment) { WSRequest request = new WSRequest("/posts/" + comment.IdPost + "/comments/" + comment.IdComment); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("content", comment.Content) }; request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "Comment", comment)); } if (returnUrl != null) { return(Redirect(returnUrl)); } return(RedirectToAction("Show", "Comment", new { idPost = comment.IdPost, idComment = comment.IdComment, message = "O comentário " + comment.IdComment + " foi atualizado" })); }
public ActionResult Update(UserViewModel model) { IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("name", model.Name), new KeyValuePair <string, string>("email", model.Email), new KeyValuePair <string, string>("permission", model.Permission.ToString()), new KeyValuePair <string, string>("address", model.Address), new KeyValuePair <string, string>("district", model.District), new KeyValuePair <string, string>("city", model.City), new KeyValuePair <string, string>("state", model.State), new KeyValuePair <string, string>("zipcode", model.ZipCode) }; WSRequest request = new WSRequest("/users/" + model.IdUser); request.AddAuthorization(Session["token"].ToString()); request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "Profile", new { message = "Não foi possivel editar o usuário" })); } return(RedirectToAction("Show", "Profile", new { message = "Sucesso ao editar perfil" })); }
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 Update(UserViewModel model) { WSRequest request = new WSRequest("/users/" + model.IdUser); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("name", model.Name), new KeyValuePair <string, string>("email", model.Email), new KeyValuePair <string, string>("permission", model.Permission.ToString()), new KeyValuePair <string, string>("address", model.Address), new KeyValuePair <string, string>("district", model.District), new KeyValuePair <string, string>("city", model.City), new KeyValuePair <string, string>("state", model.State), new KeyValuePair <string, string>("zipcode", model.ZipCode), }; request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "User", model)); } return(RedirectToAction("Index", "User")); }
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 JsonResult New(CommentViewModel comment) { var user = (UserViewModel)Session["currentUser"]; WSRequest request = new WSRequest("posts/" + comment.IdPost.ToString() + "/comments"); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("id_user", user.IdUser.ToString()), new KeyValuePair <string, string>("id_post", comment.IdPost.ToString()), new KeyValuePair <string, string>("content", comment.Content), }; request.AddJsonParameter(parameters); request.AddAuthorization(Session["token"].ToString()); var response = request.Post(); var data = new { success = false }; if (response.Code != 201) { return new JsonResult() { Data = data } } ; data = new { success = true }; return(new JsonResult() { Data = data }); }
public ActionResult Logout() { WSRequest request = new WSRequest("accounts/logout"); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("token", Session["token"].ToString()) }; request.AddAuthorization(Session["token"].ToString()); request.AddJsonParameter(parameters); try { var response = request.Post(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { Message = "Não foi possível delogar" })); } Session["token"] = null; Session["CurrentUser"] = null; var cookie = new HttpCookie("qoala_token"); cookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(cookie); } catch (Exception e) { return(RedirectToAction("Index", "Home", new { Message = e.Message })); } return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(int idUser) { var user = (UserViewModel)Session["CurrentUser"]; if (user.IdUser != idUser) { return(RedirectToAction("Show", "Profile")); } WSRequest request = new WSRequest("/users/" + idUser); request.AddAuthorization(Session["token"].ToString()); var response = request.Delete(); if (response.Code != 204) { return(RedirectToAction("Show", "Profile", new { message = "Não foi possivel deletar o usuário" })); } Session["token"] = null; Session["CurrentUser"] = null; var cookie = new HttpCookie("qoala_token"); cookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(string key) { WSRequest request = new WSRequest("infos/" + key); request.AddAuthorization(Session["token"].ToString()); var response = request.Delete(); if (response.Code != 204) { return(RedirectToAction("Index", "Information", new { message = "Não foi possível buscar esse post" })); } return(RedirectToAction("Index", "Information")); }
public ActionResult Delete(int idUser, int idDevice) { WSRequest request = new WSRequest("/users/" + idUser + "/devices/" + idDevice); request.AddAuthorization(Session["token"].ToString()); var response = request.Delete(); if (response.Code != 204) { return(RedirectToAction("Index", "Device", new { message = "O device não foi deletado" })); } return(RedirectToAction("Index", "Device", new { message = "O device foi deletado" })); }
public ActionResult Delete(int idUser) { WSRequest request = new WSRequest("/users/" + idUser); request.AddAuthorization(Session["token"].ToString()); var response = request.Delete(); if (response.Code != 204) { return(RedirectToAction("Index", "User", new { message = "Não foi possivel deletar o usuário" })); } return(RedirectToAction("Index", "User")); }
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 Delete(int idPost, string returnUrl) { WSRequest request = new WSRequest("posts/" + idPost); request.AddAuthorization(Session["token"].ToString()); var response = request.Delete(); if (response.Code != 204) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" })); } if (returnUrl != null) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Post", new { message = "Post " + idPost + " foi deletado." })); }
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 = 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 Publish(int idPost, string returnUrl) { WSRequest request = new WSRequest("posts/" + idPost + "/publish"); request.AddAuthorization(Session["token"].ToString()); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" })); } if (returnUrl != null) { return(Redirect(returnUrl)); } return(RedirectToAction("Show", "Post", new { idPost = idPost, message = "O post " + idPost + " foi publicado" })); }
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 Update(InformationViewModel model) { IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", model.Key), new KeyValuePair <string, string>("value", model.Value) }; WSRequest request = new WSRequest("infos/" + model.Key); request.AddAuthorization(Session["token"].ToString()); request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Index", "Information", new { message = "Não foi possível editar" })); } return(RedirectToAction("Index", "Information")); }
public ActionResult TurnAlarm(DeviceViewModel device) { WSRequest request = new WSRequest("/users/" + device.IdUser + "/devices/" + device.IdDevice + "/turn_alarm"); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("alarm", (!device.Alarm).ToString()) }; request.AddJsonParameter(parameters); request.AddAuthorization(Session["token"].ToString()); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "Device", device)); } return(RedirectToAction("Show", "Device", device)); }
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 AddPlan(SponsorPlanViewModel model) { var user = (UserViewModel)Session["CurrentUser"]; WSRequest request = new WSRequest("users/" + user.IdUser + "/plans/" + model.IdPlan + "/" + model.Qnt + "/" + model.UserDocument); request.AddAuthorization(Session["token"].ToString()); var response = request.Post(); if (response.Code == 400) { return(RedirectToAction("NewSponsor", "Plan", new { idPlan = model.IdPlan, message = "A quantidade de é maior que a disponivel" })); } if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possivel adicionar plano" })); } return(RedirectToAction("Index", "Home")); }
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)); }