public ActionResult ProcessPurchaseorderInvoice(HttpPostedFileBase file, long invoiceId, long purchaseOrderId, string referenceCode, int statusCode, String dueDate, string dateSent, string attachment) { var gVal = new GenericValidator(); try { if (purchaseOrderId < 1) { gVal.Code = -1; gVal.Error = "Invoice information could not be processed."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var invoiceItem = new InvoiceJson { InvoiceId = invoiceId, PurchaseOrderId = purchaseOrderId, ReferenceCode = referenceCode, StatusCode = statusCode }; if (!string.IsNullOrEmpty(dueDate)) { DateTime d1; var res1 = DateTime.TryParse(dueDate, out d1); if (res1 && d1.Year > 1) { invoiceItem.DueDate = d1; } else { gVal.Code = -1; gVal.Error = "Request could not be processed. Please try again later."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } } if (!string.IsNullOrEmpty(dateSent)) { DateTime d2; var res2 = DateTime.TryParse(dateSent, out d2); if (res2 && d2.Year > 1) { invoiceItem.DateSent = d2; } else { gVal.Code = -1; gVal.Error = "Invalid invoice reception date."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } } var path = ""; if (file != null && file.ContentLength > 0) { path = PrepareAndSaveFile(file, attachment); if (string.IsNullOrEmpty(path) || path == "/") { gVal.Code = -1; gVal.Error = "Invoice information Could not be saved."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } } else { if (string.IsNullOrEmpty(attachment)) { gVal.Code = -1; gVal.Error = "Please select an invoice file to upload."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } path = attachment; } invoiceItem.Attachment = path; invoiceItem.StatusCode = (int)PurchaseOrderInvoiceStatus.Accepted; invoiceItem.Attachment = path; var tx = new PurchaseOrderServices().ProcessPurchaseOrderInvoice(invoiceItem); if (tx < 1) { gVal.Code = -1; gVal.Error = "Invoice information Could not be processed."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Error = "Invoice was successfully procesed"; gVal.FilePath = path.Replace("~", ""); gVal.Code = tx; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public long ProcessPurchaseOrderInvoice(InvoiceJson invoice) { return(_purchaseOrderRepository.ProcessPurchaseOrderInvoice(invoice)); }