fix
This commit is contained in:
@@ -18,4 +18,9 @@ public class AccountAccountCategoryRepository : AppRepository<AccountAccountCate
|
||||
{
|
||||
return RemoveBase(accountAccountCategory) > 0;
|
||||
}
|
||||
|
||||
public bool Add(AccountAccountCategory accountAccountCategory)
|
||||
{
|
||||
return AddBase(accountAccountCategory) > 0;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.Include(x => x.Motions)!
|
||||
//.Include(x => x.Motions)!
|
||||
.FirstOrDefault(x => x.Id == id && x.AccessRights!.Any(r => r.UserId == userId));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ public interface IAccountAccountCategoryRepository
|
||||
{
|
||||
List<AccountAccountCategory> Get(Guid userId, Guid accountId, Guid categoryId);
|
||||
bool Remove(AccountAccountCategory accountAccountCategory);
|
||||
bool Add(AccountAccountCategory accountAccountCategory);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using DbContext;
|
||||
|
||||
public class RepositoryBase<TEntity> where TEntity : class
|
||||
{
|
||||
//TODO: Rename
|
||||
protected readonly AppDbContext _context;
|
||||
|
||||
protected RepositoryBase(
|
||||
@@ -49,41 +50,37 @@ public class RepositoryBase<TEntity> where TEntity : class
|
||||
return _context.Set<TEntity>().Find(id);
|
||||
}
|
||||
|
||||
protected async Task<int> AddBaseAsync(TEntity entity)
|
||||
{
|
||||
//await _context.Set<TEntity>().AddAsync(entity);
|
||||
await _context.AddAsync(entity);
|
||||
return await SaveChangesAsync();
|
||||
}
|
||||
|
||||
protected int AddBase(TEntity entity)
|
||||
{
|
||||
//_context.Set<TEntity>().Add(entity);
|
||||
_context.Add(entity);
|
||||
return SaveChanges();
|
||||
//_context.Add(entity);
|
||||
_context.Entry(entity).State = EntityState.Added;
|
||||
|
||||
var result = SaveChanges();
|
||||
|
||||
_context.Entry(entity).State = EntityState.Detached;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected int RemoveBase(TEntity entity)
|
||||
{
|
||||
_context.Set<TEntity>().Remove(entity);
|
||||
|
||||
_context.Entry(entity).State = EntityState.Deleted;
|
||||
|
||||
return SaveChanges();
|
||||
}
|
||||
var result = SaveChanges();
|
||||
|
||||
protected async Task<int> UpdateBaseAsync(TEntity entity)
|
||||
{
|
||||
_context.Attach(entity);
|
||||
_context.Entry(entity).State = EntityState.Modified;
|
||||
|
||||
return await SaveChangesAsync();
|
||||
_context.Entry(entity).State = EntityState.Detached;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected int UpdateBase(TEntity entity)
|
||||
{
|
||||
_context.Attach(entity);
|
||||
//_context.Attach(entity);
|
||||
_context.Entry(entity).State = EntityState.Modified;
|
||||
|
||||
return SaveChanges();
|
||||
var result = SaveChanges();
|
||||
|
||||
_context.Entry(entity).State = EntityState.Detached;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,7 @@ using Models.Users;
|
||||
|
||||
public interface IUserExternalRepository
|
||||
{
|
||||
Task<int> AddUserExternalAsync(UserExternal external);
|
||||
int AddUserExternal(UserExternal external);
|
||||
Task<int> AddUserExternalsAsync(IEnumerable<UserExternal> claims);
|
||||
|
||||
Task<List<UserExternal>> GetUserExternalsByUserIdAsync(Guid userId);
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ public interface IUserRepository
|
||||
Task<User?> GetByUserUserNameAsync(string userName);
|
||||
User? GetByUserUserName(string userName);
|
||||
|
||||
Task<int> AddUserAsync(User user);
|
||||
Task<int> UpdateUserAsync(User user);
|
||||
int AddUser(User user);
|
||||
int UpdateUser(User user);
|
||||
}
|
||||
@@ -6,11 +6,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public class UserExternalRepository : AppRepository<UserExternal>, IUserExternalRepository
|
||||
{
|
||||
public async Task<int> AddUserExternalAsync(UserExternal userExternal)
|
||||
{
|
||||
return await AddBaseAsync(userExternal);
|
||||
}
|
||||
|
||||
public int AddUserExternal(UserExternal userExternal)
|
||||
{
|
||||
return AddBase(userExternal);
|
||||
|
||||
@@ -26,13 +26,13 @@ public class UserRepository : AppRepository<User>, IUserRepository
|
||||
return _context.Users.FirstOrDefault(x => x.UserName == userName);
|
||||
}
|
||||
|
||||
public async Task<int> AddUserAsync(User user)
|
||||
public int AddUser(User user)
|
||||
{
|
||||
return await AddBaseAsync(user);
|
||||
return AddBase(user);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateUserAsync(User user)
|
||||
public int UpdateUser(User user)
|
||||
{
|
||||
return await UpdateBaseAsync(user);
|
||||
return UpdateBase(user);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,13 @@ public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
||||
throw new NotSupportedException($"No such provider: [{provider}]");
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
||||
builder.EnableSensitiveDataLogging(true);
|
||||
builder.EnableDetailedErrors(true);
|
||||
|
||||
#endif
|
||||
|
||||
var db = new AppDbContext(providerEnum, builder.Options);
|
||||
db.ChangeTracker.AutoDetectChangesEnabled = false;
|
||||
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class RepositoryInitializer
|
||||
/// </summary>
|
||||
private static void UpdateCurrentRates(AppDbContext dbContext)
|
||||
{
|
||||
var lastrates = dbContext.CurrencyRates
|
||||
var lastRates = dbContext.CurrencyRates
|
||||
.Include(x => x.Currency)
|
||||
.GroupBy(x => new
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public class RepositoryInitializer
|
||||
var currencies = dbContext.Currencies.ToList();
|
||||
foreach (var currency in currencies)
|
||||
{
|
||||
var rate = lastrates.FirstOrDefault(x => x.CurrencyId == currency.Id);
|
||||
var rate = lastRates.FirstOrDefault(x => x.CurrencyId == currency.Id);
|
||||
if (rate != null)
|
||||
{
|
||||
currency.CurrentRateId = rate.Id;
|
||||
|
||||
@@ -2,5 +2,5 @@ export interface ItemCategoryModel {
|
||||
id?: string,
|
||||
name?: string,
|
||||
allowDelete: boolean,
|
||||
isInternal: boolean,
|
||||
internal: boolean,
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="text-inside">
|
||||
<mat-checkbox class="example-margin" formControlName="isInternal">Is internal motion</mat-checkbox>
|
||||
<mat-checkbox class="example-margin" formControlName="internal">Is internal motion</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -39,11 +39,10 @@ export class SettingsItemCategoryEditComponent {
|
||||
this.category.name,
|
||||
[Validators.required],
|
||||
],
|
||||
isInternal: [
|
||||
this.category.isInternal,
|
||||
internal: [
|
||||
this.category?.internal ?? false,
|
||||
],
|
||||
});
|
||||
console.log(this.editForm.value);
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
|
||||
@@ -59,6 +59,8 @@ export class SettingsItemEditComponent {
|
||||
}
|
||||
|
||||
onSubmitClick() {
|
||||
console.log(this.item);
|
||||
console.log(this.editForm.value);
|
||||
if (this.editForm.valid) {
|
||||
this.errorMessage = undefined;
|
||||
this.httpClient
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<tr *ngFor="let item of categories">
|
||||
<td>{{item.name}}</td>
|
||||
<td>
|
||||
<mat-icon *ngIf="item.isInternal">done</mat-icon>
|
||||
<mat-icon *ngIf="item.internal">done</mat-icon>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-space" (click)="edit(item)" mat-raised-button color="primary">
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
namespace MyOffice.Services.Account
|
||||
{
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Identity;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Core.Helpers;
|
||||
using Data.Models.Accounts;
|
||||
using Data.Models.Items;
|
||||
using Data.Repositories.Account;
|
||||
using Data.Repositories.Currency;
|
||||
using Data.Repositories.Item;
|
||||
using Domain;
|
||||
using Item;
|
||||
using Item.Domain;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using System.Collections.Generic;
|
||||
using Identity;
|
||||
|
||||
public class AccountService
|
||||
{
|
||||
@@ -84,15 +83,19 @@
|
||||
return result.Set(_mapper.Map<AccountCategoryDto>(category));
|
||||
}
|
||||
|
||||
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, AccountCategory category)
|
||||
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, AccountCategoryDto input)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<AccountCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
category.Id = Guid.NewGuid();
|
||||
category.UserId = userId;
|
||||
var category = new AccountCategory
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
Name = input.Name,
|
||||
};
|
||||
|
||||
if (!_accountCategoryRepository.Add(category))
|
||||
{
|
||||
@@ -102,10 +105,10 @@
|
||||
return result.Set(_mapper.Map<AccountCategoryDto>(category));
|
||||
}
|
||||
|
||||
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, AccountCategory category)
|
||||
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, AccountCategoryDto input)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<AccountCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
@@ -115,7 +118,7 @@
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
exists.Name = category.Name;
|
||||
exists.Name = input.Name;
|
||||
|
||||
if (!_accountCategoryRepository.Update(exists))
|
||||
{
|
||||
@@ -300,14 +303,11 @@
|
||||
|
||||
if (category != null && account.Categories!.All(x => x.CategoryId != category.Id))
|
||||
{
|
||||
account.Categories = new List<AccountAccountCategory>
|
||||
_accountAccountCategoryRepository.Add(new AccountAccountCategory
|
||||
{
|
||||
new()
|
||||
{
|
||||
AccountId = account.Id,
|
||||
CategoryId = category.Id,
|
||||
}
|
||||
};
|
||||
AccountId = account.Id,
|
||||
CategoryId = category.Id,
|
||||
});
|
||||
}
|
||||
|
||||
if (!_accountRepository.Update(account))
|
||||
@@ -346,7 +346,7 @@
|
||||
return result.Set(categories);
|
||||
}
|
||||
|
||||
public Exec<List<Motion>, MotionAddStatus> MotionAdd(
|
||||
public Exec<List<MotionDto>, MotionAddStatus> MotionAdd(
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
MotionAddUpdate motion
|
||||
@@ -357,7 +357,7 @@
|
||||
if (motion.Item == null)
|
||||
throw new ArgumentNullException(nameof(motion.Item));
|
||||
|
||||
var result = new Exec<List<Motion>, MotionAddStatus>(MotionAddStatus.success);
|
||||
var result = new Exec<List<MotionDto>, MotionAddStatus>(MotionAddStatus.success);
|
||||
|
||||
var account = _accountRepository.Get(userId, accountId);
|
||||
if (account == null)
|
||||
@@ -388,8 +388,8 @@
|
||||
return result.Set(MotionAddStatus.failure);
|
||||
}
|
||||
|
||||
result.Set(new List<Motion>());
|
||||
result.Result!.Add(motionDb);
|
||||
result.Set(new List<MotionDto>());
|
||||
result.Result!.Add(_mapper.Map<MotionDto>(motionDb));
|
||||
|
||||
if (motion.AccountId.IsPresent() && motion.AmountBalancing != 0)
|
||||
{
|
||||
@@ -419,7 +419,7 @@
|
||||
|
||||
if (_motionRepository.Add(motionBalancing))
|
||||
{
|
||||
result.Result!.Add(motionBalancing);
|
||||
result.Result!.Add(_mapper.Map<MotionDto>(motionBalancing));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,7 +429,7 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
public Exec<Motion, MotionUpdateStatus> MotionUpdate(
|
||||
public Exec<MotionDto, MotionUpdateStatus> MotionUpdate(
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
Guid motionId,
|
||||
@@ -441,7 +441,7 @@
|
||||
if (motion.Item == null)
|
||||
throw new ArgumentNullException(nameof(motion.Item));
|
||||
|
||||
var result = new Exec<Motion, MotionUpdateStatus>(MotionUpdateStatus.success);
|
||||
var result = new Exec<MotionDto, MotionUpdateStatus>(MotionUpdateStatus.success);
|
||||
|
||||
var exists = _motionRepository.Get(userId, motionId);
|
||||
if (exists == null || exists.AccountId != accountId)
|
||||
@@ -467,7 +467,7 @@
|
||||
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<MotionDto>(exists));
|
||||
}
|
||||
|
||||
public Exec<List<Motion>, GeneralExecStatus> GetMotions(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using MyOffice.Data.Models.Users;
|
||||
|
||||
public class ItemCategoryDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public User User { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public List<ItemDto> Items { get; set; } = null!;
|
||||
public bool IsInternal { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
public class ItemDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public bool AllowDelete { get; set; }
|
||||
|
||||
public Guid CategoryId { get; set; }
|
||||
public ItemCategoryDto? Category { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public class MotionDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public Guid AccountId { get; set; }
|
||||
public AccountDto Account { get; set; } = null!;
|
||||
public int ItemId { get; set; }
|
||||
public ItemDto Item { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal AmountPlus { get; set; }
|
||||
public decimal AmountMinus { get; set; }
|
||||
public DateTime? DeletedOn { get; set; }
|
||||
}
|
||||
@@ -1,71 +1,85 @@
|
||||
namespace MyOffice.Services.Currency;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Currencies;
|
||||
using Data.Repositories.Currency;
|
||||
using MyOffice.Services.Currency.Domain;
|
||||
using Domain;
|
||||
|
||||
public class CurrencyService
|
||||
{
|
||||
private readonly ICurrencyGlobalRepository _currencyGlobalRepository;
|
||||
private readonly ICurrencyRepository _currencyRepository;
|
||||
private readonly ICurrencyRateRepository _currencyRateRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CurrencyService(
|
||||
ICurrencyGlobalRepository currencyGlobalRepository,
|
||||
ICurrencyRepository currencyRepository,
|
||||
ICurrencyRateRepository currencyRateRepository
|
||||
ICurrencyRateRepository currencyRateRepository,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_currencyGlobalRepository = currencyGlobalRepository;
|
||||
_currencyRepository = currencyRepository;
|
||||
_currencyRateRepository = currencyRateRepository;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public List<CurrencyGlobal> GetGlobalAll()
|
||||
public List<CurrencyGlobalDto> GetGlobalAll()
|
||||
{
|
||||
return _currencyGlobalRepository.GetAll();
|
||||
return _mapper.Map<List<CurrencyGlobalDto>>(_currencyGlobalRepository.GetAll());
|
||||
}
|
||||
|
||||
public List<Currency> GetAll(Guid userId)
|
||||
public List<CurrencyDto> GetAll(Guid userId)
|
||||
{
|
||||
return _currencyRepository.GetAll(userId);
|
||||
return _mapper.Map<List<CurrencyDto>>(_currencyRepository.GetAll(userId));
|
||||
}
|
||||
|
||||
public Dictionary<Currency, CurrencyRate?> GetAllWithRates(Guid userId)
|
||||
public List<CurrencyWithRateDto> GetAllWithRates(Guid userId)
|
||||
{
|
||||
var list = _currencyRepository.GetAll(userId);
|
||||
return list.ToDictionary(
|
||||
x => x,
|
||||
x => _currencyRateRepository.GetLastRates(x.Id).FirstOrDefault()
|
||||
);
|
||||
|
||||
return list.Select(x => new CurrencyWithRateDto
|
||||
{
|
||||
Currency = _mapper.Map<CurrencyDto>(x),
|
||||
Rate = _mapper.Map<CurrencyRateDto>(_currencyRateRepository.GetLastRates(x.Id).FirstOrDefault()),
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public Exec<Currency, CurrencyAddStatus> CurrencyAdd(Guid userId, Currency currency)
|
||||
public Exec<CurrencyDto, CurrencyAddStatus> CurrencyAdd(Guid userId, CurrencyDto input)
|
||||
{
|
||||
if (currency == null)
|
||||
throw new ArgumentNullException(nameof(currency));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<Currency, CurrencyAddStatus>(CurrencyAddStatus.success);
|
||||
var result = new Exec<CurrencyDto, CurrencyAddStatus>(CurrencyAddStatus.success);
|
||||
|
||||
var exists = _currencyRepository.GetByGlobalCurrency(userId, currency.CurrencyGlobalId);
|
||||
var exists = _currencyRepository.GetByGlobalCurrency(userId, input.CurrencyGlobalId);
|
||||
if (exists != null)
|
||||
{
|
||||
return result.Set(exists, CurrencyAddStatus.exists);
|
||||
return result.Set(_mapper.Map<CurrencyDto>(exists), CurrencyAddStatus.exists);
|
||||
}
|
||||
|
||||
currency.Id = Guid.NewGuid();
|
||||
currency.UserId = userId;
|
||||
var currency = new Currency
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
CurrencyGlobalId = input.CurrencyGlobalId,
|
||||
Name = input.Name,
|
||||
ShortName = input.ShortName,
|
||||
};
|
||||
|
||||
if (!_currencyRepository.Add(currency))
|
||||
{
|
||||
return result.Set(CurrencyAddStatus.failed);
|
||||
}
|
||||
|
||||
return result.Set(currency);
|
||||
return result.Set(_mapper.Map<CurrencyDto>(currency));
|
||||
}
|
||||
|
||||
public Exec<Currency, CurrencyEditStatus> CurrencyUpdate(
|
||||
public Exec<CurrencyDto, CurrencyEditStatus> CurrencyUpdate(
|
||||
Guid userId,
|
||||
Guid currencyId,
|
||||
CurrencyEdit currency
|
||||
@@ -74,7 +88,7 @@ public class CurrencyService
|
||||
if (currency == null)
|
||||
throw new ArgumentNullException(nameof(currency));
|
||||
|
||||
var result = new Exec<Currency, CurrencyEditStatus>(CurrencyEditStatus.success);
|
||||
var result = new Exec<CurrencyDto, CurrencyEditStatus>(CurrencyEditStatus.success);
|
||||
|
||||
var exists = _currencyRepository.Get(userId, currencyId);
|
||||
if (exists == null)
|
||||
@@ -104,15 +118,15 @@ public class CurrencyService
|
||||
}
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<CurrencyDto>(exists));
|
||||
}
|
||||
|
||||
public Exec<CurrencyRate, CurrencyAddRateStatus> CurrencyRateAdd(Guid userId, Guid currencyId, CurrencyRate currencyRate)
|
||||
public Exec<CurrencyRateDto, CurrencyAddRateStatus> CurrencyRateAdd(Guid userId, Guid currencyId, CurrencyRateDto input)
|
||||
{
|
||||
if (currencyRate == null)
|
||||
throw new ArgumentNullException(nameof(currencyRate));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<CurrencyRate, CurrencyAddRateStatus>(CurrencyAddRateStatus.success);
|
||||
var result = new Exec<CurrencyRateDto, CurrencyAddRateStatus>(CurrencyAddRateStatus.success);
|
||||
|
||||
var currency = _currencyRepository.Get(userId, currencyId);
|
||||
if (currency == null)
|
||||
@@ -120,11 +134,17 @@ public class CurrencyService
|
||||
return result.Set(CurrencyAddRateStatus.not_found);
|
||||
}
|
||||
|
||||
currencyRate.CurrencyId = currency.Id;
|
||||
currencyRate.DateTime = currencyRate.DateTime.Date;
|
||||
var currencyRate = new CurrencyRate
|
||||
{
|
||||
CurrencyId = currency.Id,
|
||||
DateTime = input.DateTime.Date,
|
||||
Rate = input.Rate,
|
||||
Quantity = input.Quantity,
|
||||
};
|
||||
|
||||
var rates = _currencyRateRepository.GetAtDate(currencyRate.CurrencyId, currencyRate.DateTime);
|
||||
var rate = rates.Find(x => x.Rate == currencyRate.Rate);
|
||||
|
||||
if (rate == null)
|
||||
{
|
||||
if (!_currencyRateRepository.AddRate(currencyRate))
|
||||
@@ -132,15 +152,15 @@ public class CurrencyService
|
||||
return result.Set(CurrencyAddRateStatus.failed);
|
||||
}
|
||||
|
||||
rate = currencyRate;
|
||||
|
||||
if (rate.DateTime.EndOfDay() <= DateTime.UtcNow.EndOfDay())
|
||||
// TODO: more logic to fix current rate
|
||||
if (currencyRate.DateTime.Date == DateTime.UtcNow.Date || !currency.CurrentRateId.HasValue)
|
||||
{
|
||||
currency.CurrentRateId = rate.Id;
|
||||
currency.CurrencyGlobal = null;
|
||||
currency.CurrentRateId = currencyRate.Id;
|
||||
_currencyRepository.Update(currency);
|
||||
}
|
||||
}
|
||||
|
||||
return result.Set(rate);
|
||||
return result.Set(_mapper.Map<CurrencyRateDto>(rate));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
using MyOffice.Data.Models.Currencies;
|
||||
using MyOffice.Data.Models.Users;
|
||||
|
||||
public class CurrencyDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string CurrencyGlobalId { get; set; } = null!;
|
||||
public CurrencyGlobal? CurrencyGlobal { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public User? User { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
public IEnumerable<CurrencyRate>? Rates { get; set; }
|
||||
|
||||
public int? CurrentRateId { get; set; }
|
||||
public CurrencyRate? CurrentRate { get; set; }
|
||||
|
||||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class CurrencyGlobalDto
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public string Symbol { get; set; } = null!;
|
||||
public int DefaultQuantity { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class CurrencyRateDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid CurrencyId { get; set; }
|
||||
public CurrencyDto? Currency { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public decimal Rate { get; set; }
|
||||
public IEnumerable<CurrencyDto>? Currencies { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class CurrencyWithRateDto
|
||||
{
|
||||
public CurrencyDto Currency { get; set; } = null!;
|
||||
public CurrencyRateDto? Rate { get; set; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using AutoMapper;
|
||||
using Domain;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
@@ -16,20 +17,23 @@ public class ItemService
|
||||
private readonly IItemCategoryRepository _itemCategoryRepository;
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly IItemGlobalRepository _itemGlobalRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ItemService(
|
||||
IItemCategoryRepository itemCategoryRepository,
|
||||
IItemRepository itemRepository,
|
||||
IItemGlobalRepository itemGlobalRepository
|
||||
IItemGlobalRepository itemGlobalRepository,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_itemCategoryRepository = itemCategoryRepository;
|
||||
_itemRepository = itemRepository;
|
||||
_itemGlobalRepository = itemGlobalRepository;
|
||||
_mapper = mapper;
|
||||
|
||||
}
|
||||
|
||||
public List<ItemCategory> GetAllCategories(Guid userId)
|
||||
public List<ItemCategoryDto> GetAllCategories(Guid userId)
|
||||
{
|
||||
var result = _itemCategoryRepository.GetAll(userId);
|
||||
if (result.All(x => x.Id != userId))
|
||||
@@ -44,35 +48,38 @@ public class ItemService
|
||||
|
||||
result.Add(_itemCategoryRepository.Get(userId, userId)!);
|
||||
}
|
||||
return result;
|
||||
return _mapper.Map<List<ItemCategoryDto>>(result);
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, GeneralExecStatus> CategoryAdd(Guid userId, ItemCategory category)
|
||||
public Exec<ItemCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, ItemCategoryDto input)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<ItemCategory, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
category.Id = Guid.NewGuid();
|
||||
category.UserId = userId;
|
||||
category.IsInternal = category.IsInternal;
|
||||
category.Items = new List<Item>();
|
||||
var category = new ItemCategory
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
Name = input.Name,
|
||||
IsInternal = input.IsInternal,
|
||||
};
|
||||
|
||||
if (!_itemCategoryRepository.Add(category))
|
||||
{
|
||||
return result.Set(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
return result.Set(category);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(category));
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, ItemCategory category)
|
||||
public Exec<ItemCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, ItemCategoryDto category)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
|
||||
var result = new Exec<ItemCategory, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var exists = _itemCategoryRepository.Get(userId, id);
|
||||
if (exists == null)
|
||||
@@ -82,19 +89,18 @@ public class ItemService
|
||||
|
||||
exists.Name = category.Name;
|
||||
exists.IsInternal = category.IsInternal;
|
||||
exists.Items = new List<Item>();
|
||||
|
||||
if (!_itemCategoryRepository.Update(exists))
|
||||
{
|
||||
return result.Set(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(exists));
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, ItemCategoryRemoveResult> CategoryRemove(Guid userId, Guid id)
|
||||
public Exec<ItemCategoryDto, ItemCategoryRemoveResult> CategoryRemove(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<ItemCategory, ItemCategoryRemoveResult>(ItemCategoryRemoveResult.success);
|
||||
var result = new Exec<ItemCategoryDto, ItemCategoryRemoveResult>(ItemCategoryRemoveResult.success);
|
||||
|
||||
var exists = _itemCategoryRepository.Get(userId, id);
|
||||
if (exists == null)
|
||||
@@ -111,33 +117,33 @@ public class ItemService
|
||||
return result.Set(ItemCategoryRemoveResult.failure);
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(exists));
|
||||
}
|
||||
|
||||
public List<Item> GetAll(Guid userId)
|
||||
public List<ItemDto> GetAll(Guid userId)
|
||||
{
|
||||
return _itemRepository.GetAll(userId);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.GetAll(userId));
|
||||
}
|
||||
|
||||
public List<Item> GetByCategory(Guid userId, Guid categoryId)
|
||||
public List<ItemDto> GetByCategory(Guid userId, Guid categoryId)
|
||||
{
|
||||
return _itemRepository.GetByCategory(userId, categoryId);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.GetByCategory(userId, categoryId));
|
||||
}
|
||||
|
||||
public Exec<Item, GeneralExecStatus> Update(Guid userId, Guid motionId, Guid categoryId)
|
||||
public Exec<ItemDto, GeneralExecStatus> Update(Guid userId, Guid motionId, Guid categoryId)
|
||||
{
|
||||
var result = new Exec<Item, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var motion = _itemRepository.GetByGlobal(userId, motionId);
|
||||
if (motion == null)
|
||||
var item = _itemRepository.GetByGlobal(userId, motionId);
|
||||
if (item == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
motion.Category!.Id = categoryId;
|
||||
_itemRepository.Update(motion);
|
||||
item.CategoryId = categoryId;
|
||||
_itemRepository.Update(item);
|
||||
|
||||
return result.Set(motion);
|
||||
return result.Set(_mapper.Map<ItemDto>(item));
|
||||
}
|
||||
|
||||
public Exec<Item, ItemGetOrAddResult> GetOrCreate(Guid userId, string name)
|
||||
@@ -191,11 +197,11 @@ public class ItemService
|
||||
return result.Set(item);
|
||||
}
|
||||
|
||||
public List<Item> FindItems(Guid userId, string term, int limit = 15)
|
||||
public List<ItemDto> FindItems(Guid userId, string term, int limit = 15)
|
||||
{
|
||||
if (term == null)
|
||||
throw new ArgumentNullException(nameof(term));
|
||||
|
||||
return _itemRepository.Find(userId, term, limit);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.Find(userId, term, limit));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,33 @@
|
||||
using Account.Domain;
|
||||
using AutoMapper;
|
||||
using Data.Models.Accounts;
|
||||
using Data.Models.Currencies;
|
||||
using Data.Models.Items;
|
||||
using Data.Models.Users;
|
||||
using MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class AccountServiceProfile : Profile
|
||||
{
|
||||
public AccountServiceProfile()
|
||||
{
|
||||
CreateMap<User, UserDto>();
|
||||
MapUser();
|
||||
|
||||
MapAccount();
|
||||
|
||||
MapCurrency();
|
||||
|
||||
MapItems();
|
||||
|
||||
CreateMap<Motion, MotionDto>();
|
||||
}
|
||||
|
||||
private void MapUser()
|
||||
{
|
||||
CreateMap<User, UserDto>();
|
||||
}
|
||||
|
||||
private void MapAccount()
|
||||
{
|
||||
CreateMap<Account, AccountDto>()
|
||||
.ForMember(x => x.HasMotions, o => o.MapFrom(x => x.Motions!.Any()))
|
||||
.ForMember(x => x.CurrentUserId, o => o.MapFrom<UserIdResolver>())
|
||||
@@ -45,4 +64,24 @@ public class AccountServiceProfile : Profile
|
||||
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account!.Name))
|
||||
;
|
||||
}
|
||||
|
||||
private void MapCurrency()
|
||||
{
|
||||
CreateMap<CurrencyGlobal, CurrencyGlobalDto>();
|
||||
|
||||
CreateMap<Currency, CurrencyDto>();
|
||||
|
||||
CreateMap<CurrencyRate, CurrencyRateDto>();
|
||||
}
|
||||
|
||||
private void MapItems()
|
||||
{
|
||||
CreateMap<ItemCategory, ItemCategoryDto>();
|
||||
|
||||
CreateMap<Item, ItemDto>()
|
||||
.ForMember(x => x.Id, o => o.MapFrom(x => x.ItemGlobalId))
|
||||
.ForMember(x => x.Name, o => o.MapFrom(x => x.ItemGlobal.Name))
|
||||
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Motions!.Any()))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ namespace MyOffice.Web.Controllers;
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -38,15 +37,15 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
public List<AccountDetailedViewModel> AccountsGet(string category)
|
||||
public ObjectResult AccountsGet(string category)
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
|
||||
return _mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList());
|
||||
return OkResponse(_mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList()));
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}")]
|
||||
public object AccountGet(string id)
|
||||
public ObjectResult AccountGet(string id)
|
||||
{
|
||||
var exec = _accountService.GetByIdDetailed(UserId, id!.AsGuid());
|
||||
|
||||
@@ -54,10 +53,10 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountDetailedViewModel>(exec.Result);
|
||||
return OkResponse(_mapper.Map<AccountDetailedViewModel>(exec.Result));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -65,7 +64,7 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}/motions")]
|
||||
public object MotionsGet(string id, [FromQuery] MotionsGetModel request)
|
||||
public ObjectResult MotionsGet(string id, [FromQuery] MotionsGetRequest request)
|
||||
{
|
||||
var exec = _accountService.GetMotions(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
|
||||
@@ -73,11 +72,10 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
//return exec.Result!.Select(x => x.ToModel());
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
return OkResponse(_mapper.Map<List<MotionViewModel>>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -92,9 +90,9 @@ public class AccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionAddStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case MotionAddStatus.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
return ProblemBadResponse("Adding motion failed.");
|
||||
case MotionAddStatus.success:
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
|
||||
@@ -104,18 +102,18 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
public ObjectResult MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionUpdate(UserId, id.AsGuid(), motionId.AsGuid(), _mapper.Map<MotionAddUpdate>(motion));
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionUpdateStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
return ProblemBadResponse("Motion not found.");
|
||||
case MotionUpdateStatus.failure:
|
||||
return ProblemBadRequest("Updating motion failed.");
|
||||
return ProblemBadResponse("Updating motion failed.");
|
||||
case MotionUpdateStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<List<MotionViewModel>>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -123,18 +121,18 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsDelete(string id, string motionId)
|
||||
public ObjectResult MotionsDelete(string id, string motionId)
|
||||
{
|
||||
var exec = _accountService.MotionRemove(UserId, id.AsGuid(), motionId.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionDeleteStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
return ProblemBadResponse("Motion not found.");
|
||||
case MotionDeleteStatus.failure:
|
||||
return ProblemBadRequest("Deliting motion failed.");
|
||||
return ProblemBadResponse("Deliting motion failed.");
|
||||
case MotionDeleteStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<MotionViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -142,16 +140,18 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/items")]
|
||||
public object FindItems(string term)
|
||||
public ObjectResult FindItems(string term)
|
||||
{
|
||||
var items = _itemService
|
||||
.FindItems(UserId, term)
|
||||
.Select(x => x.ToModel())
|
||||
.ToList();
|
||||
var itemsDto = _itemService.FindItems(UserId, term);
|
||||
|
||||
var items = _mapper.Map<List<ItemViewModel>>(itemsDto);
|
||||
|
||||
if (term.StartsWith("+") && term.Length > 1)
|
||||
{
|
||||
var accounts = _accountService.FindAccounts(UserId, term.Substring(1));
|
||||
var accounts = _accountService
|
||||
.FindAccounts(UserId, term.Substring(1))
|
||||
.OrderByDescending(x => x.Name);
|
||||
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var accountName = $"+{account.Name}";
|
||||
@@ -172,8 +172,10 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
return OkResponse(_mapper
|
||||
.Map<List<ItemViewModel>>(items)
|
||||
.OrderBy(x => x.AccountId)
|
||||
.ThenBy(x => x.Name);
|
||||
.ThenBy(x => x.Name)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Security.Authentication;
|
||||
using Core.Extensions;
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MyOffice.Web.Models;
|
||||
using static IdentityServer4.Models.IdentityResources;
|
||||
|
||||
public class BaseApiController : ControllerBase
|
||||
@@ -19,8 +20,18 @@ public class BaseApiController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectResult ProblemBadRequest(string? detail = null)
|
||||
public ObjectResult ProblemBadResponse(string? detail = null)
|
||||
{
|
||||
return Problem(detail, statusCode: StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
public ObjectResult OkResponse(IResponseModel response)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
public ObjectResult OkResponse<T>(IEnumerable<T> response) where T : IResponseModel
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Currencies;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Data.Repositories.Currency;
|
||||
using Models.Currency;
|
||||
using Services.Currency;
|
||||
using Services.Currency.Domain;
|
||||
using MyOffice.Core;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
@@ -17,30 +16,31 @@ public class CurrencyController : BaseApiController
|
||||
{
|
||||
private readonly CurrencyService _currencyService;
|
||||
private readonly ILogger<CurrencyController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CurrencyController(
|
||||
CurrencyService currencyService,
|
||||
ILogger<CurrencyController> logger
|
||||
ILogger<CurrencyController> logger,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_currencyService = currencyService;
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/currencies")]
|
||||
public object Get()
|
||||
public ObjectResult Get()
|
||||
{
|
||||
var list = _currencyService.GetAllWithRates(UserId);
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Key.CurrencyGlobalId)
|
||||
.Select(x => x.Key.ToModel(x.Value));
|
||||
return OkResponse(_mapper.Map<List<CurrencyViewModel>>(list).OrderBy(x => x.Id));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/currencies")]
|
||||
public object Post(CurrencyAddModel currency)
|
||||
public ObjectResult Post(CurrencyAddModel currency)
|
||||
{
|
||||
var exec = _currencyService.CurrencyAdd(UserId, new Currency
|
||||
var exec = _currencyService.CurrencyAdd(UserId, new CurrencyDto
|
||||
{
|
||||
UserId = UserId,
|
||||
CurrencyGlobalId = currency.Id,
|
||||
@@ -52,17 +52,17 @@ public class CurrencyController : BaseApiController
|
||||
{
|
||||
case CurrencyAddStatus.success:
|
||||
case CurrencyAddStatus.exists:
|
||||
_currencyService.CurrencyRateAdd(UserId, exec.Result!.Id, new CurrencyRate()
|
||||
_currencyService.CurrencyRateAdd(UserId, exec.Result!.Id, new CurrencyRateDto
|
||||
{
|
||||
CurrencyId = exec.Result!.Id,
|
||||
Rate = currency.Rate,
|
||||
Quantity = currency.Quantity,
|
||||
DateTime = currency.RateDate.Date,
|
||||
});
|
||||
return currency;
|
||||
return OkResponse(_mapper.Map<CurrencyViewModel>(exec.Result!));
|
||||
|
||||
case CurrencyAddStatus.failed:
|
||||
return ProblemBadRequest("Adding currency failed.");
|
||||
return ProblemBadResponse("Adding currency failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -70,7 +70,7 @@ public class CurrencyController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/currencies/{id}")]
|
||||
public object Put(string id, CurrencyEditModel currency)
|
||||
public ObjectResult Update(string id, CurrencyEditModel currency)
|
||||
{
|
||||
var exec = _currencyService.CurrencyUpdate(
|
||||
UserId,
|
||||
@@ -81,11 +81,11 @@ public class CurrencyController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case CurrencyEditStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<CurrencyViewModel>(exec.Result!));
|
||||
|
||||
case CurrencyEditStatus.not_found:
|
||||
case CurrencyEditStatus.failed:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -93,9 +93,9 @@ public class CurrencyController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/currencies/{id}/rate")]
|
||||
public object Post(string id, CurrencyRateModel currencyRate)
|
||||
public ObjectResult Add(string id, CurrencyRateModel currencyRate)
|
||||
{
|
||||
var exec = _currencyService.CurrencyRateAdd(UserId, id.AsGuid(), new CurrencyRate()
|
||||
var exec = _currencyService.CurrencyRateAdd(UserId, id.AsGuid(), new CurrencyRateDto
|
||||
{
|
||||
CurrencyId = id.AsGuid(),
|
||||
Quantity = currencyRate.Quantity,
|
||||
@@ -106,12 +106,12 @@ public class CurrencyController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case CurrencyAddRateStatus.failed:
|
||||
return ProblemBadRequest("Adding currency rate failed.");
|
||||
return ProblemBadResponse("Adding currency rate failed.");
|
||||
case CurrencyAddRateStatus.not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
|
||||
case CurrencyAddRateStatus.success:
|
||||
return exec.Result!;
|
||||
return OkResponse(_mapper.Map<CurrencyRateViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Data.Repositories.Currency;
|
||||
using Models.Currency;
|
||||
using Services.Currency;
|
||||
|
||||
@@ -12,19 +12,22 @@ using Services.Currency;
|
||||
public class GeneralController : BaseApiController
|
||||
{
|
||||
private readonly CurrencyService _currencyService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GeneralController(
|
||||
CurrencyService currencyService
|
||||
CurrencyService currencyService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_currencyService = currencyService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/general/currencies")]
|
||||
public object Get()
|
||||
public ObjectResult Get()
|
||||
{
|
||||
var list = _currencyService.GetGlobalAll();
|
||||
|
||||
return list.Select(x => x.ToModel());
|
||||
return Ok(_mapper.Map<List<CurrencyGlobalViewModel>>(list));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Models.Account;
|
||||
using Services.Account;
|
||||
using Services.Account.Domain;
|
||||
using MyOffice.Web.Infrastructure.Attributes;
|
||||
using Infrastructure.Attributes;
|
||||
using Services.Identity;
|
||||
|
||||
[Authorize]
|
||||
@@ -52,7 +52,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account category not found.");
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountCategoryViewModel>(exec.Result!);
|
||||
@@ -65,7 +65,7 @@ public class SettingsAccountController : BaseApiController
|
||||
[HttpPost("~/api/settings/account-categories")]
|
||||
public object AccountCategoriesAdd(AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategory { Name = request.Name! });
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
@@ -73,7 +73,7 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding account category failed.");
|
||||
return ProblemBadResponse("Adding account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -83,7 +83,7 @@ public class SettingsAccountController : BaseApiController
|
||||
[HttpPut("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesEdit([AsGuid] string id, AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategory { Name = request.Name! });
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
@@ -91,7 +91,7 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update account category failed.");
|
||||
return ProblemBadResponse("Update account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -108,11 +108,11 @@ public class SettingsAccountController : BaseApiController
|
||||
return exec.Result!;
|
||||
|
||||
case AccountCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove account category failed.");
|
||||
return ProblemBadResponse("Remove account category failed.");
|
||||
case AccountCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account category not found.");
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
case AccountCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account category have accounts.");
|
||||
return ProblemBadResponse("Account category have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -143,11 +143,11 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountAddStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
case AccountAddStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
case AccountAddStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountAddStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -172,13 +172,13 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountEditStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case AccountEditStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
case AccountEditStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
case AccountEditStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountEditStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -212,7 +212,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
@@ -233,7 +233,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
break;
|
||||
@@ -252,7 +252,7 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (inviteExec.Status)
|
||||
{
|
||||
case AccessInviteStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case AccessInviteStatus.access_exists:
|
||||
case AccessInviteStatus.invite_exists:
|
||||
@@ -273,7 +273,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
@@ -299,9 +299,9 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case InviteAcceptStatus.invite_not_found:
|
||||
return ProblemBadRequest("Invite not found.");
|
||||
return ProblemBadResponse("Invite not found.");
|
||||
case InviteAcceptStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case InviteAcceptStatus.already_accepted:
|
||||
case InviteAcceptStatus.success:
|
||||
@@ -321,7 +321,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Invite not found.");
|
||||
return ProblemBadResponse("Invite not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountAccessInviteViewModel>(exec.Result!);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Data.Models.Items;
|
||||
using Data.Repositories.Account;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Models.Item;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Services.Account;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using Core.Extensions;
|
||||
using Core;
|
||||
using Infrastructure.Attributes;
|
||||
using Services.Item;
|
||||
using Services.Item.Domain;
|
||||
|
||||
@@ -18,42 +17,43 @@ using Services.Item.Domain;
|
||||
public class SettingsItemController : BaseApiController
|
||||
{
|
||||
private ILogger<SettingsItemController> _logger;
|
||||
|
||||
private IMapper _mapper;
|
||||
private ItemService _itemService;
|
||||
|
||||
public SettingsItemController(
|
||||
ILogger<SettingsItemController> logger,
|
||||
ItemService itemService
|
||||
ItemService itemService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_itemService = itemService;
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/item-categories")]
|
||||
public object ItemsCategories()
|
||||
public ObjectResult ItemsCategories()
|
||||
{
|
||||
var list = _itemService.GetAllCategories(UserId);
|
||||
|
||||
return list
|
||||
.Select(x => x.ToModel())
|
||||
return Ok(_mapper.Map<List<ItemCategoryViewModel>>(list)
|
||||
.OrderByDescending(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name);
|
||||
.ThenBy(x => x.Name));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/item-categories")]
|
||||
public object ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
public ObjectResult ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryAdd(UserId, request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding item category failed.");
|
||||
return ProblemBadResponse("Adding item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -61,18 +61,18 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesEdit(string id, ItemCategoryViewModel request)
|
||||
public ObjectResult ItemCategoriesUpdate([AsGuid] string id, ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryUpdate(UserId, id.AsGuid(), request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update item category failed.");
|
||||
return ProblemBadResponse("Update item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -80,20 +80,20 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesDelete(string id)
|
||||
public ObjectResult ItemCategoriesDelete([AsGuid] string id)
|
||||
{
|
||||
var exec = _itemService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case ItemCategoryRemoveResult.success:
|
||||
return exec.Result!;
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case ItemCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove item category failed.");
|
||||
return ProblemBadResponse("Remove item category failed.");
|
||||
case ItemCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account item not found.");
|
||||
return ProblemBadResponse("Account item not found.");
|
||||
case ItemCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account motion have accounts.");
|
||||
return ProblemBadResponse("Account motion have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -101,29 +101,28 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/items")]
|
||||
public object Items(string? category)
|
||||
public ObjectResult Items([AsGuid] string? category)
|
||||
{
|
||||
var list = category.IsMissing()
|
||||
? _itemService.GetAll(UserId)
|
||||
: _itemService.GetByCategory(UserId, category!.AsGuid());
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.ItemGlobal.Name)
|
||||
.Select(x => x.ToModel());
|
||||
return Ok(_mapper.Map<List<ItemViewModel>>(list.OrderBy(x => x.Name)));
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/items/{id}")]
|
||||
public object Items(string id, ItemEditModel request)
|
||||
public ObjectResult Items([AsGuid] string id, ItemEditModel request)
|
||||
{
|
||||
var exec = _itemService.Update(UserId, id.AsGuid(), request.Category.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Item not found.");
|
||||
return ProblemBadResponse("Item not found.");
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Item update failed.");
|
||||
return ProblemBadResponse("Item update failed.");
|
||||
case GeneralExecStatus.success:
|
||||
return Ok(exec.Result!.ToModel());
|
||||
return Ok(_mapper.Map<ItemViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -84,10 +84,10 @@ public class UserController : BaseApiController
|
||||
public async Task<object> AttachProvider([FromBody] AttachModel model)
|
||||
{
|
||||
var validator = _externalProviderValidators.FirstOrDefault(x => x.Provider.EqualsIgnoreCase(model.Provider));
|
||||
if (validator == null) return ProblemBadRequest("Provider not supported");
|
||||
if (validator == null) return ProblemBadResponse("Provider not supported");
|
||||
|
||||
var result = await validator.ValidateAsync(model.Token);
|
||||
if (!result.IsSuccessed) return ProblemBadRequest("Token not valid");
|
||||
if (!result.IsSuccessed) return ProblemBadResponse("Token not valid");
|
||||
|
||||
var execResult = _userService.AddUserExternal(UserId, model.Provider, result.ExternalId!, result.Email!);
|
||||
switch (execResult.Status)
|
||||
@@ -100,7 +100,7 @@ public class UserController : BaseApiController
|
||||
|
||||
case AddUserExternalStatusEnum.externalid_used:
|
||||
case AddUserExternalStatusEnum.user_not_valid:
|
||||
return ProblemBadRequest("Provider already connected");
|
||||
return ProblemBadResponse("Provider already connected");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(execResult.Status.ToString());
|
||||
@@ -113,7 +113,7 @@ public class UserController : BaseApiController
|
||||
{
|
||||
var exec = await _userService.RemoveUserExternal(UserId, model.Provider);
|
||||
|
||||
if (exec.Status == GeneralExecStatus.not_found) return ProblemBadRequest("Provider not connected");
|
||||
if (exec.Status == GeneralExecStatus.not_found) return ProblemBadResponse("Provider not connected");
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ public class UserStore :
|
||||
|
||||
public async Task<IdentityResult> CreateAsync(ApplicationUser<Guid> user, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _userRepository.AddUserAsync(new User
|
||||
var result = _userRepository.AddUser(new User
|
||||
{
|
||||
Id = user.Id,
|
||||
UserName = user.UserName,
|
||||
@@ -83,7 +83,7 @@ public class UserStore :
|
||||
IsEmailConfirmed = user.IsEmailConfirmed
|
||||
};
|
||||
|
||||
var result = await _userRepository.UpdateUserAsync(userDb);
|
||||
var result = _userRepository.UpdateUser(userDb);
|
||||
return result == 1 ? IdentityResult.Success : IdentityResult.Failed();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
|
||||
public class AccountDetailedViewModel
|
||||
public class AccountDetailedViewModel: BaseViewModel
|
||||
{
|
||||
public AccountViewModel Account { get; set; } = null!;
|
||||
public decimal Rest { get; set; }
|
||||
}
|
||||
|
||||
/*public static class AccountDetailedViewModelExtensions
|
||||
{
|
||||
public static AccountDetailedViewModel ToModel(this AccountDetailedDto input)
|
||||
{
|
||||
return new AccountDetailedViewModel
|
||||
{
|
||||
Account = input.Account.ToModel(),
|
||||
Rest = input.Rest,
|
||||
};
|
||||
}
|
||||
}*/
|
||||
@@ -1,7 +1,12 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using MyOffice.Services.Currency.Domain;
|
||||
using MyOffice.Services.Identity;
|
||||
using Currency;
|
||||
using Item;
|
||||
using Motion;
|
||||
using Services.Account.Domain;
|
||||
using User;
|
||||
|
||||
@@ -67,5 +72,35 @@ public class AccountViewModelProfile : Profile
|
||||
CreateMap<AccountAccessInviteDto, AccountAccessInviteViewModel>()
|
||||
.ForMember(x => x.AllowWrite, o => o.MapFrom(x => x.IsAllowWrite))
|
||||
;
|
||||
|
||||
CreateMap<MotionDto, MotionViewModel>()
|
||||
;
|
||||
|
||||
CreateMap<ItemDto, ItemViewModel>()
|
||||
.ForMember(x => x.Category, o => o.MapFrom(x => x.Category!.Name))
|
||||
;
|
||||
|
||||
CreateMap<ItemCategoryDto, ItemCategoryViewModel>()
|
||||
.ForMember(x => x.Internal, o => o.MapFrom(x => x.IsInternal))
|
||||
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Items.Any() && x.Id != x.UserId))
|
||||
.ForMember(x => x.SortOrder, o => o.MapFrom(x => x.Id == x.UserId ? 1 : 0))
|
||||
;
|
||||
|
||||
CreateMap<CurrencyGlobalDto, CurrencyGlobalViewModel>();
|
||||
|
||||
CreateMap<CurrencyDto, CurrencyViewModel>();
|
||||
|
||||
CreateMap<CurrencyRateDto, CurrencyRateViewModel>();
|
||||
|
||||
CreateMap<CurrencyWithRateDto, CurrencyViewModel>()
|
||||
.ForMember(x => x.Id, o => o.MapFrom(x => x.Currency.Id))
|
||||
.ForMember(x => x.Code, o => o.MapFrom(x => x.Currency.CurrencyGlobalId))
|
||||
.ForMember(x => x.Name, o => o.MapFrom(x => x.Currency.Name))
|
||||
.ForMember(x => x.ShortName, o => o.MapFrom(x => x.Currency.ShortName))
|
||||
.ForMember(x => x.Rate, o => o.MapFrom(x => x.Rate == null ? (decimal?)null : x.Rate.Rate))
|
||||
.ForMember(x => x.IsPrimary, o => o.MapFrom(x => x.Currency.IsPrimary))
|
||||
.ForMember(x => x.Quantity, o => o.MapFrom(x => x.Rate == null ? (int?)null : x.Rate.Quantity))
|
||||
.ForMember(x => x.RateDate, o => o.MapFrom(x => x.Rate == null ? (DateTime?)null : x.Rate.DateTime))
|
||||
;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class MotionsGetModel
|
||||
public class MotionsGetRequest
|
||||
{
|
||||
[Required]
|
||||
public DateTime From { get; set; }
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace MyOffice.Web.Models;
|
||||
|
||||
public class BaseViewModel : IResponseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Web.Models.Currency;
|
||||
|
||||
public class CurrencyRateViewModel: BaseViewModel
|
||||
{
|
||||
public string Currency { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public decimal Rate { get; set; }
|
||||
}
|
||||
@@ -1,38 +1,14 @@
|
||||
namespace MyOffice.Web.Models.Currency
|
||||
namespace MyOffice.Web.Models.Currency;
|
||||
|
||||
public class CurrencyViewModel: BaseViewModel
|
||||
{
|
||||
using Core.Extensions;
|
||||
using Data.Models.Currencies;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
||||
|
||||
public class CurrencyViewModel
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public string Code { get; set; } = null!;
|
||||
public string Symbol { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
public decimal? Rate { get; set; }
|
||||
public int? Quantity { get; set; }
|
||||
public DateTime? RateDate { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
|
||||
public static class CurrencyViewModelExtensions
|
||||
{
|
||||
public static CurrencyViewModel ToModel(this Currency input, CurrencyRate? rate = null)
|
||||
{
|
||||
return new CurrencyViewModel
|
||||
{
|
||||
Id = input.Id.ToShort(),
|
||||
Code = input.CurrencyGlobal!.Id,
|
||||
Symbol = input.CurrencyGlobal!.Symbol,
|
||||
Name = input.Name,
|
||||
ShortName = input.ShortName,
|
||||
Quantity = input.CurrentRate?.Quantity ?? rate?.Quantity,
|
||||
Rate = input.CurrentRate?.Rate ?? rate?.Rate,
|
||||
RateDate = input.CurrentRate?.DateTime ?? rate?.DateTime,
|
||||
IsPrimary = input.IsPrimary,
|
||||
};
|
||||
}
|
||||
}
|
||||
public string Id { get; set; } = null!;
|
||||
public string Code { get; set; } = null!;
|
||||
public string Symbol { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
public decimal? Rate { get; set; }
|
||||
public int? Quantity { get; set; }
|
||||
public DateTime? RateDate { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace MyOffice.Web.Models;
|
||||
|
||||
public interface IRequestModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace MyOffice.Web.Models;
|
||||
|
||||
public interface IResponseModel
|
||||
{
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Item
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
using MyOffice.Migrations.Postgres.Migrations;
|
||||
using Services.Account.Domain;
|
||||
|
||||
public class ItemCategoryViewModel
|
||||
{
|
||||
@@ -14,32 +12,20 @@
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public bool IsInternal { get; set; }
|
||||
public bool Internal { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemCategoryViewModelExtensions
|
||||
{
|
||||
public static ItemCategoryViewModel ToModel(this ItemCategory input)
|
||||
{
|
||||
return new ItemCategoryViewModel
|
||||
{
|
||||
Id = input.Id.ToShort(),
|
||||
Name = input.Name,
|
||||
AllowDelete = !input.Items.Any() && input.Id != input.UserId,
|
||||
IsInternal = input.IsInternal,
|
||||
SortOrder = input.Id == input.UserId ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
public static ItemCategory FromModel(this ItemCategoryViewModel input)
|
||||
public static ItemCategoryDto FromModel(this ItemCategoryViewModel input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
return new ItemCategory
|
||||
return new ItemCategoryDto
|
||||
{
|
||||
Name = input.Name,
|
||||
IsInternal = input.IsInternal,
|
||||
IsInternal = input.Internal,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,17 @@
|
||||
namespace MyOffice.Web.Models.Item
|
||||
namespace MyOffice.Web.Models.Item;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class ItemViewModel : BaseViewModel
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Data.Models.Accounts;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
public string? Id { get; set; }
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
public class ItemViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool AllowDelete { get; set; }
|
||||
|
||||
public string CategoryId { get; set; } = null!;
|
||||
public string? Category { get; set; } = null!;
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
public string CategoryId { get; set; } = null!;
|
||||
public string? Category { get; set; } = null!;
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public string? AccountId { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemViewModelExtensions
|
||||
{
|
||||
public static ItemViewModel ToModel(this Item input, Account? account = null)
|
||||
{
|
||||
return new ItemViewModel
|
||||
{
|
||||
Id = input.ItemGlobal.Id.ToShort(),
|
||||
CategoryId = input.CategoryId.ToShort(),
|
||||
Category = input.Category?.Name,
|
||||
Name = input.ItemGlobal.Name,
|
||||
AllowDelete = input.Motions != null && !input.Motions.Any(),
|
||||
AccountId = account?.Id.ToShort(),
|
||||
};
|
||||
}
|
||||
}
|
||||
public string? AccountId { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
namespace MyOffice.Web.Models.Motion
|
||||
{
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
|
||||
public class MotionViewModel
|
||||
public class MotionViewModel: BaseViewModel
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public DateTime Date { get; set; }
|
||||
@@ -13,20 +10,4 @@
|
||||
public decimal Plus { get; set; }
|
||||
public decimal Minus { get; set; }
|
||||
}
|
||||
|
||||
public static class MotionViewModelExtensions
|
||||
{
|
||||
public static MotionViewModel ToModel(this Motion input)
|
||||
{
|
||||
return new MotionViewModel
|
||||
{
|
||||
Id = input.Id.ToShort(),
|
||||
Date = input.DateTime,
|
||||
Item = input.Item.ItemGlobal.Name,
|
||||
Description = input.Description,
|
||||
Plus = input.AmountPlus,
|
||||
Minus = input.AmountMinus,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
namespace MyOffice.Web.Models;
|
||||
|
||||
using AutoMapper;
|
||||
using Core.Extensions;
|
||||
@@ -44,8 +44,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MyOffice.Core\MyOffice.Core.csproj" />
|
||||
<ProjectReference Include="..\MyOffice.Data.Models\MyOffice.Data.Models.csproj" />
|
||||
<ProjectReference Include="..\MyOffice.Data.Repositories\MyOffice.Data.Repositories.csproj" />
|
||||
<ProjectReference Include="..\MyOffice.DbContext\MyOffice.DbContext.csproj" />
|
||||
<ProjectReference Include="..\MyOffice.Migration.Postgres\MyOffice.Migrations.Postgres.csproj" />
|
||||
<ProjectReference Include="..\MyOffice.Migration.Sqlite\MyOffice.Migrations.Sqlite.csproj" />
|
||||
|
||||
+11
-13
@@ -2,7 +2,6 @@ namespace MyOffice.Web;
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Core.Extensions;
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.FileProviders.Physical;
|
||||
@@ -13,19 +12,22 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Identity;
|
||||
using Identity.Domain;
|
||||
using Identity.ExternalProviders;
|
||||
using Identity.Repositories;
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using IdentityServer4.Configuration;
|
||||
using IdentityServer4.Extensions;
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer4.Services;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Identity;
|
||||
using Identity.Domain;
|
||||
using Identity.ExternalProviders;
|
||||
using Identity.Repositories;
|
||||
using Core.Identity;
|
||||
using Core.Extensions;
|
||||
using Data.Repositories.Account;
|
||||
using Data.Repositories.Currency;
|
||||
using Data.Repositories.Item;
|
||||
@@ -35,17 +37,12 @@ using Services.Users;
|
||||
using Shared;
|
||||
using Identity.Configure;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using IdentityServer4.Services;
|
||||
using Models.Account;
|
||||
using MyOffice.Services.Currency;
|
||||
using Services.Account;
|
||||
using Services.Item;
|
||||
using MyOffice.Services.Dashboard;
|
||||
using MyOffice.Services.Identity;
|
||||
using AutoMapper;
|
||||
using Models.Motion;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using MyOffice.Services.Mapper;
|
||||
|
||||
//TODO: Data.Model only Repository and Service, response <-> mapper <-> web <-> mapper <-> service <-> repository
|
||||
@@ -68,9 +65,10 @@ using MyOffice.Services.Mapper;
|
||||
//TODO: Services auto registration
|
||||
//TODO: openid-configuration failed - lock login
|
||||
//TODO: BUG some times after login redirect to dashboard but exists return url
|
||||
//TODO: email confirmation
|
||||
//TODO: email password reset
|
||||
//TODO: automapper -> Extension ToModel() ToDbo() FromModel() FromDbo()
|
||||
//TODO: SPA all http requests -> services
|
||||
//TODO: Items, select category -> save url to allow refresh
|
||||
//TODO: Accounts, select category -> save url to allow refresh
|
||||
|
||||
public class Program
|
||||
{
|
||||
|
||||
@@ -15,3 +15,9 @@ wsl host folders
|
||||
|
||||
terminal history to file
|
||||
history > history_for_print.txt
|
||||
|
||||
ssh remote
|
||||
ssh root@192.168.1.215 'systemctl status service.name'
|
||||
|
||||
update remote
|
||||
rsync -r --progress --exclude appsettings*.json _Published/ root@192.168.1.215:/var/www/XXX
|
||||
Reference in New Issue
Block a user