Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
2018-app-inutralia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
inutralia
2018-app-inutralia
Commits
06cee149
Commit
06cee149
authored
Feb 07, 2019
by
Javier Piris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creados métodos de listado de mensajes / Loading / Refresh / Delete / Save y Update de message
parent
9811b960
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
163 additions
and
4 deletions
+163
-4
NewQuestionViewModel.cs
...ia/ViewModels/QuestionsSpecialist/NewQuestionViewModel.cs
+163
-4
No files found.
inutralia/inutralia/ViewModels/QuestionsSpecialist/NewQuestionViewModel.cs
View file @
06cee149
...
@@ -3,14 +3,40 @@
...
@@ -3,14 +3,40 @@
using
inutralia.Models.Questions
;
using
inutralia.Models.Questions
;
using
MvvmHelpers
;
using
MvvmHelpers
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
System.Windows.Input
;
using
System.Windows.Input
;
using
Xamarin.Forms
;
using
Xamarin.Forms
;
public
class
NewQuestionViewModel
:
BaseViewModel
public
class
NewQuestionViewModel
:
Base
Navigation
ViewModel
{
{
public
ObservableRangeCollection
<
Message
>
ListMessages
{
get
;
}
public
enum
Estatus
{
Pendiente
=
1
,
Respondida_por_cliente
=
2
,
Respondida_por_nutricionista
=
3
,
Cerrado
=
4
}
public
Estatus
State
=>
(
Estatus
)
Message
?.
StateId
;
public
Message
Message
{
private
set
;
get
;
}
public
ICommand
SendCommand
{
get
;
set
;
}
public
ICommand
SendCommand
{
get
;
set
;
}
public
ObservableRangeCollection
<
Message
>
_ListMessages
;
// LOADING LIST
Command
_LoadNewQuestionCommand
;
// UODATE LIST
Command
_RefreshNewQuestionCommand
;
// DELETE LIST
Command
_DeleteNewQuestionCommand
;
public
NewQuestionViewModel
()
public
NewQuestionViewModel
()
{
{
IsBusy
=
true
;
IsBusy
=
true
;
...
@@ -28,11 +54,9 @@
...
@@ -28,11 +54,9 @@
MessageDateTime
=
DateTime
.
Now
MessageDateTime
=
DateTime
.
Now
};
};
ListMessages
.
Add
(
message
);
ListMessages
.
Add
(
message
);
OutText
=
""
;
OutText
=
""
;
}
}
});
});
IsBusy
=
false
;
IsBusy
=
false
;
...
@@ -44,5 +68,140 @@
...
@@ -44,5 +68,140 @@
set
{
SetProperty
(
ref
_outText
,
value
);
}
set
{
SetProperty
(
ref
_outText
,
value
);
}
}
}
string
_outText
=
string
.
Empty
;
string
_outText
=
string
.
Empty
;
// LIST MESSAGES
public
ObservableRangeCollection
<
Message
>
ListMessages
{
get
{
return
_ListMessages
??
(
_ListMessages
=
new
ObservableRangeCollection
<
Message
>());
}
set
{
_ListMessages
=
value
;
OnPropertyChanged
(
"ListMessages"
);
}
}
// LOAD
public
Command
LoadNewQuestionCommand
{
get
{
return
_LoadNewQuestionCommand
??
(
_LoadNewQuestionCommand
=
new
Command
(
async
()
=>
await
ExecuteLoadNewQuestionCommand
()));
}
}
public
async
Task
ExecuteLoadNewQuestionCommand
()
{
LoadNewQuestionCommand
.
ChangeCanExecute
();
//if (Authorizations.Count < 1)
await
FetchNewQuestion
();
LoadNewQuestionCommand
.
ChangeCanExecute
();
}
// REFRESH
public
Command
RefreshNewQuestionCommand
{
get
{
return
_RefreshNewQuestionCommand
??
(
_RefreshNewQuestionCommand
=
new
Command
(
async
()
=>
await
ExecuteRefreshNewQuestionCommand
()));
}
}
public
async
Task
ExecuteRefreshNewQuestionCommand
()
{
try
{
RefreshNewQuestionCommand
.
ChangeCanExecute
();
await
FetchNewQuestion
();
RefreshNewQuestionCommand
.
ChangeCanExecute
();
}
catch
(
Exception
e
)
{
string
err
=
e
.
Message
;
}
}
// DELETE
public
Command
DeleteNewQuestionCommand
{
get
{
return
_DeleteNewQuestionCommand
??
(
_DeleteNewQuestionCommand
=
new
Command
(
async
(
parameter
)
=>
await
ExecuteDeleteNewQuestionCommand
(
parameter
as
Message
)));
}
}
async
Task
ExecuteDeleteNewQuestionCommand
(
Message
message
)
{
if
(
message
!=
null
)
{
IsBusy
=
true
;
await
App
.
API
.
DeleteItemAsync
(
message
);
await
FetchNewQuestion
();
IsBusy
=
false
;
}
}
// FETCH
async
Task
FetchNewQuestion
()
{
IsBusy
=
true
;
try
{
ListMessages
=
new
ObservableRangeCollection
<
Message
>(
await
App
.
API
.
RefreshListAsync
<
Message
>());
}
catch
(
Exception
e
)
{
string
err
=
e
.
Message
;
}
}
// SAVE MESSAGE
public
async
Task
SaveMessage
(
string
text
)
{
var
q
=
Message
;
HttpMethod
method
=
HttpMethod
.
Post
;
IsBusy
=
true
;
if
(
q
.
Id
<
0
)
{
var
data
=
new
Dictionary
<
string
,
string
>()
{
{
"subject"
,
q
.
Subject
},{
"message"
,
text
}
};
await
App
.
API
.
RawMessage
(
method
,
string
.
Format
(
"messages"
),
data
,
q
);
}
IsBusy
=
false
;
ListMessages
=
new
ObservableRangeCollection
<
Message
>();
}
// UPDATE MESSAGE
public
async
Task
UpdateMessage
()
{
var
q
=
Message
;
HttpMethod
method
=
HttpMethod
.
Post
;
IsBusy
=
true
;
await
App
.
API
.
UpdateItemAsync
(
q
);
if
(
await
App
.
API
.
RefreshItemAsync
(
Message
))
{
Title
=
Message
.
StatusImg
;
OnPropertyChanged
(
"State"
);
}
IsBusy
=
false
;
}
public
bool
IsClosedOrPending
=>
(
State
==
Estatus
.
Pendiente
||
State
==
Estatus
.
Cerrado
||
State
==
Estatus
.
Respondida_por_cliente
||
State
==
Estatus
.
Respondida_por_nutricionista
);
public
bool
MayBeClosed
=>
!
IsClosedOrPending
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment