public async Task <bool> SendEmailAsync(string token, string subject, string body)
        {
            var model = new MessageDetail()
            {
                Body    = body,
                Subject = subject
            };
            var myContent   = JsonConvert.SerializeObject(model);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue(HttpConstants.MEDIA_TYPE_APPLICATION_FORM);
            byteContent.Headers.Add(App.Configuration.AppConfig.TokenHeaderName, token);
            var requestUri = ClientService.GetRequestUri(ControllerName, "send");
            var response   = await ClientService.PostAsync(requestUri, byteContent);

            if (response != null)
            {
                Task <string> jsonTask = response.Content.ReadAsStringAsync();
                var           result   = JsonConvert.DeserializeObject(jsonTask.Result);
                if (jsonTask.Result.Contains(HttpConstants.SUCCESS))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        public async Task <HttpResponseMessage> UploadFileResponseAsync(MediaFile _mediaFile)
        {
            var content = new MultipartFormDataContent();

            content.Add(new StreamContent(_mediaFile.GetStream()), "\"file\"", $"\"{_mediaFile.Path.Clean()}\"");
            var uploadAddress = App.Configuration.AppConfig.BaseUrl + "api/" + ControllerName + "/uploadasync";

            return(await ClientService.PostAsync(uploadAddress, content));
        }
Exemple #3
0
        public async Task <string> UploadFileAsync(MediaFile _mediaFile)
        {
            try
            {
                var content = new MultipartFormDataContent();
                content.Add(new StreamContent(_mediaFile.GetStream()), "\"file\"", $"\"{_mediaFile.Path}\"");
                var uploadAddress       = App.Configuration.AppConfig.BaseUrl + "api/" + ControllerName + "/upload";
                var httpResponseMessage = await ClientService.PostAsync(uploadAddress, content);

                if (httpResponseMessage != null)
                {
                    var message = await httpResponseMessage.Content.ReadAsStringAsync();

                    return(message);
                }
            }
            catch (Exception)
            {
                return(TextResources.MessageErrorOccurred);
            }

            return(TextResources.MessageFileUploadFailed);
        }