public string Create(string senderReceptor, string textMessage, HttpPostedFileBase file) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:53273/api/Texts"); if (textMessage.Equals(string.Empty) && file == null) { return("No puede enviar mensajes vacios"); } if (textMessage != string.Empty) { var cipher = new SDES(); var getUser = new UsersLogic(); var receptor = senderReceptor.Split('|'); var a = getUser.getUserByUsername(receptor[1]).PrivateKey; var receptorKey = (Math.Pow(g, a) % p); var key = BigInteger.ModPow((int)receptorKey, UserPrivateKey, p); var cipherKey = Convert.ToString(((int)key), 2); textMessage = cipher.CipherText(textMessage, cipherKey); } else { textMessage = string.Empty; } var compressFile = new CompresssDecompressActions(); var message = new MessageModel() { SenderReceptor = senderReceptor, Message = textMessage, UploadedFile = file != null?compressFile.generateCharactersList(file) : "", PublicKey = (int)(Math.Pow(g, UserPrivateKey) % p) }; var postTask = client.PostAsJsonAsync("Messages", message); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return("200"); } else { if ((int)result.StatusCode >= 400 && (int)result.StatusCode < 500) { return(result.StatusCode.ToString() + ". Revise los datos ingresados :D"); } else { return(result.StatusCode.ToString() + ". Contacte a un desarrollador del sistema D:"); } } } }