Esempio n. 1
0
        public IList <DocumentDataModel> GetDataListForDocumentType(int masterId, NTAEnum.eDocumentType docType)
        {
            IList <DocumentDataModel> dataList = new List <DocumentDataModel>();

            switch (docType)
            {
            case NTAEnum.eDocumentType.EmployeeEducationalCertificate:
                dataList = _educationalQualificationRepository.Table.Where(x => x.EmployeeId == masterId).Select(x => new DocumentDataModel {
                    Id = x.Id, Name = x.Degree.Name
                }).ToList();
                break;
            }

            return(dataList);
        }
Esempio n. 2
0
        public IList <DocumentFileMetaDataModel> GetFileMetaData(int fileId, int masterId, int dataId, NTAEnum.eDocumentType docType, NTAEnum.eModule module)
        {
            var documentType = _docTypeRepository.GetById((int)docType);

            if (Common.GetClientModule.Any(x => x == module))
            {
                var doc = _customerDocumentRepository.Table;

                if (fileId > 0)
                {
                    doc = doc.Where(x => x.Id == fileId);
                }

                if (dataId > 0)
                {
                    doc = doc.Where(x => x.DataId == dataId && x.DocumentTypeId == (int)docType);
                }

                var model = new List <DocumentFileMetaDataModel>();
                if (doc.Any())
                {
                    model = doc.Select(x => new DocumentFileMetaDataModel
                    {
                        FileId   = x.Id,
                        MasterId = x.DataId,
                        DataId   = x.DataId,
                        FileName = x.FileName,
                        MimeType = x.FileMimeType,
                        Name     = documentType.DisplayName,
                        Remarks  = "",
                        Module   = (int)module
                    }).ToList();
                }

                return(model);
            }
            else
            {
                var doc = _hrDocumentRepository.Table;

                if (fileId > 0)
                {
                    doc = doc.Where(x => x.Id == fileId);
                }

                if (masterId > 0)
                {
                    doc = doc.Where(x => x.MasterId == masterId && x.DocumentTypeId == (int)docType);
                }

                if (dataId > 0)
                {
                    doc = doc.Where(x => x.DataId == dataId && x.DocumentTypeId == (int)docType);
                }

                var model = new List <DocumentFileMetaDataModel>();
                if (doc.Any())
                {
                    model = doc.Select(x => new DocumentFileMetaDataModel
                    {
                        FileId   = x.Id,
                        MasterId = x.MasterId,
                        DataId   = x.DataId,
                        FileName = x.FileName,
                        MimeType = x.FileMimeType,
                        Name     = documentType.DisplayName,
                        Remarks  = x.Remarks,
                        Module   = (int)module
                    }).ToList();
                }

                return(model);
            }
        }
Esempio n. 3
0
        public async Task <int> SaveFileAsync(int masterId, int dataId, NTAEnum.eDocumentType docType, HttpPostedFileBase fileData, string remarks, int currentUserId)
        {
            if (fileData != null)
            {
                MemoryStream stream = new MemoryStream();
                if (fileData != null)
                {
                    fileData.InputStream.CopyTo(stream);
                }

                var query = _hrDocumentRepository.TableUntracked.Where(x => x.DataId == dataId && x.DocumentTypeId == (int)docType);

                var documentType = _docTypeRepository.Table.FirstOrDefault(x => x.Id == (int)docType);
                //validate file extensions
                var validExtensions = documentType.Accept.Split(',');
                var fileInfo        = new System.IO.FileInfo(fileData.FileName);
                if (!validExtensions.Any(x => fileInfo.Extension.ToLower() == x.ToLower()))
                {
                    return(await Task.Run <int>(() => { return 0; }));
                }

                if (query.Any() && !query.FirstOrDefault().DocumentType.IsMultipleAllowed)
                {
                    _hrDocumentRepository.Delete(query.FirstOrDefault());
                }

                var document = new HRDocument
                {
                    DocumentTypeId = (int)docType,
                    MasterId       = masterId,
                    DataId         = dataId,
                    FileBinary     = stream.ToArray(),
                    FileName       = System.IO.Path.GetFileName(fileData.FileName),
                    FileMimeType   = fileData.ContentType,
                    FileSize       = fileData.ContentLength,
                    Remarks        = remarks,
                    CreatedBy      = currentUserId,
                    CreatedOn      = DateTime.Now,
                    LastModifiedBy = currentUserId,
                    LastModifiedOn = DateTime.Now
                };

                if (fileData.ContentType.Contains("image"))
                {
                    Bitmap bmp = new Bitmap(stream);

                    //create thumb
                    var          thumb1  = Common.CreateThumb(bmp, 60, 60);
                    MemoryStream stream1 = new MemoryStream();
                    thumb1.Save(stream1, ImageFormat.Jpeg);
                    document.ThumbSmall = stream1.ToArray();

                    var          thumb2  = Common.CreateThumb(bmp, 100, 100);
                    MemoryStream stream2 = new MemoryStream();
                    thumb2.Save(stream2, ImageFormat.Jpeg);
                    document.ThumbMiddle = stream2.ToArray();
                }

                _hrDocumentRepository.Insert(document);
                stream.Dispose();
                return(await Task.Run <int>(() => { return document.Id; }));
            }

            return(await Task.Run <int>(() => { return 0; }));
        }