public async Task <IActionResult> GetAll() { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var allData = _dbContext.Set <DigitalSignature>().Where(x => x.CompanyId == currentUser.CompanyId).ToList(); return(Ok(allData)); }
public async Task <Response <int> > Handle(CreateNewContractCommand request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var contract = new Domain.Entities.Contract { CompanyId = currentUser.CompanyId.Value, ContractTypeId = request.ContractTypeId, ExpiredDate = request.ContractExpiredDate, Status = ContractStatus.Draft, TotalValue = request.ContractValue, CreatedBy = currentUser.UserName, Created = DateTime.Now, ContractPlace = request.ContractPlace, Content = request.ContractContent, Name = request.ContractName, ContractNum = request.ContractNum, Title = request.ContractTitle, CustomerId = request.CustomerId, Header = request.Header, AInformation = request.AInformation, BInformation = request.BInformation, ContractValue = request.Value, ContractLaw = request.ContractLaw, Footer = request.Footer, BelongToContractId = request.BelongToContractId }; await _contractRepository.AddAsync(contract); return(new Response <int>(contract.Id)); }
public async Task <Response <bool> > Handle(UpdateCompanyByCompanyCommand request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var company = await _companyRepository.GetByIdAsync(request.Id); if (company == null) { throw new ApiException("Company does not exist. "); } if (currentUser.CompanyId != company.Id) { throw new ApiException("Can not update other company."); } company.Name = request.Name; company.Address = request.Address; company.PhoneNumber = request.PhoneNumber; company.Email = request.Email; company.TaxCode = request.TaxCode; company.BankAccount = request.BankAccount; company.BusinessLicense = request.BusinessLicense; company.Representaive = request.Representaive; await _companyRepository.UpdateAsync(company); return(new Response <bool>(true)); }
public async Task <Response <List <GetAllContractsViewModel> > > Handle(GetAllContracsQuery request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var contracts = _contractRepository.GetAllContracts(currentUser.CompanyId.Value); if (request.FromDate.HasValue) { contracts = contracts.Where(x => x.Created >= request.FromDate.Value).ToList(); } if (request.ToDate.HasValue) { contracts = contracts.Where(x => x.Created <= request.ToDate.Value.Date).ToList(); } var result = contracts.Select(x => new GetAllContractsViewModel { Id = x.Id, ContractName = x.Name, ContractNum = x.ContractNum, ContractPlace = x.ContractPlace, ContractContent = x.Content, ContractTypeId = x.ContractTypeId, ContractExpiredDate = x.ExpiredDate.Value, ContractValue = x.TotalValue, ContractTitle = x.Title, Customer = new CustomerViewModel { Id = x.CustomerId, CompanyName = x.Customer.Name }, Status = x.Status, FileUrl = x.FileUrl, Header = x.Header, AInformation = x.AInformation, BInformation = x.BInformation, ContractLaw = x.ContractLaw, Footer = x.Footer, ContractStringValue = x.ContractValue, CustomerId = x.CustomerId, IsMainContract = !x.BelongToContractId.HasValue, BelongToContractId = x.BelongToContractId }).ToList(); return(new Response <List <GetAllContractsViewModel> >(result)); }
public async Task <Response <bool> > Handle(CreateContractTypeCommand request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var contractType = new HiSign.Domain.Entities.ContractType { CompanyId = currentUser.CompanyId.GetValueOrDefault(), Content = request.Content, Name = request.Name, CreatedBy = currentUser.UserName, LastModified = DateTime.Now }; await _contractTypeRepository.AddAsync(contractType); return(new Response <bool>(true)); }
public async Task <Response <IEnumerable <GetAllContractTypeViewModel> > > Handle(GetAllContractTypesQuery request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var contracTypes = await _contractTypeRepository.GetAllByCompanyIdAsync(currentUser.CompanyId.GetValueOrDefault()); var res = contracTypes.Select(x => new GetAllContractTypeViewModel { Id = x.Id, Name = x.Name, Content = x.Content, CreatedBy = x.CreatedBy, CreatedDate = x.Created }); return(new Response <IEnumerable <GetAllContractTypeViewModel> >(res)); }
public async Task <Response <bool> > Handle(UpdateContractTypeCommand request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var contractType = await _contractTypeRepository.GetByIdAsync(request.Id); if (contractType == null) { throw new ApiException($"ContractType Id {request.Id} does not exist."); } contractType.Content = request.Content; contractType.Name = request.Name; contractType.LastModified = DateTime.Now; contractType.LastModifiedBy = currentUser.UserName; await _contractTypeRepository.UpdateAsync(contractType); return(new Response <bool>(true)); }
public async Task <Response <List <GetAllCustomerViewModel> > > Handle(GetAllCustomerQuery request, CancellationToken cancellationToken) { var currentUserLogin = await _authenticatedUserService.GetCurentApplicationUser(); var customers = _customerRepository.GetAllCustomers(currentUserLogin.CompanyId.Value); var result = customers.Select(x => new GetAllCustomerViewModel { Id = x.Id, CompanyId = x.CompanyId, BankAccount = x.BankAccount, Address = x.Address, Name = x.Name, PhoneNumber = x.PhoneNumber, Email = x.Email, TaxCode = x.TaxCode, BusinessLicense = x.BusinessLicense }).ToList(); return(new Response <List <GetAllCustomerViewModel> >(result)); }
public async Task <Response <CompanyViewModel> > Handle(GetCompanyinfoQuery request, CancellationToken cancellationToken) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); var company = await _companyRepository.GetByIdAsync(currentUser.CompanyId.Value); var result = new CompanyViewModel { Id = company.Id, Name = company.Name, Address = company.Address, PhoneNumber = company.PhoneNumber, TaxCode = company.TaxCode, BankAccount = company.BankAccount, BusinessLicense = company.BusinessLicense, Email = company.Email }; return(new Response <CompanyViewModel>(result)); }
public async Task <Response <int> > Handle(CreateCustomerCommand request, CancellationToken cancellationToken) { var currentUserLogin = await _authenticatedUserService.GetCurentApplicationUser(); Domain.Entities.Customer customer = null; if (request.CompanyId.HasValue) { if (request.CompanyId.Value == currentUserLogin.CompanyId) { throw new ApiException("Can not add your company to customer list"); } var company = await _companyRepository.GetByIdAsync(request.CompanyId.Value); if (company is null) { throw new ApiException("Company ID does not exist."); } bool isExist = await _customerRepository.Exist(currentUserLogin.CompanyId.Value, company.Id); if (isExist) { throw new ApiException($"{company.Name} already added to customer list."); } customer = new Domain.Entities.Customer { CompanyId = company.Id, BelongToCompanyId = currentUserLogin.CompanyId.GetValueOrDefault(), Address = company.Address, BankAccount = company.BankAccount, BusinessLicense = company.BusinessLicense, Email = company.Email, Name = company.Name, PhoneNumber = company.PhoneNumber, TaxCode = company.TaxCode, Representaive = company.Representaive }; } else { customer = new Domain.Entities.Customer { BelongToCompanyId = currentUserLogin.CompanyId.GetValueOrDefault(), Address = request.Address, BankAccount = request.BankAccount, BusinessLicense = request.BusinessLicense, Email = request.Email, Name = request.Name, PhoneNumber = request.PhoneNumber, TaxCode = request.TaxCode, Representaive = request.Representaive }; } await _customerRepository.AddAsync(customer); return(new Response <int>(customer.Id)); }
public async Task <IActionResult> CreateAccountAsync(RegisterEmployeeRequest request) { var currentUser = await _authenticatedUserService.GetCurentApplicationUser(); return(Ok(await _accountService.RegisterAsync(currentUser.CompanyId.Value, request))); }