Added softkey data in the Favorite softkey API

This commit is contained in:
Lucio Maranta
2018-07-12 15:54:46 +02:00
parent e81e705f78
commit 9f5dadfc49
5 changed files with 136 additions and 97 deletions
@@ -1,4 +1,5 @@
using Step.Model.DTOModels;
using Step.Database.Controllers;
using Step.Model.DTOModels;
using Step.NC;
using System.Collections.Generic;
using System.Linq;
@@ -53,38 +54,27 @@ namespace Step.Controllers.WebApi
[Route("softKeys"), HttpGet]
public IHttpActionResult GetUserSoftKeysConfig()
{
Dictionary<int, List<DTOUserSoftKeyConfigModel>> output = new Dictionary<int, List<DTOUserSoftKeyConfigModel>>();
foreach (var softKey in SoftKeysConfig)
Dictionary<int, List<DTOUserSoftKeyConfigModel>> config = new Dictionary<int, List<DTOUserSoftKeyConfigModel>>();
using (UserSoftkeysController controller = new UserSoftkeysController())
{
// Check if category exists
if (!output.ContainsKey(softKey.Category))
List<DTOUserSoftKeyConfigModel> softkeys = controller.GetUserSoftkeyConfig();
// Organize by category
foreach (var softkey in softkeys)
{
// Add category if not exits
output.Add(softKey.Category, new List<DTOUserSoftKeyConfigModel>());
}
// Create subkeys dictionary for group
Dictionary<int, string> tmpSubKey = new Dictionary<int, string>();
if (softKey.Type == SOFTKEY_TYPE.GROUP && softKey.SubKeys != null)
{
tmpSubKey = new Dictionary<int, string>();
foreach (var subKey in softKey.SubKeys)
// Check if category exists
if (!config.ContainsKey(softkey.Category))
{
tmpSubKey.Add(subKey.Id, subKey.Text);
// Add category if not exits
config.Add(softkey.Category, new List<DTOUserSoftKeyConfigModel>());
}
}
// Add to the category the new softkey
output[softKey.Category].Add(new DTOUserSoftKeyConfigModel()
{
Id = softKey.Id,
Category = softKey.Category,
OperatorConfirmationNeeded = softKey.OperatorConfirmationNeeded,
Type = softKey.Type,
SubKeys = tmpSubKey
});
}
return Ok(output);
// Add to the category the new softkey
config[softkey.Category].Add(softkey);
}
}
return Ok(config);
}
[Route("heads"), HttpGet]