コード例 #1
0
        public HttpResponseMessage Import(int id)
        {
            DTO_CUS_DOC_File tbl_CUS_DOC_File = BS_CUS_DOC_File.get_CUS_DOC_File(db, PartnerID, id, true);

            if (tbl_CUS_DOC_File == null || !(tbl_CUS_DOC_File.Extension == "docx" || tbl_CUS_DOC_File.Extension == "doc"))
            {
                return(null);
            }

            string path = System.Web.HttpContext.Current.Server.MapPath("~") + tbl_CUS_DOC_File.Path;
            string json = "";

            System.IO.FileInfo fileInfo = new FileInfo(path);

            if (fileInfo.Exists)
            {
                Stream stream = File.OpenRead(path);
                Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(stream, GetFormatType("." + tbl_CUS_DOC_File.Extension.ToLower()));
                json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
                // Releases unmanaged and optionally managed resources.
                document.Dispose();
                stream.Close();
            }


            return(new HttpResponseMessage()
            {
                Content = new StringContent(json, System.Text.Encoding.UTF8, "text/plain")
            });
        }
コード例 #2
0
        public IHttpActionResult Get(int id)
        {
            DTO_CUS_DOC_File tbl_CUS_DOC_File = BS_CUS_DOC_File.get_CUS_DOC_File(db, PartnerID, id, true);

            if (tbl_CUS_DOC_File == null)
            {
                return(NotFound());
            }

            return(Ok(tbl_CUS_DOC_File));
        }
コード例 #3
0
        public IHttpActionResult Post(DTO_CUS_DOC_File tbl_CUS_DOC_File)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DTO_CUS_DOC_File result = BS_CUS_DOC_File.post_CUS_DOC_File(db, PartnerID, tbl_CUS_DOC_File, Username, true);


            if (result != null)
            {
                return(CreatedAtRoute("get_CUS_DOC_File", new { id = result.ID }, result));
            }
            return(Conflict());
        }
コード例 #4
0
        public static bool put_CUS_DOC_File(AppEntities db, int PartnerID, int ID, DTO_CUS_DOC_File item, string Username)
        {
            bool result = false;
            var  dbitem = db.tbl_CUS_DOC_File.Find(ID);

            if (dbitem != null)
            {
                dbitem.Code         = item.Code;
                dbitem.Name         = item.Name;
                dbitem.Remark       = item.Remark;
                dbitem.Sort         = item.Sort;
                dbitem.IsDisabled   = item.IsDisabled;
                dbitem.IsDeleted    = item.IsDeleted;
                dbitem.Path         = item.Path;
                dbitem.Extension    = item.Extension;
                dbitem.IsApproved   = item.IsApproved;
                dbitem.ApprovedBy   = item.ApprovedBy;
                dbitem.ApprovedDate = item.ApprovedDate;
                dbitem.FileSize     = item.FileSize;
                dbitem.FileVersion  = item.FileVersion;
                dbitem.IDDeTai      = item.IDDeTai;
                dbitem.IsHidden     = item.IsHidden;

                dbitem.ModifiedBy   = Username;
                dbitem.ModifiedDate = DateTime.Now;

                try
                {
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_DOC_File", dbitem.ModifiedDate, Username);


                    result = true;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("put_CUS_DOC_File", e);
                    result = false;
                }
            }
            return(result);
        }
コード例 #5
0
        public void SaveSFDT(int id)
        {
            DTO_CUS_DOC_File item = BS_CUS_DOC_File.get_CUS_DOC_File(db, PartnerID, id, true);

            if (item == null)
            {
                return;
            }

            string path = System.Web.HttpContext.Current.Server.MapPath("~");

            item.ModifiedDate = DateTime.Now;
            string version = ".V" + item.ModifiedDate.ToString("yyMMdd-HHmmss");

            int    index  = item.Path.LastIndexOf(".V") == -1 ? item.Path.LastIndexOf(".") : item.Path.LastIndexOf(".V");
            string fileID = item.Path.Substring(0, index);

            string newFilePath = fileID + version + ".docx";
            string pdfFIlePath = fileID + version + ".pdf";

            System.Web.HttpPostedFile         file     = System.Web.HttpContext.Current.Request.Files[0];
            Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(file.InputStream);

            document.Save(path + newFilePath);
            document.Close();

            convertWordToPDF(path + newFilePath, path + pdfFIlePath);

            item.ModifiedBy = Username;


            item.Code      = pdfFIlePath;
            item.Path      = newFilePath;
            item.Extension = "docx";
            item.FileSize  = new System.IO.FileInfo(path + newFilePath).Length;

            Put(id, item);
        }
