Added favorite softkey API
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user