public async Task <ApiResponse <NESInvoice> > Insert(NESInvoice nesInvoice) { var isValidNesVoice = Validator.IsValidNESInvoice(nesInvoice); if (!isValidNesVoice.Key) { return(ResponseHelper.CreateApiResponse <NESInvoice>(null, isValidNesVoice.Value, 400, true)); } var connector = new DbConnector(_configuration.GetConnectionString("NilveraDb")); await connector.Insert <PartyInfo>("insert into PartyInfo(register_number,name,address,district,city,country) values(@RegisterNumber," + "@Name,@Address,@District,@City,@Country)", new[] { nesInvoice.CustomerInfo }); await connector.Insert <PartyInfo>("insert into PartyInfo(register_number,name,address,district,city,country) values(@RegisterNumber," + "@Name,@Address,@District,@City,@Country)", new[] { nesInvoice.CompanyInfo }); await connector.Insert <InvoiceInfo>("insert into InvoiceInfo(uuid,invoice_seri_or_number) values(@UUID,@InvoiceSerieOrNumber)", new [] { nesInvoice.InvoiceInfo }); if (nesInvoice.ExportCustomerInfo != null) { await connector.Insert <ExportCustomerInfo>("insert into ExportCustomerInfo(party_name,person_name) values(@PartyName,@PersonName)", new [] { nesInvoice.ExportCustomerInfo }); } await connector.Insert <object>("insert into NESInvoice(id,invoice_info_id,ise_archive_invoice,customer_info_id,company_info_id) values(@Id,@InvoiceInfoId," + "@IseArchive,@CustomerInfoId,@CompanyInfoId)", new [] { new { Id = Guid.NewGuid().ToString(), InvoiceInfoId = nesInvoice.InvoiceInfo.UUID, IseArchive = nesInvoice.ISEArchiveInvoice, CustomerInfoId = nesInvoice.CustomerInfo.RegisterNumber, CompanyInfoId = nesInvoice.CompanyInfo.RegisterNumber } }); return(ResponseHelper.CreateApiResponse <NESInvoice>(default(NESInvoice), "Success", 201, false)); }
public static KeyValuePair <bool, string> IsValidNESInvoice(NESInvoice nesInvoice) { KeyValuePair <bool, string> pair; if (nesInvoice.CompanyInfo == null) { pair = FillToPairs(false, "CompanyInfo"); } else if (nesInvoice.CustomerInfo == null) { pair = FillToPairs(false, "CustomerInfo"); } else if (nesInvoice.InvoiceInfo == null) { pair = FillToPairs(false, "InvoiceInfo"); } else if (nesInvoice.InvoiceLines == null) { pair = FillToPairs(false, "InvoiceLines"); } else { pair = FillToPairs(true, ""); } return(pair); }