public async Task <bool> DeleteProfile(ProfileToModify profile) { if (await _auth.ValidateShackname(profile)) { var profileToDelete = await _context.ShackProfiles .FirstOrDefaultAsync(x => x.Shackname == profile.Shackname.ToUpper()); _context.ShackProfiles.Remove(profileToDelete); _context.SaveChanges(); return(true); } return(false); }
public async Task <IActionResult> DeleteProfile([FromBody] ProfileToModify profileToDelete) { if (profileToDelete == null) { throw new ArgumentNullException(nameof(profileToDelete)); } var res = await _repo.DeleteProfile(profileToDelete); if (res) { return(Ok("Profile is deleted")); } return(BadRequest("Could not delete Profile, see TFO for details")); }
public async Task <IActionResult> CreateProfile([FromBody] ProfileToModify profileToCreate) { if (profileToCreate == null) { throw new ArgumentNullException(nameof(profileToCreate)); } var res = await _repo.AddProfile(profileToCreate); if (res.Verified) { return(CreatedAtRoute("")); } return(BadRequest("Could not create Profile, see TFO for details")); }
public async Task <ShackProfile> UpdateProfile(ProfileToModify profile) { profile.Shackname = profile.Shackname.ToUpper(); var existingProfile = await _context.ShackProfiles .FirstOrDefaultAsync(x => x.Shackname == profile.Shackname); _mapper.Map(profile, existingProfile); if (await _context.SaveChangesAsync() > 0) { return(profile); } throw new Exception($"Updating {profile.Shackname} failed"); }
public async Task <ShackProfile> AddProfile(ProfileToModify profileToCreate) { if (await _auth.ValidateShackname(profileToCreate)) { var shacker = _mapper.Map <ShackProfile>(profileToCreate); shacker.Verified = true; shacker.CreatedAt = DateTime.Now; shacker.Shackname = shacker.Shackname.ToUpper(); await _context.ShackProfiles.AddAsync(shacker); await _context.SaveChangesAsync(); return(shacker); } return(profileToCreate); }
public async Task <bool> ValidateShackname(ProfileToModify profile) { var client = new HttpClient(); var verifyUri = new Uri("https://winchatty.com/v2/verifyCredentials/"); var credsToVerify = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("username", profile.Shackname), new KeyValuePair <string, string>("password", profile.Password), }); var response = await client.PostAsync(verifyUri, credsToVerify); if (response.IsSuccessStatusCode) { var res = await response.Content.ReadAsStringAsync(); WinChattyVerify result = JsonConvert.DeserializeObject <WinChattyVerify>(res); return(result.IsValid); } return(false); }
public async Task <IActionResult> UpdateProfile(ProfileToModify profile) { var result = await _repo.UpdateProfile(profile); return(Ok(result)); }