fix
This commit is contained in:
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -76,7 +77,8 @@ public class AccountController : BaseApiController
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.Select(x => x.ToModel());
|
||||
//return exec.Result!.Select(x => x.ToModel());
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -86,7 +88,7 @@ public class AccountController : BaseApiController
|
||||
[HttpPost("~/api/accounts/{id}/motions")]
|
||||
public object MotionsPost(string id, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionAdd(UserId, id.AsGuid(), motion.FromModel());
|
||||
var exec = _accountService.MotionAdd(UserId, id.AsGuid(), _mapper.Map<MotionAddUpdate>(motion));
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
@@ -95,7 +97,7 @@ public class AccountController : BaseApiController
|
||||
case MotionAddResult.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
case MotionAddResult.success:
|
||||
return exec.Result!.ToModel();
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -105,7 +107,7 @@ public class AccountController : BaseApiController
|
||||
[HttpPut("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionUpdate(UserId, id.AsGuid(), motionId.AsGuid(), motion.FromModel());
|
||||
var exec = _accountService.MotionUpdate(UserId, id.AsGuid(), motionId.AsGuid(), _mapper.Map<MotionAddUpdate>(motion));
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
@@ -154,7 +156,7 @@ public class AccountController : BaseApiController
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var accountName = $"+{account.Name}";
|
||||
var item = items.FirstOrDefault(x => x.Name == accountName);
|
||||
var item = items.FirstOrDefault(x => x.Name.IsPresent() && x.Name!.Length > 1 && x.Name.Substring(1) == accountName);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace MyOffice.Web.Models.Motion;
|
||||
|
||||
using AutoMapper;
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
|
||||
public class AccountControllerProfile : Profile
|
||||
{
|
||||
public AccountControllerProfile()
|
||||
{
|
||||
CreateMap<MotionRequest, MotionAddUpdate>();
|
||||
|
||||
CreateMap<Motion, MotionViewModel>()
|
||||
.ForMember(x => x.Date, o => o.MapFrom(x => x.DateTime))
|
||||
.ForMember(x => x.Item, o => o.MapFrom(x => x.Item.ItemGlobal.Name))
|
||||
.ForMember(x => x.Plus, o => o.MapFrom(x => x.AmountPlus))
|
||||
.ForMember(x => x.Minus, o => o.MapFrom(x => x.AmountMinus))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,13 @@
|
||||
namespace MyOffice.Web.Models.Motion;
|
||||
|
||||
using MyOffice.Services.Account.Domain;
|
||||
|
||||
public class MotionRequest
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public string Item { get; set; } = null!;
|
||||
public string? ItemId { get; set; } = null!;
|
||||
public string? AccountId { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal? Plus { get; set; }
|
||||
public decimal? Minus { get; set; }
|
||||
}
|
||||
|
||||
public static class MotionRequestExtension
|
||||
{
|
||||
public static MotionAddUpdate FromModel(this MotionRequest input)
|
||||
{
|
||||
return new MotionAddUpdate
|
||||
{
|
||||
Date = input.Date,
|
||||
Item = input.Item,
|
||||
Minus = input.Minus ?? 0,
|
||||
Plus = input.Plus ?? 0,
|
||||
Description = input.Description,
|
||||
};
|
||||
}
|
||||
}
|
||||
public decimal? AmountBalancing { get; set; }
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public DateTime Date { get; set; }
|
||||
public string AccountId { get; set; } = null!;
|
||||
public string Item { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal Plus { get; set; }
|
||||
|
||||
+10
-5
@@ -45,6 +45,13 @@ using MyOffice.Services.Dashboard;
|
||||
using Services.Account.Domain;
|
||||
using MyOffice.Services.Identity;
|
||||
using AutoMapper;
|
||||
using Models.Motion;
|
||||
|
||||
//TODO: Data.Model only Repository and Service, response <-> mapper <-> web <-> mapper <-> service <-> repository
|
||||
//TODO: Project management
|
||||
//TODO: Model names. Controller = xxxRequest/xxxResponse. Service xxxInput/xxxOutput.
|
||||
//TODO: Validate string as Guid when id
|
||||
//TODO: Logging
|
||||
|
||||
public class Program
|
||||
{
|
||||
@@ -217,14 +224,12 @@ public class Program
|
||||
{
|
||||
builder.Services.AddSingleton(provider => new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddProfile(new AccountMappingProfile());
|
||||
cfg.AddProfile(new AccountServiceProfile());
|
||||
cfg.AddProfile(new ViewModelProfile());
|
||||
cfg.AddProfile(new AccountViewModelProfile(provider.CreateScope().ServiceProvider.GetService<IContextProvider>()!));
|
||||
}).CreateMapper());
|
||||
|
||||
//builder.Services.AddAutoMapper(typeof(AccountMappingProfile));
|
||||
//builder.Services.AddAutoMapper(typeof(AccountViewModelProfile));
|
||||
//builder.Services.AddAutoMapper(typeof(ViewModelProfile));
|
||||
cfg.AddProfile(new AccountControllerProfile());
|
||||
}).CreateMapper());
|
||||
}
|
||||
|
||||
private static void AddRepositories(WebApplicationBuilder builder)
|
||||
|
||||
Reference in New Issue
Block a user