source: Application/Dal/ApplicationStorage/DataAccess/Concrete/AdministratorDa.cs

Last change on this file was f5f7c24, checked in by 192011 <mk.snicker@…>, 17 months ago

Initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1using Dal.ApplicationStorage.DataAccess.Abstract;
2using Microsoft.EntityFrameworkCore;
3using Microsoft.Extensions.Logging;
4using Models.DataTransferObjects.Administrator;
5using Models.DataTransferObjects.Company;
6using System;
7using System.Collections.Generic;
8using System.Linq;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace Dal.ApplicationStorage.DataAccess.Concrete
13{
14 public class AdministratorDa : IAdministrator
15 {
16 private readonly ApiContext _db;
17 private static ILogger<AdministratorDa> _logger;
18
19 public AdministratorDa(ApiContext db,ILogger<AdministratorDa> logger)
20 {
21 _db = db;
22 _logger = logger;
23 }
24
25 public async Task<List<AdministratorCompaniesDTO>> GetAllCompanies()
26 {
27 try
28 {
29 var companies = new List<AdministratorCompaniesDTO>();
30 var companiesFromDb = await _db.Companies.Include(x => x.BusinessUser.User).ToListAsync();
31 foreach (var company in companiesFromDb)
32 {
33
34 companies.Add(new AdministratorCompaniesDTO()
35 {
36 CompanyEmail = company.CompanyEmail,
37 CompanyName = company.CompanyName,
38 CompanyId = company.CompanyId,
39 IsApproved = company.AdministratorId != null ? true : false,
40 BusinessUserId = company.BusinessUserId,
41 BusinessUserName = company.BusinessUser.User.Username,
42 BusinessUserEmail = company.BusinessUser.User.Email,
43
44 });
45 }
46 return companies;
47 }
48 catch (Exception e)
49 {
50 _logger.LogError(e.Message);
51 throw;
52 }
53 }
54
55 public async Task<bool> ApproveCompany(int companyId, int administratorId)
56 {
57 try
58 {
59 var companyFromDb = await _db.Companies.Where(x => x.CompanyId == companyId).FirstOrDefaultAsync();
60 if (companyFromDb != null)
61 {
62 companyFromDb.AdministratorId = administratorId;
63 _db.Update(companyFromDb);
64 await _db.SaveChangesAsync();
65 }
66 return true;
67 }
68 catch (Exception e)
69 {
70 _logger.LogError(e.Message);
71 throw;
72 }
73 }
74
75 }
76}
Note: See TracBrowser for help on using the repository browser.