public async Task <int?> GetOrSetEmployeeIdByNameAsync(string name) { if (String.IsNullOrEmpty(name)) { return(null); } var companyId = await employeeRepository.Context.Companies.OrderBy(c => c.Id).Select(c => c.Id).LastOrDefaultAsync(); var employee = await employeeRepository.AllAsNoTracking().Where(e => e.CompanyId == companyId && e.FullName == name).FirstOrDefaultAsync(); if (employee != null) { return(employee.Id); } var newEmployee = new Employee() { FullName = name, CompanyId = companyId, }; await employeeRepository.AddAsync(employee); await employeeRepository.SaveChangesAsync(); return(newEmployee.Id); }
public async Task <int> Create(PartnerDto partnerDto) { var partner = new Partner() { Name = partnerDto.Name, Country = partnerDto.Country, City = partnerDto.City, Address = partnerDto.Address, EIK = partnerDto.EIK, IsVatRegistered = partnerDto.IsVatRegistered, VatId = partnerDto.VatId, Email = partnerDto.Email, IsActive = partnerDto.IsActive, MOL = partnerDto.MOL, }; var employee = new Employee() { FullName = partnerDto.MOL, IsActive = true, }; partner.Employees.Add(employee); await partnerRepository.AddAsync(partner); await partnerRepository.SaveChangesAsync(); return(partner.Id); }
public async Task Create(VatTypeDto vatTypeDto) { if (vatTypeDto.IsActive == true) { SetAllNonActive(); } var vatType = new VatType(); vatType.Name = vatTypeDto.Name; vatType.Description = vatTypeDto.Description; vatType.Percantage = vatTypeDto.Percantage; vatType.IsActive = vatTypeDto.IsActive; await vatTypeRepository.AddAsync(vatType); await vatTypeRepository.SaveChangesAsync(); }
public async Task Create(EmployeeDto employeeDto, int companyId) { if (employeeDto.IsActive == true) { SetAllNonActive(companyId); } var employee = new Employee() { FullName = employeeDto.FullName, IsActive = employeeDto.IsActive, PartnerId = companyId, }; await employeeRepository.AddAsync(employee); await employeeRepository.SaveChangesAsync(); }
public async Task <NonVatDocumentDto> CreateNonVatDocumentAsync(NonVatDocumentDto nonVatDocumentDto) { var documentId = await GetNewNonVatDocumentIdAsync(nonVatDocumentDto); if (documentId > nonVatDocumentDto.Id) { nonVatDocumentDto.ErrorMassages.Add($"Има вече издаден документ с №{nonVatDocumentDto.Id}, документа ще бъде издаден с № {new string('0', 10 - documentId.ToString().Length) + documentId.ToString()}"); nonVatDocumentDto.Id = documentId; return(nonVatDocumentDto); } if (nonVatDocumentDto.PartnerId == 0) { nonVatDocumentDto.ErrorMassages.Add($"Моля въведете контрагент!"); return(nonVatDocumentDto); } var companyId = await NonVatDocumentRepo.Context.Companies.OrderBy(c => c.Id).Select(c => c.Id).LastAsync(); var document = new NonVatDocument(); document.Id = nonVatDocumentDto.Id; document.CompanyObjectId = await NonVatDocumentRepo.Context.CompanyObjects .Where(o => o.GUID == userCompanyTemp.CompanyObjectGUID) .Select(o => o.Id) .FirstOrDefaultAsync(); document.PartnerId = nonVatDocumentDto.PartnerId; document.CompanyId = companyId; document.WriterEmployeeId = await employeeService.GetOrSetEmployeeIdByNameAsync(nonVatDocumentDto.WriterEmployee); document.RecipientEmployeeId = await partnerEmployeeService.GetOrSetEmployeeIdByNameAsync(nonVatDocumentDto.RecipientEmployee, nonVatDocumentDto.PartnerId); document.CreatedDate = SetDate(nonVatDocumentDto.CreatedDate, nonVatDocumentDto); document.VatReasonDate = SetDate(nonVatDocumentDto.VatReasonDate, nonVatDocumentDto); document.PaymentTypeId = nonVatDocumentDto.PaymentTypeId; document.BankAccountId = await GetBankAccountIdIfRequare(nonVatDocumentDto); document.Type = (Data.CompanyData.Models.Enums.NonVatDocumentTypes)nonVatDocumentDto.Type; document.FreeText = nonVatDocumentDto.FreeText; document.Description = nonVatDocumentDto.Description; await ProcessingSales(nonVatDocumentDto); document.SubTottal = nonVatDocumentDto.SubTottal; document.Vat = nonVatDocumentDto.Vat; document.Tottal = nonVatDocumentDto.Tottal; if (nonVatDocumentDto.HasErrors) { return(nonVatDocumentDto); } await NonVatDocumentRepo.AddAsync(document); await NonVatDocumentRepo.SaveChangesAsync(); return(nonVatDocumentDto); }
public async Task Create(QuantityTypeDto quantityTypeDto) { if (quantityTypeDto.IsActive == true) { SetAllNonActive(); } var quantityType = new QuantityType() { Type = quantityTypeDto.Type, Description = quantityTypeDto.Description, IsActive = quantityTypeDto.IsActive, }; await quantityTypeRepository.AddAsync(quantityType); await quantityTypeRepository.SaveChangesAsync(); }
public async Task Create(PaymentTypeDto paymentTypeDto) { if (paymentTypeDto.IsActiv == true) { SetAllNonActive(); } var paymentType = new PaymentType() { Name = paymentTypeDto.Name, Description = paymentTypeDto.Description, IsActiv = paymentTypeDto.IsActiv, RequireBankAccount = paymentTypeDto.RequiredBankAccount, }; await paymentTypeRepository.AddAsync(paymentType); await paymentTypeRepository.SaveChangesAsync(); }
public async Task Create(ProductDto productDto) { var company = await productRepositoy.Context.Companies.OrderBy(c => c.Id).LastOrDefaultAsync(); var product = new Product() { Name = productDto.Name, Description = productDto.Description, Barcode = productDto.Barcode, Price = productDto.Price, BasePrice = productDto.BasePrice, Quantity = productDto.Quantity, VatTypeId = productDto.VatTypeId, QuantityTypeId = productDto.QuantityTypeId, CompanyId = company.Id, }; await productRepositoy.AddAsync(product); await productRepositoy.SaveChangesAsync(); }
public async Task Create(BankAccountDto bankAccountDto, int companyId) { if (bankAccountDto.IsActive == true) { SetAllNonActive(companyId); } var bankAccount = new BankAccount() { Name = bankAccountDto.Name, BankName = bankAccountDto.BankName, BIC = bankAccountDto.BIC, IBAN = bankAccountDto.IBAN, Description = bankAccountDto.Description, IsActive = bankAccountDto.IsActive, PartnerId = companyId, }; await bankAccountRepository.AddAsync(bankAccount); await bankAccountRepository.SaveChangesAsync(); }
public async Task Create(BankAccountDto bankAccountDto) { var company = bankAccountRepository.Context.Companies.OrderBy(c => c.Id).LastOrDefault(); if (bankAccountDto.IsActive == true) { await SetAllNonActive(); } var bankAccount = new BankAccount() { Name = bankAccountDto.Name, BankName = bankAccountDto.BankName, BIC = bankAccountDto.BIC, IBAN = bankAccountDto.IBAN, Description = bankAccountDto.Description, IsActive = bankAccountDto.IsActive, CompanyId = company.Id, }; await bankAccountRepository.AddAsync(bankAccount); await bankAccountRepository.SaveChangesAsync(); }