コード例 #6
0
        public IHttpActionResult Post_FileUpload(int id)
        {
            var httpRequest = System.Web.HttpContext.Current.Request;

            if (httpRequest.Files.Count < 1)
            {
                return(BadRequest(ModelState));
            }

            DTO_CUS_DOC_File result = null;
            DTO_CUS_DOC_File item   = new DTO_CUS_DOC_File();

            foreach (string file in httpRequest.Files)
            {
                #region upload file
                var postedFile = httpRequest.Files[file];



                string uploadPath = "/Uploads/DOCs/" + DateTime.Today.ToString("yyyy/MM/dd").Replace("-", "/");


                string oldName = System.IO.Path.GetFileName(postedFile.FileName);
                string ext     = oldName.Substring(oldName.LastIndexOf('.') + 1).ToLower();

                var    g        = Guid.NewGuid();
                string fileid   = g.ToString();
                string fileName = "" + fileid + "." + oldName;
                string viewName = "" + fileid + ".pdf";

                string mapPath          = System.Web.HttpContext.Current.Server.MapPath("~/");
                string strDirectoryPath = mapPath + uploadPath;
                string strFilePath      = strDirectoryPath + "/" + fileName;
                string viewFilePath     = strDirectoryPath + "/" + viewName;

                System.IO.FileInfo existingFile = new System.IO.FileInfo(strFilePath);

                if (!System.IO.Directory.Exists(strDirectoryPath))
                {
                    System.IO.Directory.CreateDirectory(strDirectoryPath);
                }
                if (existingFile.Exists)
                {
                    existingFile.Delete();
                    existingFile = new System.IO.FileInfo(strFilePath);
                }

                postedFile.SaveAs(strFilePath);

                switch (ext)
                {
                case "doc":
                case "docx":
                    convertWordToPDF(strFilePath, viewFilePath);
                    break;

                case "xls":
                case "xlsx":
                    convertExcelToPDF(strFilePath, viewFilePath);
                    break;

                case "ppt":
                case "pptx":
                    convertPowerpointToPDF(strFilePath, viewFilePath);
                    break;

                default:
                    viewName = fileName;
                    break;
                }

                #endregion


                if (id == 0)
                {
                    item.Name      = "";
                    item.IDPartner = 1;
                    item.Code      = uploadPath + "/" + viewName;
                    item.IsDeleted = true;
                    item.Path      = uploadPath + "/" + fileName;
                    item.Extension = System.IO.Path.GetExtension(strFilePath).Replace(".", "");
                    item.FileSize  = new System.IO.FileInfo(strFilePath).Length;

                    result = BS_CUS_DOC_File.post_CUS_DOC_File(db, PartnerID, item, Username, true);
                }
                else
                {
                    item.ID        = id;
                    item.IDPartner = 1;
                    item.Code      = uploadPath + "/" + viewName;
                    item.Path      = uploadPath + "/" + fileName;
                    item.Extension = System.IO.Path.GetExtension(strFilePath).Replace(".", "");
                    item.FileSize  = new System.IO.FileInfo(strFilePath).Length;

                    result = item;


                    //var doc = db.tbl_CUS_DOC_File.Find(id);
                    //if (doc!=null)
                    //{
                    //    doc.Code = item.Code = uploadPath + "/" + viewName;
                    //    doc.Path = item.Path = uploadPath + fileName;
                    //    doc.Extension = item.Extension = System.IO.Path.GetExtension(strFilePath).Replace(".", "");
                    //    doc.FileSize = item.FileSize = new System.IO.FileInfo(strFilePath).Length;
                    //    item.ID = id;
                    //    result = item;
                    //    db.SaveChanges();
                    //}
                    //else
                    //{
                    //    return NotFound();
                    //}
                }
            }


            if (result != null)
            {
                return(CreatedAtRoute("get_CUS_DOC_File", new { id = result.ID }, result));
            }
            return(Conflict());
        }
