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
291e58b5
Commit
291e58b5
authored
Dec 16, 2018
by
Javier Piris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Terminada funcionalidad en el custom MenuViewModel de añadir ingredientes al carito del super
parent
78fbe902
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
12 deletions
+41
-12
Ingredient.cs
inutralia/inutralia.Models/Ingredient.cs
+1
-4
ShoppingList.cs
inutralia/inutralia.Models/ShoppingList.cs
+2
-0
LocalDataService.cs
inutralia/inutralia/API/LocalDataService.cs
+31
-1
CustomMenuViewModel.cs
inutralia/inutralia/ViewModels/Menus/CustomMenuViewModel.cs
+7
-7
No files found.
inutralia/inutralia.Models/Ingredient.cs
View file @
291e58b5
...
...
@@ -21,9 +21,6 @@ namespace inutralia.Models
[
JsonProperty
(
"order"
)]
public
int
Order
{
get
;
set
;
}
public
Ingredient
()
{
}
public
Ingredient
()
{
}
}
}
inutralia/inutralia.Models/ShoppingList.cs
View file @
291e58b5
...
...
@@ -20,5 +20,7 @@ namespace inutralia.Models
[
JsonProperty
(
"fromMenus"
,
Required
=
Required
.
Always
)]
public
bool
FromMenus
{
get
;
set
;
}
public
ShoppingList
()
{
}
}
}
inutralia/inutralia/API/LocalDataService.cs
View file @
291e58b5
...
...
@@ -97,6 +97,36 @@ namespace inutralia.API
return
retVal
;
}
public
async
Task
<
int
?>
UpdateItemIngredientAsync
<
T
>(
T
item
,
bool
isNew
=
false
)
where
T
:
IIdentifiableEntity
{
if
(
isNew
)
{
// Elemento nuevo: asignarle Id. Cogemos la lista de ids ...
List
<
int
>
idList
=
GetIdList
(
item
.
GetType
());
// ... buscamos el máximo y le sumamos 1
//item.Id = (idList.Count < 1) ? 1 : idList.Max () + 1;
// ... añadimos el nuevo id a la lista
idList
.
Add
(
item
.
Id
);
// ... y la guardamos
SetIdList
(
item
.
GetType
(),
idList
);
}
else
if
(!
AppSettings
.
Contains
(
GetItemPath
(
item
)))
{
// El elemento no es nuevo, pero no existe en los datos guardados
return
null
;
}
//endif
// Guardar elemento
AppSettings
.
AddOrUpdateValue
(
GetItemPath
(
item
),
JsonConvert
.
SerializeObject
(
item
));
// Retornar su id
return
item
.
Id
;
}
public
async
Task
<
int
?>
UpdateItemAsync
<
T
>
(
T
item
,
bool
isNew
=
false
)
where
T
:
IIdentifiableEntity
{
if
(
isNew
)
...
...
@@ -105,7 +135,7 @@ namespace inutralia.API
List
<
int
>
idList
=
GetIdList
(
item
.
GetType
());
// ... buscamos el máximo y le sumamos 1
//
item.Id = (idList.Count < 1) ? 1 : idList.Max () + 1;
item
.
Id
=
(
idList
.
Count
<
1
)
?
1
:
idList
.
Max
()
+
1
;
// ... añadimos el nuevo id a la lista
idList
.
Add
(
item
.
Id
);
...
...
inutralia/inutralia/ViewModels/Menus/CustomMenuViewModel.cs
View file @
291e58b5
using
inutralia.Models
;
using
System.Threading.Tasks
;
using
MvvmHelpers
;
// Este namespace está en el paquete Refractored.MvvmHelpers
using
Xamarin.Forms
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
@@ -318,6 +316,7 @@ namespace inutralia.ViewModels
// Preparar la lista de ingredientes a partir de las recetas seleccionadas
//var ingredients = new HashSet<string>();
var
ingredients
=
new
HashSet
<
Ingredient
>();
for
(
int
i
=
0
;
i
<
_LocalMenu
?.
DaySelections
?.
Length
;
i
++)
...
...
@@ -338,7 +337,6 @@ namespace inutralia.ViewModels
// Eliminar de la lista de la compra los ingredientes que no estén en los encontrados
var
listaCompra
=
await
App
.
LocalData
.
RefreshListAsync
<
ShoppingList
>();
//foreach (var ing in listaCompra.Where(sl => sl.FromMenus && !ingredients.Contains(sl.Text)))
foreach
(
var
ing
in
listaCompra
.
Where
(
sl
=>
sl
.
FromMenus
&&
!
ingredients
.
Any
(
o
=>
o
.
Name
.
Contains
(
sl
.
Text
))))
{
...
...
@@ -348,13 +346,13 @@ namespace inutralia.ViewModels
// Añadir a la lista de la compra los que falten
//foreach (string ing in ingredients.Where (i => listaCompra.Find (sl => sl.FromMenus && sl.Text.Equals (i)) == null))
foreach
(
Ingredient
ing
in
ingredients
.
Where
(
i
=>
listaCompra
.
Find
(
sl
=>
sl
.
FromMenus
&&
sl
.
Text
.
Equals
(
i
))
==
null
))
foreach
(
Ingredient
ing
in
ingredients
.
Where
(
i
=>
listaCompra
.
Find
(
sl
=>
sl
.
FromMenus
&&
sl
.
Text
.
Equals
(
i
)
&&
sl
.
Id
.
Equals
(
i
)
)
==
null
))
{
//await App.LocalData.UpdateItemAsync(new ShoppingList() { FromMenus = true, Select = false, Text = ing }, true);
await
App
.
LocalData
.
UpdateItemAsync
(
new
ShoppingList
()
{
FromMenus
=
true
,
Select
=
false
,
Text
=
ing
.
Name
,
Id
=
ing
.
Id
},
true
);
}
//endforeach
await
App
.
LocalData
.
UpdateItemAsync
(
_LocalMenu
);
await
App
.
LocalData
.
UpdateItem
Ingredient
Async
(
_LocalMenu
);
IsBusy
=
false
;
...
...
@@ -371,8 +369,10 @@ namespace inutralia.ViewModels
{
foreach
(
var
ing
in
recipes
[
index
].
Ingredients
)
{
//ingredients.Add (ing.Name);
ingredients
.
Add
(
new
Ingredient
()
{
Name
=
ing
.
Name
,
Id
=
ing
.
Id
});
// Lambda que elimina los ingredientes que se repiten al añadir recetas
if
(!
ingredients
.
Any
(
o
=>
o
.
Name
.
Contains
(
ing
.
Name
)))
//ingredients.Add (ing.Name);
ingredients
.
Add
(
new
Ingredient
()
{
Name
=
ing
.
Name
,
Id
=
ing
.
Id
});
}
//endforeach
}
//endif
}
//endif
...
...
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