private async Task SelecionarFotoDoAlbumAsync(AtendimentoFoto foto) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Álbum não suportado", "Não existe permissão para acessar o álbum de fotos", "OK"); return; } var file = await CrossMedia.Current.PickPhotoAsync(); if (file == null) { return; } var imagePath = SaveFotoFromAlbum(foto.CaminhoFoto, file); fotoCarro.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); viewModel.CaminhoFoto = imagePath; return; }
private void RegistrarCommands() { CameraCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Camera"); }); AlbumCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Album"); }); GravarFotoCommand = new Command(async() => { AtendimentoFoto.Atendimento = AtendimentoFoto.Atendimento; AtendimentoFoto.AtendimentoID = AtendimentoFoto.Atendimento.AtendimentoID; var dal = new AtendimentoFotoDAL(AtendimentoFoto.Atendimento, DependencyService.Get <IDBPath>().GetDbPath()); await dal.UpdateAsync(AtendimentoFoto, AtendimentoFoto.AtendimentoFotoID); MessagingCenter.Send <string>("Atualização realizada com sucesso.", "InformacaoCRUD"); MessagingCenter.Send <string>("consultar.png", "AtualizarFoto"); AtendimentoFoto = new AtendimentoFoto(); OnPropertyChanged(nameof(Observacoes)); }, () => { return(!string.IsNullOrEmpty(Observacoes) && !string.IsNullOrEmpty(CaminhoFoto)); }); }
public FotosCRUDView(AtendimentoFoto foto, string title) : this() { this.Title = title; this.previousBarBackgroundColor = App.navigationPage.BarBackgroundColor; this.previousBarTextColor = App.navigationPage.BarTextColor; BindingContext = viewModel = new FotosCRUDViewModel(foto); App.navigationPage.Popped += OnPoppedCRUDFoto; }
private async Task <bool> TirarFotoAsync(AtendimentoFoto foto) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("Sem Câmera", "A câmera não está disponível.", "OK"); await Task.FromResult(false); } string fileName; if (foto.CaminhoFoto == null) { fileName = String.Format("{0:ddMMyyy_HHmm}", DateTime.Now) + ".jpg"; } else { File.Delete(DependencyService.Get <IFotoLoadMediaPlugin>().GetPathToPhoto(foto.CaminhoFoto)); fileName = (foto.CaminhoFoto.LastIndexOf("/") > 0) ? foto.CaminhoFoto.Substring(foto.CaminhoFoto.LastIndexOf("/") + 1) : String.Format("{0:ddMMyyy_HHmm}", DateTime.Now) + ".jpg"; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Fotos", PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full, Name = fileName }); if (file == null) { return(await Task.FromResult(false)); } ; fotoCarro.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); viewModel.CaminhoFoto = file.Path; viewModel.NomeArquivo = fileName; MemoryStream ms = null; using (ms = new MemoryStream()) { var stream = file.GetStream(); stream.CopyTo(ms); } viewModel.ConteudoFoto = ms.ToArray(); return(await Task.FromResult(true)); }
private void RegistrarCommands() { CameraCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Camera"); }); AlbumCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Album"); }); GravarFotoCommand = new Command(async() => { string url = "http://oficinamarcelo.somee.com/api/AtendimentoFotos/FileUpload"; //TODO: xyz será o endereço da sua API AtendimentoFoto afImagem = new AtendimentoFoto() { ConteudoFoto = AtendimentoFoto.ConteudoFoto, AtendimentoID = (AtendimentoFoto.AtendimentoID == null) ? 1 : AtendimentoFoto.AtendimentoID, CaminhoFoto = AtendimentoFoto.CaminhoFoto, NomeArquivo = AtendimentoFoto.NomeArquivo, Observacoes = AtendimentoFoto.Observacoes }; //TODO: haverá mais código para envio da Foto para a API HttpClient client = new HttpClient(); MultipartFormDataContent content = new MultipartFormDataContent(); ByteArrayContent baContent = new ByteArrayContent(afImagem.ConteudoFoto); StringContent atendimentoIdContent = new StringContent(afImagem.AtendimentoID.ToString()); StringContent caminhoFotoContent = new StringContent(afImagem.CaminhoFoto); StringContent observacoesContent = new StringContent(afImagem.Observacoes); content.Add(baContent, afImagem.CaminhoFoto, afImagem.NomeArquivo); content.Add(atendimentoIdContent, "AtendimentoID"); content.Add(caminhoFotoContent, "CaminhoFoto"); content.Add(observacoesContent, "Observacoes"); //upload MultipartFormDataContent content async and store response in response var var response = await client.PostAsync(url, content); //read response result as a string async into json var var responsestr = response.Content.ReadAsStringAsync().Result; int id = 0; int.TryParse(responsestr.Replace("\"", "").Replace(@"\", ""), out id); if (id != 0) { AtendimentoFoto = new AtendimentoFoto(); OnPropertyChanged(nameof(Observacoes)); MessagingCenter.Send <string>("Dados gravados com sucesso.", "InformacaoCRUD"); } }); }
public FotoListContainerControl(AtendimentoFoto foto) { Content = new Image() { Source = DependencyService.Get <IFotoLoadMediaPlugin>().GetPathToPhoto(foto.CaminhoFoto) }; this.Foto = foto; RegistrarPanGestureRecognizer(); RegistrarTapGestureRecognizer(); }
private void RegistrarCommands() { NovoCommand = new Command(() => { var atendimentoFoto = new AtendimentoFoto() { Atendimento = this.Atendimento, AtendimentoID = this.Atendimento.AtendimentoID }; MessagingCenter.Send <AtendimentoFoto>(atendimentoFoto, "Mostrar"); }, () => { return(!this.Atendimento.EstaFinalizado); }); }
public FotosCRUDViewModel(AtendimentoFoto atendimentoFoto) { this.AtendimentoFoto = atendimentoFoto; RegistrarCommands(); }
private void RegistrarCommands() { CameraCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Camera"); }); AlbumCommand = new Command(() => { MessagingCenter.Send <AtendimentoFoto>(this.AtendimentoFoto, "Album"); }); GravarFotoCommand = new Command(async() => { string url = "http://gustavoxavier.somee.com/api/AtendimentoFotos/FileUpload"; AtendimentoFoto afImagem = new AtendimentoFoto() { ConteudoFoto = AtendimentoFoto.ConteudoFoto, AtendimentoID = AtendimentoFoto.AtendimentoID, CaminhoFoto = AtendimentoFoto.CaminhoFoto, NomeArquivo = AtendimentoFoto.NomeArquivo, Observacoes = AtendimentoFoto.Observacoes }; //Outra referência: https://github.com/CrossGeeks/FileUploaderPlugin //List<FilePathItem> listaArquivos = new List<FilePathItem>(); //FileUploadResponse response = await CrossFileUploader.Current.UploadFileAsync(url, new FileBytesItem("txtFile", afImagem.ConteudoFoto, afImagem.CaminhoFoto), new Dictionary<string, string>() //{ // {"AtendimentoID" , afImagem.AtendimentoID.ToString()} //}); //https://forums.xamarin.com/discussion/64176/how-to-upload-image-to-the-server-using-api-in-xamarin-forms //create new HttpClient and MultipartFormDataContent and add our file, and StudentId HttpClient client = new HttpClient(); MultipartFormDataContent content = new MultipartFormDataContent(); ByteArrayContent baContent = new ByteArrayContent(afImagem.ConteudoFoto); StringContent atendimentoIdContent = new StringContent(afImagem.AtendimentoID.ToString()); StringContent caminhoFotoContent = new StringContent(afImagem.CaminhoFoto); StringContent observacoesContent = new StringContent(afImagem.Observacoes); content.Add(baContent, afImagem.CaminhoFoto, afImagem.NomeArquivo); content.Add(atendimentoIdContent, "AtendimentoID"); content.Add(caminhoFotoContent, "CaminhoFoto"); content.Add(observacoesContent, "Observacoes"); //upload MultipartFormDataContent content async and store response in response var var response = await client.PostAsync(url, content); //read response result as a string async into json var var responsestr = response.Content.ReadAsStringAsync().Result; int id = 0; int.TryParse(responsestr.Replace("\"", "").Replace(@"\", ""), out id); if (id != 0) { AtendimentoFoto = new AtendimentoFoto(); OnPropertyChanged(nameof(Observacoes)); //MessagingCenter.Send<string>("Atualização realizada com sucesso.", "InformacaoCRUD"); //MessagingCenter.Send<string>("consultar.png", "AtualizarFoto"); } } /*, () => * { * return (!string.IsNullOrEmpty(Observacoes) && !string.IsNullOrEmpty(CaminhoFoto)); * }*/ ); }
public FotosCRUDView(AtendimentoFoto foto, string title) : this() { this.Title = title; BindingContext = viewModel = new FotosCRUDViewModel(foto); }
public async Task <AtendimentoFoto> PutAtendimentoFotoAsync(AtendimentoFoto f) { var result = await _request.PutAsync(ApiUrlBase, f); return(result); }
public async Task <AtendimentoFoto> PostAtendimentoFotoAsync(AtendimentoFoto f) { return(await _request.PostAsync(ApiUrlBase, f)); }
public async Task EliminarFotoAsync(AtendimentoFoto atendimentoFoto) { await atendimentoFotoDAL.DeleteAsync(atendimentoFoto); File.Delete(DependencyService.Get <IFotoLoadMediaPlugin>().GetPathToPhoto(atendimentoFoto.CaminhoFoto)); }