コード例 #7
0
        public IHttpActionResult Put(int id, DTO_CUS_DOC_File tbl_CUS_DOC_File)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_CUS_DOC_File.ID)
            {
                return(BadRequest());
            }

            //Get list staff with email can approve document
            var staffs = db.tbl_CUS_HRM_STAFF_NhanSu.Where(d => d.tbl_CUS_SYS_Role.tbl_CUS_SYS_PermissionList.Any(c => c.tbl_SYS_Form.Code == "page-approve" && c.Visible) && d.IsDeleted == false && d.Email != "" && d.IDPartner == PartnerID);

            string sendMailType = "";

            //Không có quyền duyệt mà sửa file, gửi duyệt => chờ duyệt
            if (!staffs.Any(d => d.Email == Username) && tbl_CUS_DOC_File.ApprovedBy == "Chờ duyệt")
            {
                tbl_CUS_DOC_File.IsApproved   = false;
                tbl_CUS_DOC_File.ModifiedBy   = Username;
                tbl_CUS_DOC_File.ModifiedDate = DateTime.Now;
                tbl_CUS_DOC_File.ApprovedBy   = "Chờ duyệt";
                sendMailType = "ApproveRequired";
            }
            //Không có quyền duyệt mà sửa file, KHÔNG gửi duyệt
            else if (!staffs.Any(d => d.Email == Username))
            {
                tbl_CUS_DOC_File.IsApproved   = false;
                tbl_CUS_DOC_File.ModifiedBy   = Username;
                tbl_CUS_DOC_File.ModifiedDate = DateTime.Now;
            }
            //có quyền duyệt, thực hiện duyệt file bằng cách gán IsApproved = true
            else if (tbl_CUS_DOC_File.IsApproved)
            {
                tbl_CUS_DOC_File.ModifiedBy   = Username;
                tbl_CUS_DOC_File.ModifiedDate = DateTime.Now;
                tbl_CUS_DOC_File.ApprovedBy   = Username;
                tbl_CUS_DOC_File.ApprovedDate = DateTime.Now;
                sendMailType = "Approved";
            }
            //có quyền duyệt trả file bằng cách gán ApprovedBy = "Không được duyệt"
            else if (tbl_CUS_DOC_File.ApprovedBy == "Không được duyệt")
            {
                tbl_CUS_DOC_File.IsApproved   = false;
                tbl_CUS_DOC_File.ApprovedDate = DateTime.Now;
                sendMailType = "Denied";
            }
            //có quyền duyệt, chỉ update thông thuường
            else
            {
                //Đánh dấu không gửi mail
                tbl_CUS_DOC_File.ModifiedBy   = Username;
                tbl_CUS_DOC_File.ModifiedDate = DateTime.Now;
            }

            bool resul = BS_CUS_DOC_File.put_CUS_DOC_File(db, PartnerID, id, tbl_CUS_DOC_File, Username, true);

            if (resul)
            {
                if (!string.IsNullOrEmpty(sendMailType))
                {
                    string template = "";
                    string subject  = "";


                    if (sendMailType == "ApproveRequired")
                    {
                        subject  = "Quản lý Đề tài Nghiên cứu khoa học - tài liệu chờ duyệt";
                        template =
                            @"
                        Xin chào <strong>@Model.ToName</strong>,
                        <br>
                        <br>Tài khoản @Model.ModifiedBy vừa cập nhật tài liệu trên hệ thống thư viện điện tử.
                        <br>Thông tin văn bản chờ duyệt:
                        <br>
                        <br><strong>Tiêu đề:</strong>
                        <br>@Model.Name
                        <br><strong>Mô tả ngắn:</strong>
                        <br>@Model.Remark
                        <br>
                        <br>Vui lòng xem các văn bản đang chờ duyệt tại
                        <br><a href='@Model.Domain'>@Model.Domain</a>
                        <br>";

                        foreach (var s in staffs)
                        {
                            var html = Engine.Razor.RunCompile(template, "File_ApproveRequired", null, new
                            {
                                ToName     = s.Name,
                                ModifiedBy = Username,
                                Name       = tbl_CUS_DOC_File.Name,
                                Remark     = tbl_CUS_DOC_File.Remark,
                                Domain     = "http://myduc.appcenter.vn:9003/#/approve"
                            });

                            EmailService emailService = new EmailService();
                            //emailService.Send(new IdentityMessage() { Subject = subject, Destination = s.Email, Body = html });
                        }
                    }
                    else if (sendMailType == "Approved")
                    {
                        subject  = "Quản lý Đề tài Nghiên cứu khoa học - đã duyệt tài liệu (" + tbl_CUS_DOC_File.Name + ")";
                        template =
                            @"
                        Xin chào <strong>@Model.ToName</strong>,
                        <br>
                        <br>Tài liệu <span style='color: green'>ĐÃ ĐƯỢC DUYỆT</span> trên hệ thống thư viện điện tử.
                        <br>Thông tin tài liệu:
                        <br>
                        <br><strong>Tiêu đề:</strong>
                        <br>@Model.Name
                        <br><strong>Mô tả ngắn:</strong>
                        <br>@Model.Remark
                        <br>
                        <br>Vui lòng xem các văn bản tại
                        <br><a href='@Model.Domain'>@Model.Domain</a>
                        <br>";

                        var s = db.tbl_CUS_HRM_STAFF_NhanSu.FirstOrDefault(d => d.Email == tbl_CUS_DOC_File.ModifiedBy);
                        if (s != null)
                        {
                            var html = Engine.Razor.RunCompile(template, "File_Approved", null, new
                            {
                                ToName = s.Name,

                                Name   = tbl_CUS_DOC_File.Name,
                                Remark = tbl_CUS_DOC_File.Remark,
                                Domain = "http://myduc.appcenter.vn:9003/#/sops"
                            });

                            EmailService emailService = new EmailService();
                            //emailService.Send(new IdentityMessage() { Subject = subject, Destination = s.Email, Body = html });
                        }
                    }
                    else if (sendMailType == "Denied")
                    {
                        subject  = "Quản lý Đề tài Nghiên cứu khoa học - TỪ CHỐI duyệt tài liệu (" + tbl_CUS_DOC_File.Name + ")";
                        template =
                            @"
                        Xin chào <strong>@Model.ToName</strong>,
                        <br>
                        <br>Tài liệu đã <span style='color: red'>BỊ TỪ CHỐI DUYỆT</span> trên hệ thống thư viện điện tử.
                        <br>Thông tin văn bản chờ duyệt:
                        <br>
                        <br><strong>Tiêu đề:</strong>
                        <br>@Model.Name
                        <br><strong>Mô tả ngắn:</strong>
                        <br>@Model.Remark
                        <br>
                        <br>Vui lòng xem lại các văn bản tại
                        <br><a href='@Model.Domain'>@Model.Domain</a>
                        <br>";

                        var s = db.tbl_CUS_HRM_STAFF_NhanSu.FirstOrDefault(d => d.Email == tbl_CUS_DOC_File.ModifiedBy);
                        if (s != null)
                        {
                            var html = Engine.Razor.RunCompile(template, "File_Denied", null, new
                            {
                                ToName = s.Name,

                                Name   = tbl_CUS_DOC_File.Name,
                                Remark = tbl_CUS_DOC_File.Remark,
                                Domain = "http://myduc.appcenter.vn:9003/#/sops"
                            });

                            EmailService emailService = new EmailService();
                            //emailService.Send(new IdentityMessage() { Subject = subject, Destination = s.Email, Body = html });
                        }
                    }
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #8
0
        public static DTO_CUS_DOC_File post_CUS_DOC_File(AppEntities db, int PartnerID, DTO_CUS_DOC_File item, string Username)
        {
            tbl_CUS_DOC_File dbitem = new tbl_CUS_DOC_File();

            if (item != null)
            {
                dbitem.Code         = item.Code;
                dbitem.Name         = item.Name;
                dbitem.Remark       = item.Remark;
                dbitem.Sort         = item.Sort;
                dbitem.IsDisabled   = item.IsDisabled;
                dbitem.IsDeleted    = item.IsDeleted;
                dbitem.Path         = item.Path;
                dbitem.Extension    = item.Extension;
                dbitem.IsApproved   = item.IsApproved;
                dbitem.ApprovedBy   = item.ApprovedBy;
                dbitem.ApprovedDate = item.ApprovedDate;
                dbitem.FileSize     = item.FileSize;
                dbitem.FileVersion  = item.FileVersion;
                dbitem.IDDeTai      = item.IDDeTai;
                dbitem.IsHidden     = item.IsHidden;

                dbitem.CreatedBy   = Username;
                dbitem.CreatedDate = DateTime.Now;

                dbitem.ModifiedBy   = Username;
                dbitem.ModifiedDate = DateTime.Now;

                dbitem.IDPartner = PartnerID;


                try
                {
                    db.tbl_CUS_DOC_File.Add(dbitem);
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_DOC_File", dbitem.ModifiedDate, Username);



                    item.ID = dbitem.ID;

                    item.CreatedBy   = dbitem.CreatedBy;
                    item.CreatedDate = dbitem.CreatedDate;

                    item.ModifiedBy   = dbitem.ModifiedBy;
                    item.ModifiedDate = dbitem.ModifiedDate;

                    item.IDPartner = dbitem.IDPartner;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("post_CUS_DOC_File", e);
                    item = null;
                }
            }
            return(item);
        }
コード例 #9
0
        public static bool put_CUS_DOC_File(AppEntities db, int PartnerID, int ID, DTO_CUS_DOC_File item, string Username, bool custom)
        {
            bool   result  = false;
            var    dbitem  = db.tbl_CUS_DOC_File.Find(ID);
            string changes = "";
            string oldName = "";

            if (dbitem != null)
            {
                string format = "\"{0}\": {{\"old\":\"{1}\", \"new\":\"{2}\"}},";
                if (dbitem.Code != item.Code)
                {
                    changes += string.Format(format, "Code", dbitem.Code, item.Code);
                }
                dbitem.Code = item.Code;

                if (dbitem.Name != item.Name)
                {
                    changes += string.Format(format, "Name", dbitem.Name, item.Name);
                }

                oldName     = dbitem.Name;
                dbitem.Name = item.Name;

                if (dbitem.Remark != item.Remark)
                {
                    changes += string.Format(format, "Remark", dbitem.Remark, item.Remark);
                }
                dbitem.Remark = item.Remark;

                if (dbitem.FileVersion != item.FileVersion)
                {
                    changes += string.Format(format, "FileVersion", dbitem.FileVersion, item.FileVersion);
                }
                dbitem.FileVersion = item.FileVersion;

                dbitem.Sort         = item.Sort;
                dbitem.IsDisabled   = item.IsDisabled;
                dbitem.IsDeleted    = item.IsDeleted;
                dbitem.ModifiedBy   = item.ModifiedBy;
                dbitem.ModifiedDate = item.ModifiedDate;

                if (dbitem.Path != item.Path)
                {
                    changes += string.Format(format, "Path", dbitem.Path, item.Path);
                }
                dbitem.Path = item.Path;

                if (dbitem.Extension != item.Extension)
                {
                    changes += string.Format(format, "Extension", dbitem.Extension, item.Extension);
                }
                dbitem.Extension = item.Extension;

                if (dbitem.FileSize != item.FileSize)
                {
                    changes += string.Format(format, "FileSize", dbitem.FileSize, item.FileSize);
                }
                dbitem.FileSize = item.FileSize;

                if (dbitem.IsApproved != item.IsApproved)
                {
                    changes += string.Format(format, "IsApproved", dbitem.IsApproved, item.IsApproved);
                }
                dbitem.IsApproved = item.IsApproved;

                if (dbitem.ApprovedBy != item.ApprovedBy)
                {
                    changes += string.Format(format, "ApprovedBy", dbitem.ApprovedBy, item.ApprovedBy);
                }
                dbitem.ApprovedBy = item.ApprovedBy;

                dbitem.ApprovedDate = item.ApprovedDate;



                try
                {
                    var folder = dbitem.tbl_CUS_DOC_FileInFolder.FirstOrDefault();

                    if (folder == null && item.IDFolder != null)
                    {
                        dbitem.tbl_CUS_DOC_FileInFolder.Add(new tbl_CUS_DOC_FileInFolder()
                        {
                            IDFolder = item.IDFolder, IDPartner = item.IDPartner, CreatedBy = dbitem.CreatedBy, CreatedDate = dbitem.CreatedDate, ModifiedBy = dbitem.ModifiedBy, ModifiedDate = dbitem.ModifiedDate
                        });
                    }
                    else if (folder != null && folder.IDFolder != item.IDFolder && item.IDFolder != null)
                    {
                        folder.IDFolder = item.IDFolder;
                    }
                    else if (folder != null && item.IDFolder == null)
                    {
                        db.tbl_CUS_DOC_FileInFolder.Remove(folder);
                    }

                    //check change to save activities

                    tbl_CUS_DOC_File_Actitity activity = new tbl_CUS_DOC_File_Actitity();
                    if (!db.tbl_CUS_DOC_File_Actitity.Any(d => d.IDPartner == PartnerID && d.IDFile == dbitem.ID))
                    {
                        activity.Code = "Add";
                        activity.Name = dbitem.Name;
                        changes       = string.Format(format, "Name", "", "Thêm tài liệu mới");
                    }
                    else if (changes != "")
                    {
                        activity.Code = "Update";
                        activity.Name = oldName;
                    }
                    if (!string.IsNullOrEmpty(changes))
                    {
                        activity.Remark = "{" + changes.Substring(0, changes.Length - 1) + "}";
                    }

                    activity.IDFile       = dbitem.ID;
                    activity.IDPartner    = dbitem.IDPartner;
                    activity.CreatedBy    = Username;
                    activity.CreatedDate  = DateTime.Now;
                    activity.ModifiedBy   = dbitem.ModifiedBy;
                    activity.ModifiedDate = dbitem.ModifiedDate;

                    if (!string.IsNullOrEmpty(activity.Code))
                    {
                        db.tbl_CUS_DOC_File_Actitity.Add(activity);
                    }


                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_DOC_File", dbitem.ModifiedDate, Username);



                    result = true;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("put_CUS_DOC_File", e);
                    result = false;
                }
            }
            return(result);
        }
コード例 #10
0
        public IHttpActionResult Post_FileUpload(int id)
        {
            var httpRequest = System.Web.HttpContext.Current.Request;

            if (httpRequest.Files.Count < 1)
            {
                return(BadRequest(ModelState));
            }

            DTO_CUS_DOC_File result = null;
            DTO_CUS_DOC_File item   = new DTO_CUS_DOC_File();

            foreach (string file in httpRequest.Files)
            {
                var postedFile = httpRequest.Files[file];

                string uploadPath = "/Uploads/NCKH/" + DateTime.Today.ToString("yyyy/MM/dd").Replace("-", "/");


                string oldName = System.IO.Path.GetFileName(postedFile.FileName);
                string ext     = oldName.Substring(oldName.LastIndexOf('.') + 1).ToLower();

                var    g        = Guid.NewGuid();
                string fileid   = g.ToString();
                string fileName = "" + fileid + "." + oldName;

                string mapPath          = System.Web.HttpContext.Current.Server.MapPath("~/");
                string strDirectoryPath = mapPath + uploadPath;
                string strFilePath      = strDirectoryPath + "/" + fileName;

                System.IO.FileInfo existingFile = new System.IO.FileInfo(strFilePath);

                if (!System.IO.Directory.Exists(strDirectoryPath))
                {
                    System.IO.Directory.CreateDirectory(strDirectoryPath);
                }
                if (existingFile.Exists)
                {
                    existingFile.Delete();
                    existingFile = new System.IO.FileInfo(strFilePath);
                }

                postedFile.SaveAs(strFilePath);


                if (id == 0)
                {
                    item.Name      = oldName;
                    item.Code      = uploadPath + "/" + fileName;
                    item.Path      = uploadPath + "/" + fileName;
                    item.Extension = System.IO.Path.GetExtension(strFilePath).Replace(".", "");
                    item.FileSize  = new System.IO.FileInfo(strFilePath).Length;
                    item.IsHidden  = true;
                    result         = BS_CUS_DOC_File.post_CUS_DOC_File(db, PartnerID, item, Username, true);
                }
                else
                {
                    item.ID        = id;
                    item.Name      = oldName;
                    item.Code      = uploadPath + "/" + fileName;
                    item.Path      = uploadPath + "/" + fileName;
                    item.Extension = System.IO.Path.GetExtension(strFilePath).Replace(".", "");
                    item.FileSize  = new System.IO.FileInfo(strFilePath).Length;
                    item.IsHidden  = true;
                    result         = item;
                }
            }


            if (result != null)
            {
                return(CreatedAtRoute("get_CUS_DOC_File", new { id = result.ID }, result));
            }
            return(Conflict());
        }