-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressController.cs
More file actions
99 lines (92 loc) · 3.54 KB
/
AddressController.cs
File metadata and controls
99 lines (92 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using DirectPay.Common.Extensions;
using DirectPay.Common.Mappers;
using DirectPay.DAL.Entities.Operations;
using DirectPay.DAL.Entities.BankAccounts;
using DirectPay.Ioc;
using DirectPay.Logic.Dto;
using DirectPay.Logic.Services;
using DirectPay.Web.ViewModels;
using Microsoft.Extensions.Localization;
namespace DirectPay.Web.Areas.Company.Controllers
{
[Authorize(Policy = "Company")]
[Area("Company")]
public class AddressController : Controller
{
private readonly IOperationService _operationService;
private readonly IAddressService _addressService;
private readonly IStringLocalizer<SharedResource> _localizer;
private readonly IDictionaryService _dictionaryService;
private readonly IMapper<Operation, OperationVm> _operationMapper;
private readonly IMapper<BankAccount, BankAccountVm> _addressMapper;
public static readonly string Name = nameof(AddressController).TrimEnd("Controller");
public AddressController(IAddressService addressService, IDictionaryService dictionaryService,
IStringLocalizer<SharedResource> localizer)
{
_addressService = addressService;
_dictionaryService = dictionaryService;
_localizer = localizer;
}
public IActionResult Index()
{
IUrlHelper urlHelper = IocContainer.Container.GetInstance<IUrlHelper>();
var model = new
{
getAddressesUrl = urlHelper.Action(nameof(GetAddresses_), Name),
deleteAddressUrl = urlHelper.Action(nameof(DeleteAddress), Name),
getAddressUrl = urlHelper.Action(nameof(GetAddress), Name),
addAddressUrl = urlHelper.Action(nameof(AddAddress), Name),
};
return View("~/Areas/Company/Views/Settings/Addresses.cshtml", model);
}
[HttpPost]
public string AddAddress(AddressDto address, IEnumerable<TranslationDto> names)
{
string result = _addressService.AddAddress(address, names.ToList(), true);
return result == null ? null : string.Format(_localizer[result].Value, _localizer["Attribute"].Value);
}
public IEnumerable<DictionaryDto<string>> GetAddresses_()
{
var addresses =
_addressService.GetAddresses()
.Select(a => new DictionaryDto<string>
{
Id = a.Id.ToString(),
Code = a.Code,
Name = a.Translations.Where(t => t.LanguageId == "RU").FirstOrDefault().Name
});
return addresses;
}
public object GetAddress(Guid id)
{
var address = _addressService.GetAddresses()
.Select(a => new
{
a.Id,
a.Code,
a.Props1,
a.Inn,
a.Okato,
a.PersonalAccount,
a.Kpp,
a.Props6,
a.Bic,
a.Account,
a.CorrespondentAccount,
a.Rounding,
a.Translations
}).Where(a => a.Id == id).ToArray()[0];
return address;
}
[HttpPost]
public void DeleteAddress(Guid id)
{
_addressService.DeleteAddress(id);
}
}
}