public async Task <ApiResult <CipherResponse> > SaveAsync(Cipher cipher) { ApiResult <CipherResponse> response = null; var request = new CipherRequest(cipher); if (cipher.Id == null) { response = await _cipherApiRepository.PostAsync(request); } else { response = await _cipherApiRepository.PutAsync(cipher.Id, request); } if (response.Succeeded) { var data = new CipherData(response.Result, _authService.UserId); await UpsertDataAsync(data, true, cipher.Id == null); cipher.Id = data.Id; } else if (response.StatusCode == System.Net.HttpStatusCode.Forbidden || response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { _authService.LogOut(); } return(response); }
public void CipherTest() { var cipherConverter = new CipherConverter(); var request = new CipherRequest() { UserInput = "Test" }; var result = cipherConverter.EncryptWord(request); Assert.AreEqual(result.Output, "QBPQ"); }
public ActionResult CipherInput(CipherModel request) { if (ModelState.IsValid) { var cipherConverter = new CipherConverter(); var cipherData = new CipherRequest(); cipherData.UserInput = request.UserInput; var result = cipherConverter.EncryptWord(cipherData); return(View("CipherOutput", result)); } else { return(View(request)); } }
public CipherResponse EncryptWord(CipherRequest request) { var response = new CipherResponse(); response.UserInput = request.UserInput; response.ModifiedInput = response.UserInput.ToUpper(); var temp = new StringBuilder(); for (int i = 0; i < response.ModifiedInput.Length; i++) { char c = response.ModifiedInput[i]; if (response.Caesar.ContainsKey(c)) { temp.Append(response.Caesar[c]); } response.Output = temp.ToString(); } return(response); }
public async Task <ApiResult <CipherResponse> > SaveAsync(Login login) { ApiResult <CipherResponse> response = null; var request = new CipherRequest(login); if (login.Id == null) { response = await _cipherApiRepository.PostAsync(request); } else { response = await _cipherApiRepository.PutAsync(login.Id, request); } if (response.Succeeded) { var data = new LoginData(response.Result, _authService.UserId); if (login.Id == null) { await _loginRepository.InsertAsync(data); login.Id = data.Id; } else { await _loginRepository.UpdateAsync(data); } } else if (response.StatusCode == System.Net.HttpStatusCode.Forbidden || response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { MessagingCenter.Send(Application.Current, "Logout", (string)null); } return(response); }
public Task <CipherResponse> PutCipherAsync(string id, CipherRequest request) { return(SendAsync <CipherRequest, CipherResponse>(HttpMethod.Put, string.Concat("/ciphers/", id), request, true, true)); }
public Task <CipherResponse> PostCipherAsync(CipherRequest request) { return(SendAsync <CipherRequest, CipherResponse>(HttpMethod.Post, "/ciphers", request, true, true)); }