Ejemplo n.º 1
0
        public ActionResult UploadImportData()
        {
            var model = new ProductList();

            foreach (string f in Request.Files)
            {
                var fileContent = Request.Files[f];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    // get a stream
                    var      stream   = fileContent.InputStream;
                    var      fileName = String.Format("{1}_{0}", Path.GetFileName(fileContent.FileName), DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
                    FileInfo fileInfo;
                    FileManagement.SaveFile("Import/Product", fileName, stream, out fileInfo);
                    model.Data = ProductInfo.Read(UserID, Employee.ID, fileInfo, Employee.BussinessID);
                    Session[SessionKey.Import] = model;
                }
                break;
            }
            if (Request.IsAjaxRequest())
            {
                return(Json(new
                {
                    html = RenderPartialViewToString(Views.ImportPartial, model)
                }, JsonRequestBehavior.AllowGet));
            }
            return(View(Views.Import, model));
        }
Ejemplo n.º 2
0
        public ActionResult UploadFile(int id)
        {
            var list    = new List <ImexItem>();
            var result  = false;
            var message = "";

            foreach (string f in Request.Files)
            {
                var fileContent = Request.Files[f];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    // get a stream
                    var      stream   = fileContent.InputStream;
                    var      fileName = String.Format("{1}_{0}", Path.GetFileName(fileContent.FileName), DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
                    FileInfo fileInfo;
                    FileManagement.SaveFile("Import/Import", fileName, stream, out fileInfo);
                    list = ImexItem.Read(UserID, Employee.ID, fileInfo, Employee.BussinessID);
                    var unavailable = list.Count(i => i.ID <= 0 || i.WarehouseID <= 0);
                    if (unavailable > 0)
                    {
                        message = String.Format("{0} sản phẩm không tìm thấy", unavailable);
                    }
                    else
                    {
                        message = "Nhập sản phẩn từ file thành công";
                        result  = true;
                    }
                }
                break;
            }
            return(Json(new
            {
                result = result,
                list = ImexItem.ToJson(list.Where(i => i.ID > 0 && i.WarehouseID > 0)),
                message = message
            }, JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 3
0
        public ActionResult UploadFile(string folder)
        {
            var message  = "Upload failed";
            var result   = false;
            var fileName = "";
            var task     = Task.Run(() =>
            {
                try
                {
                    foreach (string file in Request.Files)
                    {
                        var fileContent = Request.Files[file];
                        if (fileContent != null && fileContent.ContentLength > 0)
                        {
                            // get a stream
                            var stream = fileContent.InputStream;
                            // and optionally write the file to disk
                            fileName = Path.GetFileName(fileContent.FileName);
                            result   = FileManagement.SaveFile(folder, fileName, stream);
                            if (result)
                            {
                                message = "File uploaded successfully";
                            }
                        }
                    }
                }
                catch (Exception e) { }
            });

            task.Wait();
            return(Json(new
            {
                file = fileName,
                img = String.Format("/{0}/{1}/{2}", FileManagement.MediaFolder, folder, fileName)
            }, JsonRequestBehavior.DenyGet));
        }