Added softkey data in the Favorite softkey API
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class FavoriteUserSoftkeysController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
|
||||
public FavoriteUserSoftkeysController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<FavoriteUserSoftkeyModel> GetUserFavoriteSoftkeys(int userId)
|
||||
{
|
||||
return dbCtx.
|
||||
FavoriteUserSoftkeys
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<FavoriteUserSoftkeyModel> InsertUserSoftkeyModel(List<uint> softKeyIds, int userId)
|
||||
{
|
||||
List<FavoriteUserSoftkeyModel> softKeys = new List<FavoriteUserSoftkeyModel>();
|
||||
// Create new list with db models
|
||||
foreach (int softKeyId in softKeyIds)
|
||||
{
|
||||
softKeys.Add(new FavoriteUserSoftkeyModel()
|
||||
{
|
||||
UserId = userId,
|
||||
SoftkeyId = softKeyId
|
||||
});
|
||||
}
|
||||
// Add list to database
|
||||
dbCtx.FavoriteUserSoftkeys.AddRange(softKeys);
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return softKeys;
|
||||
}
|
||||
|
||||
public void DeleteUserSoftkeyModel(int userId)
|
||||
{
|
||||
// Get user favorite softkeys
|
||||
List<FavoriteUserSoftkeyModel> softKeys = GetUserFavoriteSoftkeys(userId);
|
||||
|
||||
foreach(FavoriteUserSoftkeyModel sofkey in softKeys)
|
||||
{
|
||||
// Delete
|
||||
dbCtx.FavoriteUserSoftkeys.Remove(sofkey);
|
||||
}
|
||||
// Save database context
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static Step.Model.Constants;
|
||||
using static Step.Config.ServerConfig;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class UserSoftkeysController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
|
||||
public UserSoftkeysController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<DTOUserSoftKeyConfigModel> GetUserSoftkeyConfig()
|
||||
{
|
||||
List<DTOUserSoftKeyConfigModel> config = new List<DTOUserSoftKeyConfigModel>();
|
||||
|
||||
foreach (var softKey in SoftKeysConfig)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
tmpSubKey.Add(subKey.Id, subKey.Text);
|
||||
}
|
||||
}
|
||||
// Add to the category the new softkey
|
||||
config.Add(new DTOUserSoftKeyConfigModel()
|
||||
{
|
||||
Id = softKey.Id,
|
||||
Category = softKey.Category,
|
||||
OperatorConfirmationNeeded = softKey.OperatorConfirmationNeeded,
|
||||
Type = softKey.Type,
|
||||
SubKeys = tmpSubKey
|
||||
});
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public List<FavoriteUserSoftkeyModel> FindUserFavoriteSoftkeys(int userId)
|
||||
{
|
||||
return dbCtx.
|
||||
FavoriteUserSoftkeys
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DTOUserSoftKeyConfigModel> GetUserFavoriteSoftkeys(int userId)
|
||||
{
|
||||
// Find user softkey stored in the database
|
||||
List<FavoriteUserSoftkeyModel> favoriteKey = FindUserFavoriteSoftkeys(userId);
|
||||
// Get config
|
||||
List<DTOUserSoftKeyConfigModel> userSoftkey = GetUserSoftkeyConfig();
|
||||
|
||||
return userSoftkey
|
||||
.Where(x =>
|
||||
favoriteKey.Any(y => y.SoftkeyId == x.Id
|
||||
))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DTOUserSoftKeyConfigModel> InsertUserSoftkeyModel(List<uint> softKeyIds, int userId)
|
||||
{
|
||||
List<FavoriteUserSoftkeyModel> softKeys = new List<FavoriteUserSoftkeyModel>();
|
||||
// Create new list with db models
|
||||
foreach (int softKeyId in softKeyIds)
|
||||
{
|
||||
softKeys.Add(new FavoriteUserSoftkeyModel()
|
||||
{
|
||||
UserId = userId,
|
||||
SoftkeyId = softKeyId
|
||||
});
|
||||
}
|
||||
|
||||
// Add list to database
|
||||
dbCtx.FavoriteUserSoftkeys.AddRange(softKeys);
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetUserFavoriteSoftkeys(userId);
|
||||
}
|
||||
|
||||
public void DeleteUserSoftkeyModel(int userId)
|
||||
{
|
||||
// Get user favorite softkeys
|
||||
List<FavoriteUserSoftkeyModel> softKeys = FindUserFavoriteSoftkeys(userId);
|
||||
|
||||
foreach(FavoriteUserSoftkeyModel sofkey in softKeys)
|
||||
{
|
||||
// Delete
|
||||
dbCtx.FavoriteUserSoftkeys.Remove(sofkey);
|
||||
}
|
||||
// Save database context
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\FavoriteUserSoftkeysController.cs" />
|
||||
<Compile Include="Controllers\UserSoftkeysController.cs" />
|
||||
<Compile Include="Controllers\FunctionsAccessController.cs" />
|
||||
<Compile Include="Controllers\MachinesController.cs" />
|
||||
<Compile Include="Controllers\MaintenancesController.cs" />
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,7 +23,7 @@ namespace Step.Controllers.WebApi
|
||||
// Find user id from the bearer token
|
||||
var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault();
|
||||
int userIdInt = Convert.ToInt32(userId.Value);
|
||||
using (FavoriteUserSoftkeysController controller = new FavoriteUserSoftkeysController())
|
||||
using (UserSoftkeysController controller = new UserSoftkeysController())
|
||||
{
|
||||
return Ok(
|
||||
controller.GetUserFavoriteSoftkeys(userIdInt)
|
||||
@@ -38,11 +39,11 @@ namespace Step.Controllers.WebApi
|
||||
|
||||
var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault();
|
||||
int intUserId = Convert.ToInt32(userId.Value);
|
||||
using (FavoriteUserSoftkeysController controller = new FavoriteUserSoftkeysController())
|
||||
using (UserSoftkeysController controller = new UserSoftkeysController())
|
||||
{
|
||||
// Delete saved softkey
|
||||
controller.DeleteUserSoftkeyModel(intUserId);
|
||||
List<FavoriteUserSoftkeyModel> favorite = new List<FavoriteUserSoftkeyModel>();
|
||||
List<DTOUserSoftKeyConfigModel> favorite = new List<DTOUserSoftKeyConfigModel>();
|
||||
if (favoriteSoftkeyIds != null && favoriteSoftkeyIds.Count > 0)
|
||||
{
|
||||
// Insert new list of id
|
||||
|
||||
Reference in New Issue
Block a user