示例#1
0
        public IActionResult Dowload(int id)
        {
            var    blDocument = new BLDocument();
            var    document   = blDocument.GetByID(id);
            var    filePath   = Path.Combine(_hostingEnvironment.WebRootPath, "upload", $"{document.physical_name}.{document.extension}");
            string contentType;

            new FileExtensionContentTypeProvider().TryGetContentType(document.name, out contentType);
            return(PhysicalFile(filePath, contentType, document.name));
        }
        public JsonResult UploadFile(BLDocument modal)
        {
            string _imgname      = string.Empty;
            long   returnimageid = 0;
            string imagePath     = string.Empty;

            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var pic = System.Web.HttpContext.Current.Request.Files["uploadDocument"];
                if (pic.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(pic.FileName);
                    var _ext     = Path.GetExtension(pic.FileName);

                    _imgname = Guid.NewGuid().ToString();
                    _imgname = "docuemnt" + _imgname + _ext;
                    var getfolder = string.Empty;
                    if (string.IsNullOrEmpty(modal.FolderName))
                    {
                        getfolder = "/" + ConfigurationManager.AppSettings["ContentFolder"] + "/Documents/";
                    }
                    else
                    {
                        getfolder = "/" + ConfigurationManager.AppSettings["ContentFolder"] + "/Documents/" + modal.FolderName + "/";
                        if (!Directory.Exists(Server.MapPath(getfolder)))
                        {
                            Directory.CreateDirectory(Server.MapPath(getfolder));
                        }
                    }
                    var _comPath = Server.MapPath(getfolder) + _imgname;
                    var path     = _comPath;
                    // Saving document in Original Mode
                    pic.SaveAs(path);

                    var userId = User.Identity.GetUserId();
                    // Save Document
                    var bLDocument = new BLDocument()
                    {
                        OriginalName = fileName,
                        CretedBy     = userId,
                        DocPath      = getfolder + _imgname,
                        FileName     = _imgname,
                        FolderName   = modal.FolderName == null ? "Documents" : modal.FolderName,
                        LinkId       = modal.LinkId,
                        LinkTable    = modal.LinkTable,
                    };
                    imagePath     = getfolder + _imgname;
                    returnimageid = bLDocument.Save();
                }
            }
            return(Json(new { id = returnimageid, path = imagePath }, JsonRequestBehavior.AllowGet));
        }
        public DocumentModel GetUserDocumentView(int DocumentId, int UserId)
        {
            DocumentModel objDocumentModel = new DocumentModel();
            BLDocument    objBLDocument    = new BLDocument();

            objDocumentModel = objBLDocument.GetDocumentById(DocumentId);
            objDocumentModel.DocumentHTML = objBLDocumentResponse.GetDocumentPreviewTemp(DocumentId, UserId);

            objDocumentModel.objListActivityModel = new List <ActivityModel>();
            objDocumentModel.objListActivityModel = objBLDocumentResponse.GetUserDocumentHistory(DocumentId, UserId);

            return(objDocumentModel);
        }
        public DocumentResponseDetailModel GetDocumentResponseForSave(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            BLDocument objBLDocument = new BLDocument();
            BLStep     objBLStep     = new BLStep();

            //1. Fill Document detail
            objDocumentResponseDetailModel.objDocumentModel = new DocumentModel();
            objDocumentResponseDetailModel.objDocumentModel = objBLDocument.GetDocumentById(objDocumentResponseDetailModel.DocumentID);
            objDocumentResponseDetailModel.objDocumentModel.DocumentHTML = objBLDocumentResponse.GetDocumentPreviewTemp(objDocumentResponseDetailModel.DocumentID, objDocumentResponseDetailModel.UserId);
            //2. Fill Step detail
            objDocumentResponseDetailModel.objStepList = new List <StepModel>();
            objDocumentResponseDetailModel.objStepList = objBLStep.GetStepByDocumentIdAndUserId(objDocumentResponseDetailModel.DocumentID, objDocumentResponseDetailModel.UserId);


            return(objBLDocumentResponse.GetDocumentResponseForSave(objDocumentResponseDetailModel));
        }
示例#5
0
        public HomeLayOutModel GetLayOutData()
        {
            HomeLayOutModel objHomeLayOutModel = new HomeLayOutModel();

            BLCategory    objBLCategory    = new BLCategory();
            BLDocument    objBLDocument    = new BLDocument();
            BLSubCategory objBLSubCategory = new BLSubCategory();

            ViewCategoryModel objViewCategoryModel = new ViewCategoryModel();

            objViewCategoryModel.CurrentPage        = 1;
            objViewCategoryModel.PageSize           = int.MaxValue - 1;
            objHomeLayOutModel.objViewCategoryModel = new ViewCategoryModel();
            objHomeLayOutModel.objViewCategoryModel = objBLCategory.GetCategoryList(objViewCategoryModel);

            if (objHomeLayOutModel != null && objHomeLayOutModel.objViewCategoryModel != null && objHomeLayOutModel.objViewCategoryModel.CategoryList != null && objHomeLayOutModel.objViewCategoryModel.CategoryList.Count > 0)
            {
                for (int i = 0; i < objHomeLayOutModel.objViewCategoryModel.CategoryList.Count; i++)
                {
                    //string[] DocumentIds = objHomeLayOutModel.objViewCategoryModel.CategoryList[i].QuickLinks.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    //if (DocumentIds != null && DocumentIds.Length > 0)
                    //{
                    //    objHomeLayOutModel.objViewCategoryModel.CategoryList[i].objDocumentList = new List<DocumentModel>();
                    //    for (int j = 0; j < DocumentIds.Length; j++)
                    //    {
                    //        objHomeLayOutModel.objViewCategoryModel.CategoryList[i].objDocumentList.Add(objBLDocument.GetDocumentById(Convert.ToInt32(DocumentIds[j])));
                    //    }
                    //}
                }
            }
            ViewSubCategoryModel objViewSubCategoryModel = new ViewSubCategoryModel();

            objViewSubCategoryModel.CurrentPage = 1;
            objViewSubCategoryModel.PageSize    = int.MaxValue - 1;

            objHomeLayOutModel.objSubViewCategoryModel = new ViewSubCategoryModel();
            objHomeLayOutModel.objSubViewCategoryModel = objBLSubCategory.GetSubCategoryList(objViewSubCategoryModel);

            return(objHomeLayOutModel);
        }
示例#6
0
        public IActionResult UploadFile()
        {
            ServiceResult result   = new ServiceResult();
            var           files    = Request.Form.Files;
            var           parentID = Int32.Parse(Request.Form["parentID"]);
            var           count    = files.Count;

            foreach (var file in files)
            {
                var      fileExtension = file.FileName.Split(".").Last();
                var      fileName      = file.FileName.Substring(0, file.FileName.Length - fileExtension.Length - 1);
                var      physicalName  = Guid.NewGuid();
                var      filePath      = Path.Combine(_hostingEnvironment.WebRootPath, "upload", $"{physicalName}.{fileExtension}");
                Document document      = new Document()
                {
                    name          = file.FileName,
                    parent_id     = parentID,
                    physical_name = physicalName.ToString(),
                    extension     = fileExtension,
                    type          = 1
                };

                try
                {
                    using (var stream = System.IO.File.Create(filePath))
                    {
                        file.CopyTo(stream);
                        var blDocument = new BLDocument();
                        blDocument.Insert(document);
                    }
                }
                catch (Exception)
                {
                    count--;
                }
            }
            // Trả về số file upload thành công
            return(Ok(count));
        }
示例#7
0
 public DocumentController()
 {
     bl = new BLDocument();
 }