152 lines
3.6 KiB
C#
152 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using VAR.Focus.Web.Code.Entities;
|
|
|
|
namespace VAR.Focus.Web.Code.BusinessLogic
|
|
{
|
|
public class Boards
|
|
{
|
|
#region Declarations
|
|
|
|
private static Boards _currentInstance = null;
|
|
|
|
private List<Board> _boards = new List<Board>();
|
|
private int _lastIDBoard=0;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public static Boards Current
|
|
{
|
|
get
|
|
{
|
|
if (_currentInstance == null)
|
|
{
|
|
_currentInstance = new Boards();
|
|
}
|
|
return _currentInstance;
|
|
}
|
|
set { _currentInstance = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Life cycle
|
|
|
|
public Boards()
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public methods
|
|
|
|
public List<Board> Boards_GetListForUser(string userName)
|
|
{
|
|
// FIXME: filter by permissions
|
|
return _boards.Where(board => board.Active).ToList();
|
|
}
|
|
|
|
public Board Board_GetByIDBoard(int idBoard)
|
|
{
|
|
foreach (Board board in _boards)
|
|
{
|
|
if (board.IDBoard == idBoard)
|
|
{
|
|
return board;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Board Boards_SetBoard(int idBoard, string title, string description, string userName)
|
|
{
|
|
DateTime currentDate = DateTime.UtcNow;
|
|
Board board;
|
|
if (idBoard == 0)
|
|
{
|
|
lock (this)
|
|
{
|
|
_lastIDBoard++;
|
|
board = new Board();
|
|
board.IDBoard = _lastIDBoard;
|
|
board.CreatedBy = userName;
|
|
board.CreatedDate = currentDate;
|
|
_boards.Add(board);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
board = Board_GetByIDBoard(idBoard);
|
|
}
|
|
|
|
board.Title = title;
|
|
board.Description = description;
|
|
|
|
board.Active = true;
|
|
board.ModifiedBy = userName;
|
|
board.ModifiedDate = currentDate;
|
|
|
|
SaveData();
|
|
|
|
return board;
|
|
}
|
|
|
|
public bool Boards_DelBoard(int idBoard, string userName)
|
|
{
|
|
DateTime currentDate = DateTime.UtcNow;
|
|
Board board;
|
|
if (idBoard == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
board = Board_GetByIDBoard(idBoard);
|
|
}
|
|
if (board == null) { return false; }
|
|
|
|
board.Active = false;
|
|
board.ModifiedBy = userName;
|
|
board.ModifiedDate = currentDate;
|
|
|
|
SaveData();
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private methods
|
|
|
|
#region Persistence
|
|
|
|
private const string BoardsPersistenceFile = "boards";
|
|
|
|
private void LoadData()
|
|
{
|
|
_boards = Persistence.LoadList<Board>(BoardsPersistenceFile);
|
|
_lastIDBoard = 0;
|
|
foreach (Board board in _boards)
|
|
{
|
|
if (board.IDBoard > _lastIDBoard)
|
|
{
|
|
_lastIDBoard = board.IDBoard;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SaveData()
|
|
{
|
|
Persistence.SaveList(BoardsPersistenceFile, _boards);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|