Ejemplo n.º 1
0
        private static bool CanCompineFiles(HttpPostedFileBase[] UploadedFiles, out byte[] Result, out string contentType)
        {
            contentType = string.Empty;
            Result      = null;
            try
            {
                if (UploadedFiles == null)
                {
                    return(false);
                }


                if (UploadedFiles.Count() == 1 /*!Images[0].ContentType.Contains("doc")*/)
                {
                    Constants.Enumerations.UploadFileTypesEnum FileType = GetFileType(UploadedFiles[0]);
                    if (FileType == Constants.Enumerations.UploadFileTypesEnum.Pdf || FileType == Constants.Enumerations.UploadFileTypesEnum.Image)
                    {
                        contentType = UploadedFiles[0].ContentType.Replace("application/octet-stream", "image/jpeg");
                        Result      = ImageProcesses.ReadFully(UploadedFiles[0].InputStream);
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public List <Error> UploadOneFile(string Source, string SourceId)
        {
            List <Error> errors    = new List <Error>();
            var          imageData = _hrUnitOfWork.MissionRepository.GetBytes(int.Parse(SourceId));

            if (imageData != null)
            {
                return(errors);
            }
            var      file     = HttpContext.Request.Files[0];
            int      sid      = Convert.ToInt32(SourceId);
            var      stream   = ImageProcesses.ReadFully(file.InputStream);
            WebImage fullsize = null;
            WebImage thumbs   = null;

            fullsize = new WebImage(stream).Resize(1240, 1754);
            thumbs   = new WebImage(stream).Resize(124, 175);

            CompanyDocsViews doc = new CompanyDocsViews()
            {
                CompanyId   = CompanyId,
                name        = file.FileName,
                CreatedUser = UserName,
                Source      = Source,
                SourceId    = sid,
                file_stream = fullsize != null?fullsize.GetBytes() : stream,
                                  thumbs = thumbs != null?thumbs.GetBytes() : null
            };

            _hrUnitOfWork.CompanyRepository.Add(doc);
            errors = Save(Language);
            return(errors);
        }
        //public void UpdateEmp_EmpPapersStatus(int EmpID,List<Paper_UploadStatus> EmpDocsTypes)
        //{
        //    try
        //    {
        //        double Total = EmpDocsTypes.Count(a => a.IsRequired && a.IsEmpPaper);
        //        double Uploaded = EmpDocsTypes.Count(a => a.IsRequired && a.IsEmpPaper && a.IsUploaded);

        //        // double Percentage = (Uploaded / Total) * 100;
        //        string PaperStatus = string.Format("{0} / {1}", Uploaded, Total);
        //        //Update employee record
        //        var person = hrUnitOfWork.PeopleRepository.GetPerson(EmpID);
        //        if (person != null)
        //            person.PaperStatus = PaperStatus;

        //        hrUnitOfWork.Save();
        //    }
        //    catch
        //    {

        //    }
        //}



        public bool IsValid(ModelStateDictionary ModelState, EmploymentPapersUploadVModel Model, string Culture, out string ErrorMessage)
        {
            if (!Model.HasExpiryDate)
            {
                ModelState.Remove("ExpireDate_string");
            }

            bool Result = true;

            ErrorMessage = string.Empty;
            if (!ModelState.IsValid)
            {
                Result = CreateErrorMessage(MsgUtils.Instance.Trls(Culture, Constants.MessagesKeys.InvalidData), ref ErrorMessage);
            }

            if (Model.EmpID == 0)
            {
                Result = CreateErrorMessage(MsgUtils.Instance.Trls(Culture, "No employee found"), ref ErrorMessage);
            }

            if (!string.IsNullOrEmpty(Model.ExpireDate_string))
            {
                DateTime ExpireDate = Model.ExpireDate_string.ToMyDateTime(Culture);

                if (ExpireDate < DateTime.Now.Date)
                {
                    Result = CreateErrorMessage(MsgUtils.Instance.Trls(Culture, "Invalid Expire Date"), ref ErrorMessage);
                }
            }

            string KendoErrorMessage;

            if (!Constants.KendoGridValidation.IsValid(Model.BatchGridData_List, Culture, out KendoErrorMessage))
            {
                Result = CreateErrorMessage(KendoErrorMessage, ref ErrorMessage);
            }

            if (Model.Images == null && Model.Stream_Id == null)
            {
                Result = CreateErrorMessage(MsgUtils.Instance.Trls(Culture, "Please insert image"), ref ErrorMessage);
            }

            if (!ImageProcesses.IsValidExtension(Model.Images, Model.ValidFileExtensions))
            {
                Result = CreateErrorMessage(MsgUtils.Instance.Trls(Culture, "Invalid file extension"), ref ErrorMessage);
            }

            return(Result);
        }
Ejemplo n.º 4
0
        //private static void CovertWordToPDF(HttpPostedFileBase wordFile, string CurrentWordFullPath, string NewPdfFullPath)
        //{

        //    try
        //    {
        //        // Create a new Microsoft Word application object
        //        Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

        //        // C# doesn't have optional arguments so we'll need a dummy value
        //        object oMissing = System.Reflection.Missing.Value;

        //        word.Visible = false;
        //        word.ScreenUpdating = false;

        //        wordFile.SaveAs(CurrentWordFullPath);

        //        // Cast as Object for word Open method
        //        Object filename = (Object)CurrentWordFullPath;

        //        // Use the dummy value as a placeholder for optional arguments
        //        Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        //        doc.Activate();

        //        // NewPdfFullPath = CurrentWordFullPath.Replace(".docx", ".pdf").Replace(".doc", ".pdf");
        //        object outputFileName = (object)NewPdfFullPath;
        //        object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

        //        // Save document into PDF Format
        //        doc.SaveAs(ref outputFileName,
        //            ref fileFormat, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        //            ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        //        // Close the Word document, but leave the Word application open.
        //        // doc has to be cast to type _Document so that it will find the
        //        // correct Close method.
        //        object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
        //        ((Microsoft.Office.Interop.Word._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
        //        doc = null;

        //        // word has to be cast to type _Application so that it will find
        //        // the correct Quit method.
        //        ((Microsoft.Office.Interop.Word._Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
        //        word = null;
        //    }
        //    catch
        //    {

        //    }
        //}


        private static void ReadBytes_ContentType(string FullPath, out byte[] Result, out string contentType)
        {
            Result      = null;
            contentType = string.Empty;
            try
            {
                FileStream fStream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
                contentType = MimeMapping.GetMimeMapping(FullPath);
                Result      = ImageProcesses.ReadFully(fStream);
                fStream.Close();
            }
            catch
            {
            }
        }
Ejemplo n.º 5
0
        public JsonResult UploadOneFile(string Source, string SourceId)
        {
            var file = HttpContext.Request.Files[0];

            if (file == null)
            {
                return(Json("No files found"));
            }

            int sid = Convert.ToInt32(SourceId);

            WebImage fullsize = null;
            WebImage thumbs   = null;

            byte[] stream = null;
            ImageProcesses.GetFull_ThumpImages(Source, file.InputStream, file.ContentType, out fullsize, out thumbs, out stream);
            //var stream = ReadFully(file.InputStream);
            //WebImage fullsize = null;
            //WebImage thumbs= null;

            //if (Source == "EmployeePic")
            //{
            //    fullsize = new WebImage(stream).Resize(180, 180);
            //    thumbs = new WebImage(stream).Resize(32, 32);
            //}
            //else if (Source == "CompanyLogo")
            //{
            //    fullsize = new WebImage(stream).Resize(396,130);
            //    thumbs = new WebImage(stream).Resize(80, 80);
            //}
            //else if (file.ContentType != "application/pdf")
            //{
            //    fullsize = new WebImage(stream).Resize(1240, 1754); //   1240, 1754    2480, 3508
            //    thumbs = new WebImage(stream).Resize(124, 175);
            //}
            //else if (file.ContentType == "application/pdf")
            //{
            //    // do nothing
            //}
            //else
            //{
            //    fullsize = new WebImage(stream).Resize(1240, 1754);
            //    thumbs = new WebImage(stream).Resize(80, 80);
            //}

            CompanyDocsViews doc = new CompanyDocsViews()
            {
                CompanyId   = (Source == "CompanyLogo" ? sid : CompanyId),
                name        = file.FileName,
                CreatedUser = UserName,
                Source      = Source,
                SourceId    = sid,
                file_stream = fullsize != null?fullsize.GetBytes() : stream,
                                  thumbs = thumbs != null?thumbs.GetBytes() : null
            };

            _hrUnitOfWork.CompanyRepository.Add(doc);

            var    errors = SaveChanges(Language);
            string error  = errors.Count > 0 ? errors.First().errors.First().message : "OK";

            return(Json(error));
        }