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 long UpdateMasterAccount(MasterAccountCreateEditModel modelParam) { var dto = _mapper.Map <MasterAccount>(modelParam); if (!_masterAccountRepository.IsExists(new MasterAccount { Id = dto.Id })) { throw new MasterAccountNotFoundException(); } var entry = _masterAccountRepository.GetEntry(new MasterAccount { AccountAlias = dto.AccountAlias }); if (entry != null && entry.Id != dto.Id) { _actionContext.SetModelError("accountAlias", "Account alias is busy"); } entry = _masterAccountRepository.GetEntry(new MasterAccount { AccountName = dto.AccountName }); if (entry != null && entry.Id != dto.Id) { _actionContext.SetModelError("accountName", "Account name is busy"); } _actionContext.ThrowIfModelInvalid(); var existingAccount = _masterAccountRepository.GetById(dto.Id); existingAccount.UpdatedById = _identityService.GetIdentityId(); existingAccount.AccountName = modelParam.AccountName; existingAccount.AccountAlias = modelParam.AccountAlias; existingAccount = _masterAccountRepository.Update(existingAccount); return(existingAccount.Id); }
public IHttpActionResult AddNewAccountMaster(MasterAccountCreateEditModel modelParam) { return(Ok(_masterAccountService.AddMasterAccount(modelParam))); }
public IHttpActionResult UpdateMasterAccount(MasterAccountCreateEditModel modelParam) { return(Ok(_masterAccountService.UpdateMasterAccount(modelParam))); }