private async Task SaveInvoiceFile(ZubairEntities dbContext, Guid invoiceItemId, dynamic invFile)
        {
            int?invoiceFileId = invFile.id;

            if (invoiceFileId != null)
            {
                var invoiceFile = await dbContext.invoicefiles.Where(c => c.id == invoiceFileId).FirstOrDefaultAsync();

                // create file
                if (invoiceFile != null)
                {
                    invoiceFile.invoice_item_id = invFile.invoiceItemId;
                    invoiceFile.name            = invFile.name;

                    invoiceFile.filelocation = GetFilePath(invoiceFile.name);
                }
            }
            else
            {
                var tempInvoiceFile = new invoicefile
                {
                    invoice_item_id = invoiceItemId,
                    name            = invFile.name
                };

                tempInvoiceFile.filelocation = GetFilePath(tempInvoiceFile.name);
                dbContext.invoicefiles.Add(tempInvoiceFile);
            }
            await dbContext.SaveChangesAsync();
        }
示例#2
0
        public async Task <(bool IsSuccess, string ErrorMessage)> CreateInvoiceFile(InvoiceFile invoiceFile)
        {
            try
            {
                using (ZubairEntities dbContext = new ZubairEntities())
                {
                    if (invoiceFile != null)
                    {
                        var tempInvoiceFile = new invoicefile();
                        tempInvoiceFile.invoice_item_id = invoiceFile.InvoiceItemId;
                        tempInvoiceFile.name            = invoiceFile.Name;
                        tempInvoiceFile.filelocation    = invoiceFile.FileLocation;
                        dbContext.invoicefiles.Add(tempInvoiceFile);
                        await dbContext.SaveChangesAsync();

                        return(true, null);
                    }
                }
                return(false, "Not Found");
            }
            catch (Exception ex)
            {
                //logger?.LogError(ex.ToString());
                return(false, ex.Message);
            }
        }