Add instance model, dto, controller and service + update other objects and controllers
This commit is contained in:
parent
35e2d8296b
commit
3b6c480cc6
@ -20,5 +20,6 @@ namespace Manager.Interfaces.DTO
|
||||
public bool isOffline { get; set; } // MyVisit - True if MyVisit is full offline
|
||||
/*public string latitude { get; set; } // MyVisit - latitude of visit ? (MyVisit)
|
||||
public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ namespace Manager.Interfaces.DTO
|
||||
public bool connected{ get; set; }
|
||||
public DateTime dateCreation{ get; set; }
|
||||
public DateTime dateUpdate { get; set; }
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceDetailDTO : DeviceDTO
|
||||
|
||||
13
Manager.Interfaces/DTO/InstanceDTO.cs
Normal file
13
Manager.Interfaces/DTO/InstanceDTO.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class InstanceDTO
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public DateTime dateCreation { get; set; }
|
||||
}
|
||||
}
|
||||
@ -12,5 +12,6 @@ namespace Manager.Interfaces.DTO
|
||||
public string label { get; set; }
|
||||
public DateTime dateCreation { get; set; }
|
||||
public string data { get; set; }
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,5 +20,6 @@ namespace Manager.Interfaces.DTO
|
||||
public string data { get; set; } // == Include section type info
|
||||
public DateTime dateCreation { get; set; } // == Include section type info
|
||||
public int order { get; set; } // Order to show
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,5 +10,6 @@ namespace Manager.Interfaces.DTO
|
||||
public string token_type { get; set; }
|
||||
public int expires_in { get; set; }
|
||||
public DateTimeOffset expiration { get; set; }
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,10 @@ namespace Manager.Interfaces.Models
|
||||
[BsonElement("IsOffline")]
|
||||
public bool IsOffline { get; set; }
|
||||
|
||||
[BsonElement("InstanceId")]
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public ConfigurationDTO ToDTO()
|
||||
{
|
||||
return new ConfigurationDTO()
|
||||
@ -65,7 +69,8 @@ namespace Manager.Interfaces.Models
|
||||
secondaryColor = SecondaryColor,
|
||||
isMobile = IsMobile,
|
||||
isTablet = IsTablet,
|
||||
isOffline = IsOffline
|
||||
isOffline = IsOffline,
|
||||
instanceId = InstanceId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -85,7 +90,8 @@ namespace Manager.Interfaces.Models
|
||||
isTablet = IsTablet,
|
||||
isOffline = IsOffline,
|
||||
sections = sections,
|
||||
resources = resources
|
||||
resources = resources,
|
||||
instanceId = InstanceId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +60,9 @@ namespace Manager.Interfaces.Models
|
||||
[BsonElement("LastConnectionLevel")]
|
||||
public DateTime LastConnectionLevel { get; set; }
|
||||
|
||||
[BsonElement("InstanceId")]
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public DeviceDTO ToDTO()
|
||||
{
|
||||
@ -74,7 +77,8 @@ namespace Manager.Interfaces.Models
|
||||
configuration = Configuration,
|
||||
configurationId = ConfigurationId,
|
||||
dateUpdate = DateUpdate,
|
||||
dateCreation = DateCreation
|
||||
dateCreation = DateCreation,
|
||||
instanceId = InstanceId
|
||||
};
|
||||
}
|
||||
|
||||
@ -95,7 +99,8 @@ namespace Manager.Interfaces.Models
|
||||
batteryLevel = BatteryLevel,
|
||||
lastBatteryLevel = LastBatteryLevel,
|
||||
dateUpdate = DateUpdate,
|
||||
dateCreation = DateCreation
|
||||
dateCreation = DateCreation,
|
||||
instanceId = InstanceId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
36
Manager.Interfaces/Models/Instance.cs
Normal file
36
Manager.Interfaces/Models/Instance.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Manager.Interfaces.DTO;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Instance Information
|
||||
/// </summary>
|
||||
public class Instance
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
[BsonRequired]
|
||||
public string Name { get; set; } // UNIQUE !..
|
||||
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
public InstanceDTO ToDTO()
|
||||
{
|
||||
return new InstanceDTO()
|
||||
{
|
||||
id = Id,
|
||||
name = Name,
|
||||
dateCreation = DateCreation
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -31,6 +31,10 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string Data { get; set; }
|
||||
|
||||
[BsonElement("InstanceId")]
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public ResourceDTO ToDTO(bool isExport = false)
|
||||
{
|
||||
return new ResourceDTO()
|
||||
|
||||
@ -61,6 +61,10 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string Data { get; set; } // Json encapsulated section info
|
||||
|
||||
[BsonElement("InstanceId")]
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public SectionDTO ToDTO()
|
||||
{
|
||||
return new SectionDTO()
|
||||
|
||||
@ -38,6 +38,10 @@ namespace Manager.Interfaces.Models
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
[BsonElement("InstanceId")]
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public UserDetailDTO ToDTO()
|
||||
{
|
||||
return new UserDetailDTO()
|
||||
|
||||
@ -42,15 +42,16 @@ namespace ManagerService.Controllers
|
||||
/// <summary>
|
||||
/// Get a list of all configuration (summary)
|
||||
/// </summary>
|
||||
/// <param name="id">id instance</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(List<ConfigurationDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
public ObjectResult Get([FromQuery] string instanceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Configuration> configurations = _configurationService.GetAll();
|
||||
List<Configuration> configurations = _configurationService.GetAll(instanceId);
|
||||
|
||||
return new OkObjectResult(configurations.Select(r => r.ToDTO()));
|
||||
}
|
||||
|
||||
@ -37,14 +37,15 @@ namespace ManagerService.Controllers
|
||||
/// <summary>
|
||||
/// Get a list of all devices
|
||||
/// </summary>
|
||||
/// <param name="id">id instance</param>
|
||||
[ProducesResponseType(typeof(List<DeviceDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
public ObjectResult Get([FromQuery] string instanceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Device> devices = _deviceService.GetAll();
|
||||
List<Device> devices = _deviceService.GetAll(instanceId);
|
||||
|
||||
return new OkObjectResult(devices.Select(d => d.ToDTO()));
|
||||
}
|
||||
|
||||
216
ManagerService/Controllers/InstanceController.cs
Normal file
216
ManagerService/Controllers/InstanceController.cs
Normal file
@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Manager.Framework.Business;
|
||||
using Manager.Interfaces.DTO;
|
||||
using Manager.Interfaces.Models;
|
||||
using Manager.Services;
|
||||
using ManagerService.Service.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSwag.Annotations;
|
||||
|
||||
namespace ManagerService.Controllers
|
||||
{
|
||||
[Authorize] // TODO Add ROLES (Roles = "Admin")
|
||||
[ApiController, Route("api/[controller]")]
|
||||
[OpenApiTag("Instance", Description = "Instance management")]
|
||||
public class InstanceController : ControllerBase
|
||||
{
|
||||
private InstanceDatabaseService _instanceService;
|
||||
private UserDatabaseService _userService;
|
||||
private readonly ILogger<InstanceController> _logger;
|
||||
private readonly ProfileLogic _profileLogic;
|
||||
|
||||
public InstanceController(ILogger<InstanceController> logger, InstanceDatabaseService instanceService, UserDatabaseService userService, ProfileLogic profileLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_instanceService = instanceService;
|
||||
_userService = userService;
|
||||
_profileLogic = profileLogic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of instance
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<Instance>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Instance> instances = _instanceService.GetAll();
|
||||
|
||||
return new OkObjectResult(instances);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific instance
|
||||
/// </summary>
|
||||
/// <param name="id">id instance</param>
|
||||
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{id}")]
|
||||
public ObjectResult GetDetail(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Instance instance = _instanceService.GetById(id);
|
||||
|
||||
if (instance == null)
|
||||
throw new KeyNotFoundException("This instance was not found");
|
||||
|
||||
return new OkObjectResult(instance.ToDTO());
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance
|
||||
/// </summary>
|
||||
/// <param name="newInstance">New instance info</param>
|
||||
//[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 409)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPost]
|
||||
public ObjectResult CreateInstance([FromBody] Instance newInstance)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newInstance == null)
|
||||
throw new ArgumentNullException("instance param is null");
|
||||
|
||||
newInstance.DateCreation = DateTime.Now;
|
||||
|
||||
List<Instance> instances = _instanceService.GetAll();
|
||||
|
||||
if (instances.Select(i => i.Name).Contains(newInstance.Name))
|
||||
throw new InvalidOperationException("This name is already used");
|
||||
|
||||
Instance instanceCreated = _instanceService.Create(newInstance);
|
||||
|
||||
return new OkObjectResult(instanceCreated.ToDTO());
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return new ConflictObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update an instance
|
||||
/// </summary>
|
||||
/// <param name="updatedinstance">instance to update</param>
|
||||
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPut]
|
||||
public ObjectResult Updateinstance([FromBody] Instance updatedInstance)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updatedInstance == null)
|
||||
throw new ArgumentNullException("instance param is null");
|
||||
|
||||
Instance instance = _instanceService.GetById(updatedInstance.Id);
|
||||
|
||||
if (instance == null)
|
||||
throw new KeyNotFoundException("instance does not exist");
|
||||
|
||||
Instance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
||||
|
||||
return new OkObjectResult(instanceModified.ToDTO());
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete an instance
|
||||
/// </summary>
|
||||
/// <param name="id">Id of instance to delete</param>
|
||||
[ProducesResponseType(typeof(string), 202)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpDelete("{id}")]
|
||||
public ObjectResult DeleteInstance(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id == null)
|
||||
throw new ArgumentNullException("instance param is null");
|
||||
|
||||
Instance instance = _instanceService.GetById(id);
|
||||
|
||||
// Delete all user in instance
|
||||
List<User> users = _userService.GetByInstanceId(instance.Id);
|
||||
|
||||
foreach(var user in users)
|
||||
{
|
||||
_userService.Remove(user.Id);
|
||||
}
|
||||
|
||||
if (instance == null)
|
||||
throw new KeyNotFoundException("instance does not exist");
|
||||
|
||||
_instanceService.Remove(id);
|
||||
|
||||
return new ObjectResult("The instance has been deleted") { StatusCode = 202 };
|
||||
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,14 +39,15 @@ namespace ManagerService.Controllers
|
||||
/// <summary>
|
||||
/// Get a list of all resources (summary)
|
||||
/// </summary>
|
||||
/// <param name="id">id instance</param>
|
||||
[ProducesResponseType(typeof(List<ResourceDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
public ObjectResult Get([FromQuery] string instanceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Resource> resources = _resourceService.GetAll();
|
||||
List<Resource> resources = _resourceService.GetAll(instanceId);
|
||||
|
||||
return new OkObjectResult(resources.Select(r => r.ToDTO(r.Type == ResourceType.ImageUrl)));
|
||||
}
|
||||
@ -135,15 +136,12 @@ namespace ManagerService.Controllers
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPost("upload"), DisableRequestSizeLimit]
|
||||
public IActionResult Upload([FromForm] string label, [FromForm] string type) // Create but with local //[FromBody] ResourceDetailDTO uploadResource
|
||||
public IActionResult Upload([FromForm] string label, [FromForm] string type, [FromForm] string instanceId) // Create but with local //[FromBody] ResourceDetailDTO uploadResource
|
||||
{
|
||||
try
|
||||
{
|
||||
if (label == null || type == null)
|
||||
if (label == null || type == null || instanceId == null)
|
||||
throw new ArgumentNullException("One of resource params is null");
|
||||
ResourceDTO uploadResource = new ResourceDTO();
|
||||
uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type);
|
||||
uploadResource.label = label;
|
||||
|
||||
List<Resource> resources = new List<Resource>();
|
||||
|
||||
@ -163,10 +161,11 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
// Todo add some verification ?
|
||||
Resource resource = new Resource();
|
||||
resource.Label = uploadResource.label;
|
||||
resource.Type = uploadResource.type;
|
||||
resource.Label = label;
|
||||
resource.Type = (ResourceType)Enum.Parse(typeof(ResourceType), type);
|
||||
resource.DateCreation = DateTime.Now;
|
||||
resource.Data = stringResult;
|
||||
resource.InstanceId = instanceId;
|
||||
Resource resourceCreated = _resourceService.Create(resource);
|
||||
resources.Add(resourceCreated);
|
||||
}
|
||||
@ -209,6 +208,7 @@ namespace ManagerService.Controllers
|
||||
resource.Type = newResource.type;
|
||||
resource.DateCreation = DateTime.Now;
|
||||
resource.Data = newResource.data;
|
||||
resource.InstanceId = newResource.instanceId;
|
||||
|
||||
Resource resourceCreated = _resourceService.Create(resource);
|
||||
|
||||
@ -290,12 +290,13 @@ namespace ManagerService.Controllers
|
||||
if (id == null)
|
||||
throw new ArgumentNullException("Resource param is null");
|
||||
|
||||
if (!_resourceService.IsExist(id))
|
||||
var ressource = _resourceService.GetById(id);
|
||||
if (ressource == null)
|
||||
throw new KeyNotFoundException("Resource does not exist");
|
||||
|
||||
|
||||
// Delete all resource occurence
|
||||
foreach (var section in _sectionService.GetAll())
|
||||
foreach (var section in _sectionService.GetAll(ressource.InstanceId))
|
||||
{
|
||||
if (section.ImageId == id)
|
||||
{
|
||||
|
||||
@ -35,14 +35,15 @@ namespace ManagerService.Controllers
|
||||
/// <summary>
|
||||
/// Get a list of all section (summary)
|
||||
/// </summary>
|
||||
/// <param name="id">id instance</param>
|
||||
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
public ObjectResult Get([FromQuery] string instanceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Section> sections = _sectionService.GetAll();
|
||||
List<Section> sections = _sectionService.GetAll(instanceId);
|
||||
|
||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||
}
|
||||
|
||||
@ -18,9 +18,9 @@ namespace Manager.Services
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Configurations = database.GetCollection<Configuration>("Configurations");
|
||||
}
|
||||
public List<Configuration> GetAll()
|
||||
public List<Configuration> GetAll(string instanceId)
|
||||
{
|
||||
return _Configurations.Find(d => true).ToList();
|
||||
return _Configurations.Find(d => d.InstanceId == instanceId).ToList();
|
||||
}
|
||||
|
||||
public Configuration GetById(string id)
|
||||
|
||||
@ -19,9 +19,9 @@ namespace Manager.Services
|
||||
_Devices = database.GetCollection<Device>("Devices");
|
||||
}
|
||||
|
||||
public List<Device> GetAll()
|
||||
public List<Device> GetAll(string instanceId)
|
||||
{
|
||||
return _Devices.Find(d => true).ToList();
|
||||
return _Devices.Find(d => d.InstanceId == instanceId).ToList();
|
||||
}
|
||||
|
||||
public List<Device> GetAllConnected()
|
||||
|
||||
59
ManagerService/Services/InstanceDatabaseService.cs
Normal file
59
ManagerService/Services/InstanceDatabaseService.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Manager.Interfaces.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Manager.Services
|
||||
{
|
||||
public class InstanceDatabaseService
|
||||
{
|
||||
private readonly IMongoCollection<Instance> _Instances;
|
||||
|
||||
public InstanceDatabaseService(IConfiguration config)
|
||||
{
|
||||
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Instances = database.GetCollection<Instance>("Instances");
|
||||
}
|
||||
public List<Instance> GetAll()
|
||||
{
|
||||
return _Instances.Find(m => true).ToList();
|
||||
}
|
||||
|
||||
public Instance GetByName(string name)
|
||||
{
|
||||
return _Instances.Find<Instance>(i => i.Name == name).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Instance GetById(string id)
|
||||
{
|
||||
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault() != null ? true : false;
|
||||
}
|
||||
|
||||
public Instance Create(Instance instance)
|
||||
{
|
||||
_Instances.InsertOne(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Instance Update(string id, Instance instanceIn)
|
||||
{
|
||||
_Instances.ReplaceOne(instance => instance.Id == id, instanceIn);
|
||||
return instanceIn;
|
||||
}
|
||||
|
||||
public void Remove(string id)
|
||||
{
|
||||
_Instances.DeleteOne(instance => instance.Id == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -18,9 +18,9 @@ namespace Manager.Services
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Resources = database.GetCollection<Resource>("Resources");
|
||||
}
|
||||
public List<Resource> GetAll()
|
||||
public List<Resource> GetAll(string instanceId)
|
||||
{
|
||||
return _Resources.Find(r => true).ToList();
|
||||
return _Resources.Find(r => r.InstanceId == instanceId).ToList();
|
||||
}
|
||||
|
||||
public Resource GetByType(ResourceType type)
|
||||
|
||||
@ -19,9 +19,9 @@ namespace Manager.Services
|
||||
_Sections = database.GetCollection<Section>("Sections");
|
||||
}
|
||||
|
||||
public List<Section> GetAll()
|
||||
public List<Section> GetAll(string instanceId)
|
||||
{
|
||||
return _Sections.Find(s => !s.IsSubSection).ToList();
|
||||
return _Sections.Find(s => !s.IsSubSection && s.InstanceId == instanceId).ToList();
|
||||
}
|
||||
|
||||
public List<Section> GetAllFromConfiguration(string configurationId)
|
||||
|
||||
@ -79,7 +79,8 @@ namespace ManagerService.Service.Services
|
||||
expires_in = _tokenSettings.AccessTokenExpiration * 60,
|
||||
expiration = new DateTimeOffset(token.ValidTo),
|
||||
token_type = "Bearer",
|
||||
scope = Security.Scope
|
||||
scope = Security.Scope,
|
||||
instanceId = user.InstanceId
|
||||
};
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
|
||||
@ -20,22 +20,27 @@ namespace Manager.Services
|
||||
}
|
||||
public List<User> GetAll()
|
||||
{
|
||||
return _Users.Find(m => true).ToList();
|
||||
return _Users.Find(u => true).ToList();
|
||||
}
|
||||
|
||||
public User GetByEmail(string email)
|
||||
{
|
||||
return _Users.Find<User>(m => m.Email == email).FirstOrDefault();
|
||||
return _Users.Find<User>(u => u.Email == email).FirstOrDefault();
|
||||
}
|
||||
|
||||
public User GetById(string id)
|
||||
{
|
||||
return _Users.Find<User>(m => m.Id == id).FirstOrDefault();
|
||||
return _Users.Find<User>(u => u.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<User> GetByInstanceId(string id)
|
||||
{
|
||||
return _Users.Find<User>(u => u.InstanceId == id).ToList();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Users.Find<User>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
||||
return _Users.Find<User>(u => u.Id == id).FirstOrDefault() != null ? true : false;
|
||||
}
|
||||
|
||||
public User Create(User user)
|
||||
|
||||
@ -141,6 +141,7 @@ namespace ManagerService
|
||||
services.AddScoped<ResourceDatabaseService>();
|
||||
services.AddScoped<LanguageInit>();
|
||||
services.AddScoped<DeviceDatabaseService>();
|
||||
services.AddScoped<InstanceDatabaseService>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
"ConnectionStrings": {
|
||||
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV
|
||||
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas
|
||||
//"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas
|
||||
"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas
|
||||
//"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF
|
||||
"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017" //PROD MyMuseum
|
||||
//"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017" //PROD MyMuseum
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user