public JsonResult Post([FromBody] PostInvoice aData) { Invoice invoice = Bl.RequestSendingInvoice(aData); if (invoice != null) { return(new JsonResult(new List <Invoice> { invoice })); } return(new JsonResult(null)); }
public Invoice RequestSendingInvoice(PostInvoice aInvoice) { //Validating data if (aInvoice.CompanyId == null) { return(null); } //Getting company from Id InformationBL bl = new InformationBL(); Company company = bl.GetCompanyFrom(aInvoice.CompanyId); if (company == null) { return(null); } //Getting active worker int activeWorkers = NumberOfActiveWorker(company.Table); //Getting rate card from Rate Type if (aInvoice.RateCardId != null) { company.RateCardId = aInvoice.RateCardId; } RateCard rateCard = bl.GetRateCardFromId(company.RateCardId); double rate = GetRateFrom(rateCard, activeWorkers); //Generating invoice unique name string front = "EMP"; string end = null; int nItems = this.adater.NumberOfGoogleStorageItems(this.bucketName); if (nItems.ToString("D").Length == 1) { end = "000" + nItems.ToString(); } else if (nItems.ToString("D").Length == 2) { end = "00" + nItems.ToString(); } else if (nItems.ToString("D").Length == 3) { end = "00" + nItems.ToString(); } else { end = nItems.ToString(); } string invName = front + end; //xxxx //Creating invoice model Invoice invoice = CreateInvoice(invName, company.Name, company.Email, activeWorkers, rate); //Saving invoice data to company company.InvoiceNo = invoice.InvoiceNo; company.RecentDate = invoice.InvoiceDate; company.RecentActiveWorkers = activeWorkers.ToString(); company.RecentTotal = invoice.Total; company.RecentRate = rate.ToString(); Company updateCom = bl.UpdateCompany(company); if (updateCom == null) { return(null); } //Create invoice a memory stream of pdf content MemoryStream memory = CreateInvoiceMemoryStream(invoice); if (memory == null) { return(null); } //Upload the content of file to cloud this.adater.UploadObject(this.bucketName, invName + ".pdf", "application/pdf", memory); //TODO -- Should me synchronize? //Send mail EmailHandler handler = new EmailHandler(); handler.SendMail(invoice.Company.Email, invName + ".pdf", this.adater); return(invoice); }