diff --git a/MyOffice.Services/Account/AccountService.cs b/MyOffice.Services/Account/AccountService.cs index 55677c6..f6da905 100644 --- a/MyOffice.Services/Account/AccountService.cs +++ b/MyOffice.Services/Account/AccountService.cs @@ -308,7 +308,7 @@ if (!_accountMotionRepository.Add(accountMotionDb)) { - return result.Set(GeneralExecStatus.failure); + return result.Set(AccountMotionAddResult.failure); } diff --git a/MyOffice.Services/Account/Domain/AccountMotionAdd.cs b/MyOffice.Services/Account/Domain/AccountMotionAdd.cs index b069ebf..0cf8aed 100644 --- a/MyOffice.Services/Account/Domain/AccountMotionAdd.cs +++ b/MyOffice.Services/Account/Domain/AccountMotionAdd.cs @@ -4,7 +4,7 @@ { public DateTime Date { get; set; } public string Motion { get; set; } = null!; - public string Description { get; set; } = null!; + public string? Description { get; set; }; public decimal Plus { get; set; } public decimal Minus { get; set; } } diff --git a/MyOffice.Web/Controllers/AccountController.cs b/MyOffice.Web/Controllers/AccountController.cs index b91d975..26e50ee 100644 --- a/MyOffice.Web/Controllers/AccountController.cs +++ b/MyOffice.Web/Controllers/AccountController.cs @@ -4,8 +4,10 @@ using Core.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Models.Account; +using MyOffice.Data.Models.Accounts; using MyOffice.Web.Models.AccountMotion; using Services.Account; +using Services.Account.Domain; [Authorize] [ApiController] @@ -43,8 +45,18 @@ public class AccountController : BaseApiController [HttpPost("~/api/accounts/{id}/motions")] public object AccountsMotionsPost(string id, AccountMotionRequest accountMotion) { - var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid()); + var exec = _accountService.AccountMotionAdd(UserId, id.AsGuid(), accountMotion.FromModel()); + switch (exec.Status) + { + case AccountMotionAddResult.account_not_found: + return ProblemBadRequest("Account failed."); + case AccountMotionAddResult.failure: + return ProblemBadRequest("Adding motion failed."); + case AccountMotionAddResult.success: + return exec.Result!; - return list.Select(x => x.ToModel()); + default: + throw new NotSupportedException(exec.Status.ToString()); + } } } \ No newline at end of file diff --git a/MyOffice.Web/Models/AccountMotion/AccountMotionViewModel.cs b/MyOffice.Web/Models/AccountMotion/AccountMotionViewModel.cs index 3590b39..d3eea7f 100644 --- a/MyOffice.Web/Models/AccountMotion/AccountMotionViewModel.cs +++ b/MyOffice.Web/Models/AccountMotion/AccountMotionViewModel.cs @@ -1,6 +1,7 @@ namespace MyOffice.Web.Models.AccountMotion; using Data.Models.Accounts; +using Services.Account.Domain; public class AccountMotionViewModel { @@ -27,13 +28,16 @@ public static class AccountMotionViewModelExtension public static class AccountMotionRequestExtension { - public static AccountMotion FromModel(this AccountMotionRequest input) + public static AccountMotionAdd FromModel(this AccountMotionRequest input) { - /*return new AccountMotion + return new AccountMotionAdd { - CreatedOn = input.Date, - mo - };*/ + Date = input.Date, + Motion = input.Motion, + Minus = input.Minus, + Plus = input.Plus, + Description = input.Description, + }; } }