public ActionResult Edit(GalleryViewModel gallery, HttpPostedFileBase file) { if (ModelState.IsValid) { var photoUrl = Upload(file); gallery.PhotoUrl = photoUrl.Substring(1, photoUrl.Length - 2); var client = GlobalWebApiClient.GetClient(); var response = client.PutAsJsonAsync("api/galleries/update/", gallery).Result; try { if (response.IsSuccessStatusCode) { gallery = response.Content.ReadAsAsync <GalleryViewModel>().Result; TempData["SuccessMessage"] = "Gallery updated successfully"; return(RedirectToAction("Details", gallery)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(gallery)); }
public ActionResult DeletePost(Guid postId) { if (Session["Email"] == null) { return(RedirectToAction("Login", "Account")); } var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("api/Account/LoggedUser").Result; if (response.IsSuccessStatusCode) { var userLogged = response.Content.ReadAsAsync <ProfileViewModel>().Result; JObject jObj = new JObject { ["postId"] = postId }; foreach (var post in userLogged.Posts) { if (post.Id == postId) { response = client.DeleteAsync("api/posts/del" + postId).Result; return(RedirectToAction("Home", "Profiles")); } } } return(View("Error")); }
public ActionResult Delete(Guid?id) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.DeleteAsync("api/galleries/gallery/del/" + id.ToString()).Result; try { if (response.IsSuccessStatusCode) { TempData["SuccessMessage"] = "Gallery deleted successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { var result = ex.Message;; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View()); }
public ActionResult Delete(Guid?id) { if (Session["Email"] != null) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.DeleteAsync("api/profiles/profile/del/" + id.ToString()).Result; try { if (response.IsSuccessStatusCode) { TempData["SuccessMessage"] = "Profile deleted successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } } return(RedirectToAction("Login", "Account")); }
public ActionResult Edit(PostViewModel pvm) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.PutAsJsonAsync("/api/posts/update/", pvm).Result; try { if (response.IsSuccessStatusCode) { pvm = response.Content.ReadAsAsync <PostViewModel>().Result; TempData["SuccessMessage"] = "Post updated successfully"; return(RedirectToAction("Details", pvm)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(pvm)); }
public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model) { if (ModelState.IsValid) { const String URI_ADDRESS = "api/Account/ResetPassword"; try { var client = GlobalWebApiClient.GetClient(); var dataJson = JsonConvert.SerializeObject(model); var content = new StringContent(dataJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(URI_ADDRESS, content); if (response.IsSuccessStatusCode) { var ResetPasswordResponse = await response.Content.ReadAsAsync <ResetPasswordViewModel>(); return(RedirectToAction("ResetPasswordConfirmation", "Accounts")); } } catch (Exception) { throw; } } return(View(model)); }
public ActionResult DeleteConfirmed(Guid id) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.DeleteAsync("/api/marketplaces/marketplace/del/" + id.ToString()).Result; try { if (response.IsSuccessStatusCode) { var marketplace = response.Content.ReadAsAsync <MarketplaceViewModel>().Result; TempData["SuccessMessage"] = "Marketplace deleted successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View()); }
public ActionResult CreateImage(TransportImageViewModel transport, HttpPostedFileBase file) { if (ModelState.IsValid) { var photoUrl = Upload(file); transport.DetailsIVM.PhotoUrl = photoUrl.Substring(1, photoUrl.Length - 2); transport.DetailsIVM.GalleryId = transport.DetailsGVM.Id; transport.DetailsIVM.ProfileId = Guid.Parse(Session["UserId"].ToString()); var client = GlobalWebApiClient.GetClient(); var response = client.PostAsJsonAsync("/api/images/save/", transport.DetailsIVM).Result; try { if (response.IsSuccessStatusCode) { //var gallery = responseGallery.Content.ReadAsAsync<TransportImageViewModel>().Result; var ivm = response.Content.ReadAsAsync <ImageViewModel>().Result; TempData["SuccessMessage"] = "Image created successfully"; return(RedirectToAction("Details", "Gallery", transport.DetailsGVM)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(RedirectToAction("Index", "Gallery")); }
public ActionResult Create([Bind(Include = "Id,Title,Description,Price,Actived,CreationDate," + "UpdateDate")] AnnouncementViewModel announcement, HttpPostedFileBase file) { if (ModelState.IsValid) { var photoUrl = Upload(file); announcement.PhotoUrl = photoUrl.Substring(1, photoUrl.Length - 2); var client = GlobalWebApiClient.GetClient(); var response = client.PostAsJsonAsync("api/announcements/save/", announcement).Result; try { if (response.IsSuccessStatusCode) { announcement = response.Content.ReadAsAsync <AnnouncementViewModel>().Result; TempData["SuccessMessage"] = "Announcement created successfully"; return(RedirectToAction("Details", announcement)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(announcement)); }
public ActionResult Create(NotificationViewModel nvm) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.PostAsJsonAsync("api/notifications/save/", nvm).Result; try { if (response.IsSuccessStatusCode) { nvm = response.Content.ReadAsAsync <NotificationViewModel>().Result; TempData["SuccessMessage"] = "Notification created successfully"; return(RedirectToAction("Details", nvm)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(nvm)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { const String URI_ADDRESS = "api/Account/ForgotPassword"; try { var client = GlobalWebApiClient.GetClient(); var dataJson = JsonConvert.SerializeObject(model); var content = new StringContent(dataJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(URI_ADDRESS, content); if (response.IsSuccessStatusCode) { var ForgotResponse = await response.Content.ReadAsAsync <ForgotPasswordViewModel>(); //return RedirectToAction("Login", "Account"); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } } catch (Exception) { throw; } } // If we got this far, something failed, redisplay form return(View(model)); }
// GET: Image public ActionResult GetImagesByUserId() { var client = GlobalWebApiClient.GetClient(); //var response = client.GetAsync("api/Account/LoggedUser").Result; var responseProfile = client.GetAsync(@"api/profiles/profile/" + Session["Email"].ToString().EncodeBase64()).Result; if (responseProfile.IsSuccessStatusCode) { var userLogged = responseProfile.Content.ReadAsAsync <ProfileViewModel>().Result; if ((Session["Email"] == null) || !(userLogged.Id.ToString().Equals(Session["UserId"].ToString()))) { return(RedirectToAction("Login", "Account")); } else { IEnumerable <ImageViewModel> userImages; //var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/images/imagesbyuser").Result; if (response.IsSuccessStatusCode) { userImages = response.Content.ReadAsAsync <IEnumerable <ImageViewModel> >().Result; ViewBag.PhotoCount = userImages.ToList().Count; return(PartialView(@"~/Views/Shared/_ImagesParcial.cshtml", userImages.ToList())); } ViewBag.Result = "Server Error. Please contact administrator!"; //return RedirectToAction("Index", "Gallery"); return(PartialView(@"~/Views/Shared/_ImagesParcial.cshtml", ViewBag.Result)); } } return(RedirectToAction("Login", "Account")); }
public async Task <ActionResult> LogOff() { if (ModelState.IsValid) { const String URI_ADDRESS = "api/Accounts/LogOff"; try { var client = GlobalWebApiClient.GetClient(); var content = new StringContent("application/json"); var response = await client.PostAsync(URI_ADDRESS, content); if (response.IsSuccessStatusCode) { Session.Clear(); return(RedirectToAction("Login", "Accounts")); } } catch (Exception ex) { var result = ex.Message; } } return(View()); }
public ActionResult Create([Bind(Include = "Id,Title,CreationDate,UpdateDate")] MarketplaceViewModel marketplace) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.PostAsJsonAsync("/api/marketplaces/save/", marketplace).Result; try { if (response.IsSuccessStatusCode) { marketplace = response.Content.ReadAsAsync <MarketplaceViewModel>().Result; TempData["SuccessMessage"] = "Marketplace created successfully"; return(RedirectToAction("Details", marketplace)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(marketplace)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { const String URI_ADDRESS = "api/Accounts/Register"; try { var client = GlobalWebApiClient.GetClient(); var dataJson = JsonConvert.SerializeObject(model); var content = new StringContent(dataJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(URI_ADDRESS, content); if (response.IsSuccessStatusCode) { return(RedirectToAction("SuccessEmail", "Accounts")); } } catch (Exception ex) { var result = ex.Message; } } return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,PhotoUrl,Name,Type,Description,CreationDate," + "UpdateDate")] ImageViewModel image, HttpPostedFileBase file) { if (ModelState.IsValid) { var photoUrl = Upload(file); image.PhotoUrl = photoUrl.Substring(1, photoUrl.Length - 2); var client = GlobalWebApiClient.GetClient(); var response = client.PutAsJsonAsync("/api/images/update/", image).Result; try { if (response.IsSuccessStatusCode) { image = response.Content.ReadAsAsync <ImageViewModel>().Result; TempData["SuccessMessage"] = "Image updated successfully"; return(RedirectToAction("Details", image)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(image)); }
public ActionResult Create([Bind(Include = "Id,Name,Description,CreationDate,UpdateDate,Actived")] GroupViewModel group) { if (ModelState.IsValid) { var client = GlobalWebApiClient.GetClient(); var response = client.PostAsJsonAsync("/api/groups/save/", group).Result; try { if (response.IsSuccessStatusCode) { group = response.Content.ReadAsAsync <GroupViewModel>().Result; TempData["SuccessMessage"] = "Group created successfully"; return(RedirectToAction("Details", group)); } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } return(View(group)); }
//GET: Profiles/Delete/5 public ActionResult Delete(Guid id) { if ((Session["Email"] == null) || !(id.ToString().Equals(Session["UserId"].ToString()))) { return(RedirectToAction("Login", "Account")); } else { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync(@"api/profiles/profile/info/" + id.ToString()).Result; try { if (response.IsSuccessStatusCode) { var profile = response.Content.ReadAsAsync <ProfileViewModel>().Result; return(View(profile)); } else { return(View()); } } catch (Exception ex) { var result = ex.Message; } } return(RedirectToAction("Login", "Account")); }
//GET: Profiles public ActionResult Index(String termo = "") { if (Session["Email"] != null) { try { IEnumerable <ProfileViewModel> profiles; var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("api/profiles/all").Result; if (response.IsSuccessStatusCode) { profiles = response.Content.ReadAsAsync <IEnumerable <ProfileViewModel> >().Result; var profile = profiles.ToList().FirstOrDefault(p => p.Email == Session["Email"].ToString()); if (profile == null) { return(RedirectToAction("Create", "Profiles")); } else if (termo != String.Empty) { client = GlobalWebApiClient.GetClient(); response = client.GetAsync(@"api/profiles/info/" + termo).Result; if (response.IsSuccessStatusCode) { profiles = response.Content.ReadAsAsync <IEnumerable <ProfileViewModel> >().Result; return(View(profiles.ToList())); } else { ViewBag.Error = "Server Error. Please contact administrator!"; } } else { return(View(profiles.ToList())); } } else { ViewBag.Error = "Server Error. Please contact administrator!"; } } catch (Exception ex) { var result = ex.Message; } return(View("Error")); } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Details(Guid?id) { try { var client = GlobalWebApiClient.GetClient(); var responseGallery = client.GetAsync("api/galleries/gallery/info/" + id.ToString()).Result; if (responseGallery.IsSuccessStatusCode) { var gallery = responseGallery.Content.ReadAsAsync <GalleryViewModel>().Result; //var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/images/imagesbyuser").Result; var responseUser = client.GetAsync("/api/Account/LoggedUser").Result; if (responseUser.IsSuccessStatusCode && response.IsSuccessStatusCode) { IEnumerable <ImageViewModel> userImages; userImages = response.Content.ReadAsAsync <IEnumerable <ImageViewModel> >().Result; var loggedUser = responseUser.Content.ReadAsAsync <ProfileViewModel>().Result; if (loggedUser.Id.ToString().Equals(Session["UserId"].ToString())) { ViewBag.PhotoCount = userImages.ToList().Count; ViewBag.ImagesByUser = userImages.ToList(); ViewBag.LoggedUser = true; var transport = new TransportImageViewModel { DetailsGVM = gallery }; return(View(transport)); } else { ViewBag.LoggedUser = false; } } } else { return(View()); } } catch (Exception ex) { var result = ex.Message; } return(View()); }
// GET: Image/Delete/5 public ActionResult Delete(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/images/image/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var image = response.Content.ReadAsAsync <ImageViewModel>().Result; return(View(image)); } else { return(View()); } }
// GET: Notifications/Edit/5 public ActionResult Edit(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync($"api/notifications/notification/info/?id={id.ToString()}").Result; if (response.IsSuccessStatusCode) { var nvm = response.Content.ReadAsAsync <NotificationViewModel>().Result; return(View(nvm)); } else { return(View()); } }
// GET: Posts/Delete/5 public ActionResult Delete(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync($"api/posts/post/del/?id={id.ToString()}").Result; if (response.IsSuccessStatusCode) { var pvm = response.Content.ReadAsAsync <PostViewModel>().Result; return(View(pvm)); } else { return(View()); } }
// GET: Announcement/Edit/5 public ActionResult Edit(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("api/announcements/announcement/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var announcement = response.Content.ReadAsAsync <AnnouncementViewModel>().Result; return(View(announcement)); } else { return(View()); } }
// GET: Group/Edit/5 public ActionResult Edit(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/groups/group/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var group = response.Content.ReadAsAsync <GroupViewModel>().Result; return(View(group)); } else { return(View()); } }
// GET: Marketplace/Edit/5 public ActionResult Edit(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/marketplaces/marketplace/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var marketplace = response.Content.ReadAsAsync <MarketplaceViewModel>().Result; return(View(marketplace)); } else { return(View()); } }
//POST: Image/Upload public String Upload(HttpPostedFileBase file) { if (Session["Email"] != null) { if (ModelState.IsValid) { try { const String URI_ADDRESS = "api/images/upload"; var client = GlobalWebApiClient.GetClient(); using (var content = new MultipartFormDataContent()) { byte[] Bytes = new byte[file.InputStream.Length + 1]; file.InputStream.Read(Bytes, 0, Bytes.Length); var fileContent = new ByteArrayContent(Bytes); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = file.FileName }; content.Add(fileContent); var response = client.PostAsync(URI_ADDRESS, content).Result; if (response.IsSuccessStatusCode) { var photoUrl = response.Content.ReadAsStringAsync().Result; return(photoUrl); } else { ViewBag.Failed = "Failed! " + response.Content.ToString(); } } } catch (Exception ex) { var result = ex.Message; } } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } } return(null); }
// GET: Announcement/Details/5 public ActionResult Details(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("api/announcements/announcement/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var announcement = response.Content.ReadAsAsync <AnnouncementViewModel>().Result; return(View(announcement)); } else { ViewBag.Result = "Server Error. Please contact administrator!"; } return(View()); }
// GET: Marketplace/Details/5 public ActionResult Details(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync("/api/marketplaces/marketplace/info/" + id.ToString()).Result; if (response.IsSuccessStatusCode) { var marketplace = response.Content.ReadAsAsync <MarketplaceViewModel>().Result; return(View(marketplace)); } else { ViewBag.Result = "Server Error. Please contact administrator!"; } return(View()); }
// GET: Notifications/Details/5 public ActionResult Details(Guid?id) { var client = GlobalWebApiClient.GetClient(); var response = client.GetAsync($"api/notifications/notification/info/?id={id.ToString()}").Result; if (response.IsSuccessStatusCode) { var nvm = response.Content.ReadAsAsync <NotificationViewModel>().Result; return(View(nvm)); } else { ViewBag.Result = "Server Error. Please contact administrator!"; } return(View()); }