Commit dc40bd25 by gema

creación de una conversación nueva y respuesta en una conversación ya existente

parent 4c75320c
......@@ -2,6 +2,7 @@
{
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
[JsonObject(MemberSerialization.OptIn)]
[DataPath("conversation")]
......@@ -9,8 +10,9 @@
public class Conversation : ObservableEntityData
{
/* [JsonProperty("subject", Required = Required.Always)]*/
[JsonProperty("subject", Required = Required.Always)]
[JsonProperty("subject")]
public string Subject { get; set; }
[JsonProperty("created_at")]
......@@ -22,9 +24,16 @@
[JsonProperty("messages")]
public IList<Message> Messages { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
public Conversation() { }
/*public string ExcerptCompress => Excerpt == null ? "..." : Excerpt.Substring(0, Math.Min(80, Excerpt.Length)).Length < 80 ? Excerpt : Excerpt.Substring(0, Excerpt.Substring(0, 80).LastIndexOf(" ")) + ((Excerpt.Length > 80) ? "..." : "");*/
}
}
......@@ -6,7 +6,7 @@
[DataPath("conversation")]
public class Message : ObservableEntityData
{
[JsonProperty("message", Required = Required.Always)]
[JsonProperty("message")]
public string Text { get; set; }
[JsonProperty("read")]
......
......@@ -136,6 +136,8 @@ namespace inutralia.API
string dataPath = GetDataPath(item.GetType());
string fullPath = isNew ? dataPath : string.Format("{0}/{1}", dataPath, item.Id);
// Crear uri a partir de la URL base y el path
var uri = new Uri(string.Format(Constants.ApiUrlTemplate, fullPath));
......@@ -168,8 +170,10 @@ namespace inutralia.API
return item.Id;
} //endif
}
catch (Exception)
{ }
catch (Exception e)
{
var error = e;
}
// Si llegamos aquí, es que la petición devolvió error
return null;
......
namespace inutralia.ViewModels
{
using inutralia.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class CreateNutriQuestionViewModel : BaseNavigationViewModel
{
public CreateNutriQuestionViewModel()
{
Conversation = new Conversation();
}
public Conversation Conversation { get; private set; }
public async Task RefreshData()
{
if (Conversation == null)
return;
IsBusy = true;
if (await App.API.RefreshItemAsync(Conversation))
{
OnPropertyChanged("Conversation");
// Cambiar título
var Caca = Conversation.Subject;
var Caca2 = Conversation.Created_at;
var Caca3 = Conversation.State;
var caca4 = Conversation.Messages[0];
} //endif
IsBusy = false;
}
public async Task SaveData(string subjectValue, string messageValue)
{
IsBusy = true;
Conversation.Subject = subjectValue;
Conversation.Message = messageValue;
await App.API.UpdateItemAsync(Conversation, true);
IsBusy = false;
}
}
}
\ No newline at end of file
......@@ -14,8 +14,14 @@
Conversation.Messages = new Message[0];
}
public DetailsNutriQuestionListViewModel() { Conversation = new Conversation(); }
public Conversation Conversation { get; private set; }
public async Task RefreshData()
{
if (Conversation == null)
......@@ -33,5 +39,15 @@
IsBusy = false;
}
public async Task saveData(string messageValue)
{
IsBusy = true;
Conversation.Message = messageValue;
await App.API.UpdateItemAsync(Conversation);
IsBusy = false;
}
}
}
\ No newline at end of file
......@@ -26,12 +26,14 @@
Placeholder="Asunto"
Margin="0,30,0,0"/>
<Editor Text="Consulta"
<Entry
Placeholder="Consulta"
x:Name="consultaEditor"
HeightRequest="100"
VerticalOptions="FillAndExpand" />
<Button Text="ENVIAR CONSULTA >"
Clicked="OnCreateButtonClicked"
HorizontalOptions="FillAndExpand"
BackgroundColor="#333333"
TextColor="#ffffff"
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using inutralia.ViewModels;
using System;
using Xamarin.Forms;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace inutralia.Views.NutriQuestion
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CreateNutriQuestion : ContentPage
{
protected CreateNutriQuestionViewModel ViewModel => BindingContext as CreateNutriQuestionViewModel;
public CreateNutriQuestion()
{
InitializeComponent();
/* if (consultaEditor.Text == null)
BindingContext = new CreateNutriQuestionViewModel();
}
protected override async void OnAppearing()
{
consultaEditor.Placeholder = "Please work";
}*/
base.OnAppearing();
}
async void OnCreateButtonClicked(object sender, EventArgs e)
{
try
{
var subjectValue = asunto.Text;
var messageValue = consultaEditor.Text;
await ViewModel.SaveData(subjectValue, messageValue);
await DisplayAlert("Exito", "El mensaje se ha enviado correctamente.", "Entendido");
(App.Current.MainPage as RootPage).Navigate<HomeView>();
}
catch (Exception )
{
await DisplayAlert("Error", "Se ha producido un error. Por favor, intentelo más tarde", "Entendido");
}
}
}
}
\ No newline at end of file
......@@ -106,12 +106,14 @@
<StackLayout Grid.Row="2" Grid.Column="0" >
<Editor Text="Escribe un mensaje..."
x:Name="consultaEditor"
<Entry
Placeholder="Escribe un mensaje.."
x:Name="messageEntry"
HeightRequest="45"
VerticalOptions="FillAndExpand" />
<Button Text="ENVIAR >"
Clicked="OnSendButtonClicked"
HorizontalOptions="FillAndExpand"
BackgroundColor="#333333"
TextColor="#ffffff"
......

using inutralia.ViewModels;
using System;
using Xamarin.Forms;
......@@ -24,6 +25,25 @@ namespace inutralia.Views.NutriQuestion
}
async void OnSendButtonClicked(object sender, EventArgs e)
{
try
{
var messageValue = messageEntry.Text;
await ViewModel.saveData(messageValue);
await DisplayAlert("Exito", "El mensaje se ha enviado correctamente.", "Entendido");
(App.Current.MainPage as RootPage).Navigate<HomeView>();
}
catch (Exception)
{
await DisplayAlert("Error", "Se ha producido un error. Por favor, intentelo más tarde", "Entendido");
}
}
}
}
......@@ -54,6 +54,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ViewModels\NutriQuestions\CreateNutriQuestionViewModel.cs" />
<Compile Include="ViewModels\NutriQuestions\DetailsNutriQuestionListViewModel.cs" />
<Compile Include="ViewModels\NutriQuestions\NutriQuestionListViewModel.cs" />
<Compile Include="ViewModels\Menus\CustomMenuViewModel.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment