public GetBankAccountDto Add(CreateBankAccountDto bankAccountDto) { var bankAccount = _mapper.Map <BankAccount>(bankAccountDto); var bankAccountInDb = _unitOfWork.BankAccountRepository.Add(bankAccount); _unitOfWork.SaveChanges(); return(_mapper.Map <GetBankAccountDto>(bankAccountInDb)); }
public IActionResult Post([FromHeader(Name = "username")] string userName, CreateBankAccountDto toCreateBankAccount) { Guid createdBankAccountid; using (var context = _contextFactory.CreateContext()) { createdBankAccountid = _service.Create(context, userName, toCreateBankAccount); } var currentUrl = UriHelper.GetDisplayUrl(Request); return(Created($"{currentUrl}/{createdBankAccountid}", null)); }
public Guid Create(IContext context, string userName, CreateBankAccountDto toCreateBankAccount) { Validate(toCreateBankAccount); var bankAccountId = Guid.NewGuid(); var bankAccountRepository = context.GetRepository <BankAccount>(); var operationTypeRepository = context.GetRepository <OperationType>(); var userBankAccountRepository = context.GetRepository <UserBankAccount>(); var userRepository = context.GetRepository <User>(); var user = userRepository.SingleOrDefault(new UserByUserNameSpecification(userName)); if (user == null) { throw new DaGetUnauthorizedException("Utilisateur inconnu"); } bankAccountRepository.Add(new BankAccount() { Balance = toCreateBankAccount.InitialBalance.Value, OpeningBalance = toCreateBankAccount.InitialBalance.Value, ActualBalance = toCreateBankAccount.InitialBalance.Value, BankAccountTypeId = toCreateBankAccount.BankAccountTypeId.Value, Id = bankAccountId, Wording = toCreateBankAccount.Wording }); foreach (var operationType in toCreateBankAccount.OperationsTypes) { operationTypeRepository.Add(new OperationType() { Id = Guid.NewGuid(), BankAccountId = bankAccountId, Wording = operationType }); } userBankAccountRepository.Add(new UserBankAccount() { BankAccountId = bankAccountId, Id = Guid.NewGuid(), IsOwner = true, IsReadOnly = false, UserId = user.Id }); context.Commit(); return(bankAccountId); }
public IActionResult Create(CreateBankAccountDto createBankAccountDto) { var bankAccount = _bankAccountService.Add(createBankAccountDto); return(CreatedAtAction(nameof(Get), new { id = bankAccount.Id }, bankAccount)); }