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 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 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 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 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 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 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 RegisterSponsor(RegisterViewModel model) { WSRequest request = new WSRequest("accounts/register"); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("name", model.Name), new KeyValuePair <string, string>("password", model.Password), new KeyValuePair <string, string>("document", model.Document), new KeyValuePair <string, string>("permission", "4"), new KeyValuePair <string, string>("email", model.Email) }; request.AddJsonParameter(parameters); var data = new { message = "Registro efetuado com sucesso" }; try { var response = request.Post(); if (response.Code != 201) { Response.StatusCode = 400; data = new { message = response.Body.GetValue("Message").ToString() }; } else { string token = response.Body.GetValue("token").ToString(); Session["token"] = token; var cookie = new HttpCookie("qoala_token", token); cookie.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie); } } catch (Exception e) { Response.StatusCode = 400; data = new { message = e.Message }; } return(new JsonResult() { Data = data }); }
public ActionResult Login(LoginViewModel model, string returnUrl) { WSRequest request = new WSRequest("accounts/login"); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("password", model.Password), new KeyValuePair <string, string>("email", model.Email) }; request.AddJsonParameter(parameters); var data = new { message = "Login efetuado com sucesso" }; try { var response = request.Post(); if (response.Code != 201) { Response.StatusCode = 400; data = new { message = response.Body.GetValue("Message").ToString() }; } else { string token = response.Body.GetValue("token").ToString(); Session["token"] = token; var cookie = new HttpCookie("qoala_token", token); cookie.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie); } } catch (Exception e) { Response.StatusCode = 400; data = new { message = e.Message }; } return(new JsonResult { Data = data }); // nao da pra fazer isso, pq? :: só não faz o redirect nem nada //return RedirectToAction("Show", "Profile", new { Data=data }); }
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 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 Update(DeviceViewModel device) { WSRequest request = new WSRequest("/users/" + device.IdUser + "/devices/" + device.IdDevice); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("alias", device.Alias.ToString()), new KeyValuePair <string, string>("color", device.Color.ToString()), new KeyValuePair <string, string>("frequency_update", device.FrequencyUpdate.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 Update(PostViewModel post) { WSRequest request = new WSRequest("/posts/" + post.IdPost); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("title", post.Title), new KeyValuePair <string, string>("content", post.Content) }; request.AddJsonParameter(parameters); var response = request.Put(); if (response.Code != 204) { return(RedirectToAction("Edit", "Post", post)); } return(RedirectToAction("Show", "Post", new { idPost = post.IdPost, message = "O post " + post.IdPost + " foi atualizado" })); }
public ActionResult Create(PostViewModel post) { WSRequest request = new WSRequest("/posts"); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("title", post.Title), new KeyValuePair <string, string>("content", post.Content), new KeyValuePair <string, string>("id_user", post.IdUser.ToString()) }; request.AddJsonParameter(parameters); var response = request.Post(); if (response.Code != 201) { return(RedirectToAction("New", "Post", new { error = "Não foi possivel cadastrar" })); } return(RedirectToAction("Show", "Post", new { idPost = response.Body.GetValue("id_post") })); }
public ActionResult Create(DeviceViewModel device) { var user = (UserViewModel)Session["CurrentUser"]; WSRequest request = new WSRequest("/users/" + user.IdUser + "/devices"); request.AddAuthorization(Session["token"].ToString()); IEnumerable <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("color", device.Color), new KeyValuePair <string, string>("alias", device.Alias), new KeyValuePair <string, string>("frequency_update", device.FrequencyUpdate.ToString()), new KeyValuePair <string, string>("alarm", true.ToString()) }; request.AddJsonParameter(parameters); var response = request.Post(); if (response.Code != 201) { return(RedirectToAction("Index", "Device", new { message = "O device não foi cadastrado" })); } return(RedirectToAction("Index", "Device", new { message = "O device foi cadastrado" })); }