예제 #1
0
 public ActionResult Create(Invoice InvoiceModel, HttpPostedFileBase upload)
 {
     try
     {
         Domain.Context.AssetManagementEntities AME = new Domain.Context.AssetManagementEntities();
         if (ModelState.IsValid)
         {
             if (upload != null && upload.ContentLength > 0)
             {
                 var invoice = new Invoice
                 {
                     FileName    = System.IO.Path.GetFileName(upload.FileName),
                     ContentType = upload.ContentType
                 };
                 using (var reader = new System.IO.BinaryReader(upload.InputStream))
                 {
                     invoice.Content = reader.ReadBytes(upload.ContentLength);
                 }
                 InvoiceModel.Content     = invoice.Content;
                 InvoiceModel.ContentType = invoice.ContentType;
                 InvoiceModel.FileName    = invoice.FileName;
             }
             AME.Invoices.Add(InvoiceModel);
             AME.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (RetryLimitExceededException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(InvoiceModel));
 }
예제 #2
0
        public ActionResult ViewInvoice(int id)
        {
            Domain.Context.AssetManagementEntities AME = new Domain.Context.AssetManagementEntities();
            var file = AME.Invoices.Find(id);

            return(File(file.Content, file.ContentType));
        }
예제 #3
0
        // GET: Invoice
        public ActionResult Index(int?page)
        {
            Domain.Context.AssetManagementEntities AME = new Domain.Context.AssetManagementEntities();
            int PageSize   = 6;
            int PageNumber = (page ?? 1);

            return(View(AME.Invoices.ToList().ToPagedList(PageNumber, PageSize)));
        }
예제 #4
0
 public ActionResult ViewByInvoiceNumber(string id)
 {
     Domain.Context.AssetManagementEntities AME = new Domain.Context.AssetManagementEntities();
     try
     {
         var file = AME.Invoices.Single(i => i.InvoiceNumber == id);
         return(File(file.Content, file.ContentType));
     }
     catch (InvalidOperationException e)
     {
         Session["ExeptionMessage"] = e.Message;
         Session["Message"]         = "Invoice not found. The admin will be see to the matter as soon as possible...";
         return(RedirectToAction("PageNotFound"));
     }catch (ArgumentException e)
     {
         Session["ExeptionMessage"] = e.Message;
         Session["Message"]         = "Invoice not found. The admin will be see to the matter as soon as possible...";
         return(RedirectToAction("PageNotFound"));
     }
 }