public IHttpActionResult GetByEmail(string email) { email = email.DecodeBase64(); ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); Profile profile = profileStored.GetByEmail(email); if (profile == null) { return(NotFound()); } return(Ok(profile)); }
public Follow CheckFollow(int id) { Follow follow = new Follow(); Profile profile; ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); profile = profileStored.GetByEmail(Session["userEmail"].ToString()); string url = "api/Follow/" + profile.Id + "/" + id; follow = _client.GetAsync(url).Result.Content.ReadAsAsync <Follow>().Result; return(follow); }
//POST: /Follow/FollowProfile/id public async Task <Follow> FollowProfile(int id) { Follow follow = new Follow(); Profile profile; ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); profile = profileStored.GetByEmail(Session["userEmail"].ToString()); follow.UserId = profile.Id; follow.FollowingId = id; await _client.PostAsJsonAsync <Follow>("api/follow", follow); return(follow); }
public ActionResult Edit(int id) { RegisterClientToken(); Gallery gallery = new Gallery(); gallery = _client.GetAsync("api/Gallery/" + id).Result.Content.ReadAsAsync <Gallery>().Result; ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); Profile createdProfile = profileStored.GetByEmail(Session["userEmail"].ToString()); ViewBag.LoggedUserId = createdProfile.Id; return(View(gallery)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { var loginRequest = await _client.PostAsJsonAsync <LoginViewModel>("api/account/login", model); if (!loginRequest.IsSuccessStatusCode) { RedirectToAction("Index"); } //Get Token and save in Session //setup login data var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", model.Email), new KeyValuePair <string, string>("password", model.Password), }); //send request HttpResponseMessage responseMessage = await _client.PostAsync("Token", formContent); //get access token from response body var responseJson = await responseMessage.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseJson); Session["apiToken"] = jObject.GetValue("access_token").ToString(); Session["userEmail"] = model.Email; ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); Profile profile = profileStored.GetByEmail(model.Email); if (profile.Id != 0) { HttpResponseMessage result = await _client.GetAsync("api/Profiles/" + profile.Id); var profileResponseJson = await result.Content.ReadAsStringAsync(); var profileJObject = JObject.Parse(profileResponseJson); if (result.IsSuccessStatusCode) { return(RedirectPermanent("/Profile/Details/" + profile.Id)); } } return(RedirectToAction("Create", "Profile")); }
public async Task <ActionResult> CreateGallery([Bind(Include = "Id,Name")] Gallery gallery) { RegisterClientToken(); if (ModelState.IsValid) { ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); Profile createdProfile = profileStored.GetByEmail(Session["userEmail"].ToString()); gallery.ProfileId = createdProfile.Id; await _client.PostAsJsonAsync <Gallery>("api/gallery", gallery); return(RedirectPermanent("/Profile/Details/" + createdProfile.Id)); } return(View(gallery)); }
public Follow DeleteFollow(int id) { Profile profile; Follow follow = new Follow(); ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); profile = profileStored.GetByEmail(Session["userEmail"].ToString()); string url = "api/Follow/" + profile.Id + "/" + id; var deleteResult = _client.DeleteAsync(url).Result; if (!deleteResult.IsSuccessStatusCode) { return(follow); } follow = deleteResult.Content.ReadAsAsync <Follow>().Result; return(follow); }
public async Task <ActionResult> Create([Bind(Include = "Id,FirstName,LastName,Email,Birthday,AccountId,PhotoUrl")] Profile profile, HttpPostedFileBase PhotoUrl) { RegisterClientToken(); if (ModelState.IsValid) { //##### Upload da Foto para o Blob ##### HttpPostedFileBase file = PhotoUrl; var blobService = new BlobService(); string fileUrl = await blobService.UploadImage("socialnetwork", Guid.NewGuid().ToString() + file.FileName, file.InputStream, file.ContentType); profile.PhotoUrl = fileUrl; //####################################### await _client.PostAsJsonAsync <Profile>("api/profiles", profile); ProfileStoredProcedureRepository profileStored = new ProfileStoredProcedureRepository(); Profile createdProfile = profileStored.GetByEmail(profile.Email); return(RedirectPermanent("/Profile/Details/" + createdProfile.Id)); } return(View(profile)); }