public long AddMasterAccount(MasterAccountCreateEditModel modelParam) { var dto = _mapper.Map <MasterAccount>(modelParam); var entry = _masterAccountRepository.Query().FirstOrDefault(acc => acc.Deleted && acc.AccountName == dto.AccountName); // restore existing account if (entry != null) { var existingAccount = entry; entry = _masterAccountRepository.GetEntry(new MasterAccount { AccountAlias = dto.AccountAlias }); if (entry != null) { _actionContext.SetModelError("accountAlias", "Account alias is busy"); } _actionContext.ThrowIfModelInvalid(); existingAccount.Deleted = false; existingAccount.AccountAlias = dto.AccountAlias; existingAccount.UpdatedById = _identityService.GetIdentityId(); return(_masterAccountRepository.Update(existingAccount).Id); } entry = _masterAccountRepository.GetEntry(new MasterAccount { AccountAlias = dto.AccountAlias }); if (entry != null) { _actionContext.SetModelError("accountAlias", "Account alias is busy"); } entry = _masterAccountRepository.GetEntry(new MasterAccount { AccountName = dto.AccountName }); if (entry != null) { _actionContext.SetModelError("accountName", "Account name is busy"); } _actionContext.ThrowIfModelInvalid(); dto.CreatedById = _identityService.GetIdentityId(); dto = _masterAccountRepository.Add(dto); return(dto.Id); }
public IActionResult AddMasterAccount([FromBody] MasterAccount model) { Master_repo.Add(model); return(new OkObjectResult(new { MasterAccountID = model.MasterAccountId })); }