public async Task <ActionResult <Invoice> > GetInvoice(int id) { try { var invoice = await _invoice.GetInvoice(id); if (invoice == null) { ResponseViewModel Response1 = new ResponseViewModel(false, HttpStatusCode.NoContent, "NoContent", null); return(Ok(Response1)); } var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", invoice); return(Ok(Response)); } catch (Exception) { var Response = new ResponseViewModel(false, HttpStatusCode.BadRequest, "failed", null); return(Ok(Response)); } }
public async Task <IActionResult> GetInvoice(int id) { InvoiceViewModel result = await _invoice.GetInvoice(id); if (result != null) { var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result); return(Ok(Response)); } else { var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null); return(Ok(Response)); } }
///...............Report for Import for all products................ /// public async Task <List <double> > GetImportedReports(string period, DateTime from, DateTime to, string invoType) { try { if (period == "daily") { //Define list of invoices to store the result List <Double> result = new List <double>(); System.TimeSpan diff = to.Subtract(from); for (var day = from.Date; day <= to; day.AddDays(1)) { //to store the full imports Double value = 0; string dateday = day.ToString("yyyy-MM-dd"); //return list of id_invoices in each day List <int> importNumber = _db.Invoice.Where(p => p.Date.ToString() == dateday && p.Type == invoType).Select(p => p.Idinvoice).ToList(); for (int j = 0; j < importNumber.Count; j++) { InvoiceViewModel subresult = await _invoice.GetInvoice(importNumber[j]); value += Convert.ToDouble(subresult.FullCost); } result.Add(value); } return(result); } else if (period == "monthly") { //Define list of invoices to store the result List <Double> result = new List <double>(); System.TimeSpan diff = to.Subtract(from); for (var month = from.Month; month <= to.Month; month++) { //to store the full imports Double value = 0; //return list of id_invoices in each day List <int> importNumber = _db.Invoice.Where(p => p.Date.Value.Month == month && p.Type == invoType).Select(p => p.Idinvoice).ToList(); for (int j = 0; j < importNumber.Count; j++) { InvoiceViewModel subresult = await _invoice.GetInvoice(importNumber[j]); value += Convert.ToDouble(subresult.FullCost); } result.Add(value); } return(result); } else if (period == "annual") { //Define list of invoices to store the result List <Double> result = new List <double>(); System.TimeSpan diff = to.Subtract(from); for (var year = from.Year; year <= to.Year; year++) { //to store the full imports Double value = 0; //return list of id_invoices in each day List <int> importNumber = _db.Invoice.Where(x => x.Date.Value.Year == year && x.Type == invoType).Select(x => x.Idinvoice).ToList(); for (int j = 0; j < importNumber.Count; j++) { InvoiceViewModel subResult = await _invoice.GetInvoice(importNumber[j]); value += Convert.ToDouble(subResult.FullCost); } result.Add(value); } return(result); } return(null); } catch (Exception) { return(null); } }