mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Fix changes to companies service affecting company view.
This commit is contained in:
@@ -68,14 +68,18 @@ namespace Marechai.Services
|
||||
public Task<CompanyViewModel> GetAsync(int id) => _context.Companies.Where(c => c.Id == id).
|
||||
Select(c => new CompanyViewModel
|
||||
{
|
||||
Id = c.Id, Name = c.Name, Founded = c.Founded,
|
||||
Sold = c.Sold, SoldToId = c.SoldToId,
|
||||
CountryId = c.CountryId, Status = c.Status,
|
||||
Website = c.Website, Twitter = c.Twitter,
|
||||
Facebook = c.Facebook, Address = c.Address,
|
||||
City = c.City, Province = c.Province,
|
||||
Id = c.Id,
|
||||
LastLogo = c.
|
||||
Logos.OrderByDescending(l => l.Year).
|
||||
FirstOrDefault().Guid,
|
||||
Name = c.Name, Founded = c.Founded,
|
||||
Sold = c.Sold, SoldToId = c.SoldToId,
|
||||
CountryId = c.CountryId, Status = c.Status,
|
||||
Website = c.Website, Twitter = c.Twitter,
|
||||
Facebook = c.Facebook, Address = c.Address,
|
||||
City = c.City, Province = c.Province,
|
||||
PostalCode = c.PostalCode,
|
||||
Country = c.Country.Name
|
||||
Country = c.Country.Name
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
public async Task UpdateAsync(CompanyViewModel viewModel)
|
||||
@@ -102,6 +106,23 @@ namespace Marechai.Services
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(CompanyViewModel viewModel)
|
||||
{
|
||||
var model = new Company
|
||||
{
|
||||
Name = viewModel.Name, Founded = viewModel.Founded, Sold = viewModel.Sold,
|
||||
SoldToId = viewModel.SoldToId, CountryId = viewModel.CountryId, Status = viewModel.Status,
|
||||
Website = viewModel.Website, Twitter = viewModel.Twitter, Facebook = viewModel.Facebook,
|
||||
Address = viewModel.Address, City = viewModel.City, Province = viewModel.Province,
|
||||
PostalCode = viewModel.PostalCode
|
||||
};
|
||||
|
||||
await _context.Companies.AddAsync(model);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return model.Id;
|
||||
}
|
||||
|
||||
public async Task<List<Machine>> GetMachinesAsync(int id) =>
|
||||
await _context.Machines.Where(m => m.CompanyId == id).OrderBy(m => m.Name).Select(m => new Machine
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user