Ejemplo n.º 1
0
        public ActionResult Quotation(HttpPostedFileBase file1)
        {
            try
            {
                if (file1 == null)
                {
                    throw new Exception("No file was uploaded");
                }

                //convert excel to list
                List <StationerySupplier> list = StationerySupplierQuote.ConvertToList(file1.InputStream);

                //validate data
                StationerySupplierQuote.ValidateData(list);

                //upload data
                _stationerySupplierRepo.UpdateAll(list);


                ViewBag.Success = "Successfully uploaded";
                return(View());
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View());
            }
        }
Ejemplo n.º 2
0
        //GET: Suppliers/QuotationTemplate (will download Excel file directly)
        public ActionResult QuotationTemplate()
        {
            //get data to put into excel
            List <StationerySupplierQuote> slist =
                _stationerySupplierRepo.GetAll().Select(x => new StationerySupplierQuote
            {
                ItemCode     = x.ItemNum,
                ItemName     = x.Stationery.Description,
                SupplierCode = x.SupplierId,
                SupplierName = x.Supplier.SupplierName,
                Rank         = x.Rank,
                UnitPrice    = x.Price
            }).ToList();

            byte[] filecontent = StationerySupplierQuote.ConvertListToByte(slist);
            return(File(filecontent, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        "quotations.xlsx"));
        }