2020-08-09 02:41:00 +01:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
// MARECHAI: Master repository of computing history artifacts information
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:24:15 +00:00
|
|
|
|
// Copyright © 2003-2021 Natalia Portillo
|
2020-08-09 02:41:00 +01:00
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Marechai.Database.Models;
|
|
|
|
|
|
using Marechai.ViewModels;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
namespace Marechai.Services;
|
|
|
|
|
|
|
|
|
|
|
|
public class SoftwareVariantsService(MarechaiContext context)
|
2020-08-09 02:41:00 +01:00
|
|
|
|
{
|
2025-11-13 04:05:35 +00:00
|
|
|
|
public async Task<List<SoftwareVariantViewModel>> GetAsync() => await context.SoftwareVariants
|
|
|
|
|
|
.OrderBy(b => b.SoftwareVersion.Family.Name)
|
|
|
|
|
|
.ThenBy(b => b.SoftwareVersion.Version)
|
|
|
|
|
|
.ThenBy(b => b.Name)
|
|
|
|
|
|
.ThenBy(b => b.Version)
|
|
|
|
|
|
.ThenBy(b => b.Introduced)
|
|
|
|
|
|
.Select(b => new SoftwareVariantViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = b.Id,
|
|
|
|
|
|
Name = b.Name,
|
|
|
|
|
|
Version = b.Version,
|
|
|
|
|
|
Introduced = b.Introduced,
|
|
|
|
|
|
ParentId = b.ParentId,
|
|
|
|
|
|
Parent = b.Parent.Name ?? b.Parent.Version,
|
|
|
|
|
|
SoftwareVersionId = b.SoftwareVersionId,
|
|
|
|
|
|
SoftwareVersion =
|
|
|
|
|
|
b.SoftwareVersion.Name ??
|
|
|
|
|
|
b.SoftwareVersion.Version,
|
|
|
|
|
|
MinimumMemory = b.MinimumMemory,
|
|
|
|
|
|
RecommendedMemory = b.RecommendedMemory,
|
|
|
|
|
|
RequiredStorage = b.RequiredStorage,
|
|
|
|
|
|
PartNumber = b.PartNumber,
|
|
|
|
|
|
SerialNumber = b.SerialNumber,
|
|
|
|
|
|
ProductCode = b.ProductCode,
|
|
|
|
|
|
CatalogueNumber = b.CatalogueNumber,
|
|
|
|
|
|
DistributionMode = b.DistributionMode
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<SoftwareVariantViewModel> GetAsync(ulong id) => await context.SoftwareVariants
|
|
|
|
|
|
.Where(b => b.Id == id)
|
|
|
|
|
|
.Select(b => new SoftwareVariantViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = b.Id,
|
|
|
|
|
|
Name = b.Name,
|
|
|
|
|
|
Version = b.Version,
|
|
|
|
|
|
Introduced = b.Introduced,
|
|
|
|
|
|
ParentId = b.ParentId,
|
|
|
|
|
|
Parent =
|
|
|
|
|
|
b.Parent.Name ?? b.Parent.Version,
|
|
|
|
|
|
SoftwareVersionId = b.SoftwareVersionId,
|
|
|
|
|
|
SoftwareVersion =
|
|
|
|
|
|
b.SoftwareVersion.Name ??
|
|
|
|
|
|
b.SoftwareVersion.Version,
|
|
|
|
|
|
MinimumMemory = b.MinimumMemory,
|
|
|
|
|
|
RecommendedMemory = b.RecommendedMemory,
|
|
|
|
|
|
RequiredStorage = b.RequiredStorage,
|
|
|
|
|
|
PartNumber = b.PartNumber,
|
|
|
|
|
|
SerialNumber = b.SerialNumber,
|
|
|
|
|
|
ProductCode = b.ProductCode,
|
|
|
|
|
|
CatalogueNumber = b.CatalogueNumber,
|
|
|
|
|
|
DistributionMode = b.DistributionMode
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsync(SoftwareVariantViewModel viewModel, string userId)
|
2020-08-09 02:41:00 +01:00
|
|
|
|
{
|
2025-11-13 04:05:35 +00:00
|
|
|
|
SoftwareVariant model = await context.SoftwareVariants.FindAsync(viewModel.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if(model is null) return;
|
|
|
|
|
|
|
|
|
|
|
|
model.Name = viewModel.Name;
|
|
|
|
|
|
model.Version = viewModel.Version;
|
|
|
|
|
|
model.Introduced = viewModel.Introduced;
|
|
|
|
|
|
model.ParentId = viewModel.ParentId;
|
|
|
|
|
|
model.SoftwareVersionId = viewModel.SoftwareVersionId;
|
|
|
|
|
|
model.MinimumMemory = viewModel.MinimumMemory;
|
|
|
|
|
|
model.RecommendedMemory = viewModel.RecommendedMemory;
|
|
|
|
|
|
model.RequiredStorage = viewModel.RequiredStorage;
|
|
|
|
|
|
model.PartNumber = viewModel.PartNumber;
|
|
|
|
|
|
model.SerialNumber = viewModel.SerialNumber;
|
|
|
|
|
|
model.ProductCode = viewModel.ProductCode;
|
|
|
|
|
|
model.CatalogueNumber = viewModel.CatalogueNumber;
|
|
|
|
|
|
model.DistributionMode = viewModel.DistributionMode;
|
|
|
|
|
|
|
|
|
|
|
|
await context.SaveChangesWithUserAsync(userId);
|
|
|
|
|
|
}
|
2020-08-09 02:41:00 +01:00
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
public async Task<ulong> CreateAsync(SoftwareVariantViewModel viewModel, string userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var model = new SoftwareVariant
|
2020-08-09 02:41:00 +01:00
|
|
|
|
{
|
2025-11-13 04:05:35 +00:00
|
|
|
|
Name = viewModel.Name,
|
|
|
|
|
|
Version = viewModel.Version,
|
|
|
|
|
|
Introduced = viewModel.Introduced,
|
|
|
|
|
|
ParentId = viewModel.ParentId,
|
|
|
|
|
|
SoftwareVersionId = viewModel.SoftwareVersionId,
|
|
|
|
|
|
MinimumMemory = viewModel.MinimumMemory,
|
|
|
|
|
|
RecommendedMemory = viewModel.RecommendedMemory,
|
|
|
|
|
|
RequiredStorage = viewModel.RequiredStorage,
|
|
|
|
|
|
PartNumber = viewModel.PartNumber,
|
|
|
|
|
|
SerialNumber = viewModel.SerialNumber,
|
|
|
|
|
|
ProductCode = viewModel.ProductCode,
|
|
|
|
|
|
CatalogueNumber = viewModel.CatalogueNumber,
|
|
|
|
|
|
DistributionMode = viewModel.DistributionMode
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await context.SoftwareVariants.AddAsync(model);
|
|
|
|
|
|
await context.SaveChangesWithUserAsync(userId);
|
|
|
|
|
|
|
|
|
|
|
|
return model.Id;
|
|
|
|
|
|
}
|
2020-08-09 02:41:00 +01:00
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
public async Task DeleteAsync(ulong id, string userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
SoftwareVariant item = await context.SoftwareVariants.FindAsync(id);
|
2020-08-09 02:41:00 +01:00
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
if(item is null) return;
|
2020-08-09 02:41:00 +01:00
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
context.SoftwareVariants.Remove(item);
|
2020-08-09 02:41:00 +01:00
|
|
|
|
|
2025-11-13 04:05:35 +00:00
|
|
|
|
await context.SaveChangesWithUserAsync(userId);
|
2020-08-09 02:41:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|