示例#1
0
        public void UploadPhoto(int organisationId, int personnelId, byte[] photo)
        {
            var personnel    = _nidanDataService.RetrievePersonnel(organisationId, personnelId, x => true);
            var organisation = RetrieveOrganisation(organisationId);
            var document     = RetrieveDocument(organisationId, personnelId);

            if (document != null)
            {
                //DeletePhoto(document.DocumentGuid);
            }

            _documentServiceAPI.CreateDocument(
                new Document
            {
                Product     = organisation.Name,
                Category    = PersonnelProfileCategory,
                Content     = photo,
                Description = "Profile Picture",
                //FileName = personnel.Fullname + ".jpg",
                PayrollId = personnelId.ToString(),
                //EmployeeName = personnel.Fullname,
                CreatedBy         = personnelId.ToString(),
                DocumentAttribute = new List <DocumentAttribute>
                {
                    new DocumentAttribute
                    {
                        Key   = PersonnelPhotoKey,
                        Value = personnelId.ToString()
                    }
                }
            });
        }
        public ValidationResult <EmployeeDocument> CreateEmployeeDocument(DocumentMeta documentMeta, int employeeId, string userId)
        {
            var validationResult = new ValidationResult <EmployeeDocument>();

            try
            {
                //upload document to document service
                var documentCategoryId = documentMeta.DocumentTypeId;
                var documentCategory   = _payrollBureauDataService.Retrieve <DocumentCategory>(e => e.DocumentCategoryId == documentMeta.DocumentTypeId);
                if (documentCategory == null)
                {
                    validationResult.Errors = new List <string> {
                        "Document category not found"
                    };
                    return(validationResult);
                }

                var apiDocument = new Document
                {
                    Product        = ProductName,
                    Category       = documentCategory.FirstOrDefault()?.Name,
                    PayrollId      = employeeId.ToString(),
                    CreatedBy      = userId,
                    CreatedDateUTC = DateTime.UtcNow
                };

                var document = _documentServiceRestClient.CreateDocument(apiDocument);

                if (document == null)
                {
                    validationResult.Errors = new List <string>()
                    {
                        "Document could not be saved, please try again"
                    };
                    return(validationResult);
                }

                var employeeDocument = new EmployeeDocument()
                {
                    DocumentCategoryId = documentCategoryId,
                    DocumentGuid       = document.DocumentGuid,
                    EmployeeId         = employeeId,
                    Filename           = documentMeta.FileName,
                    CreatedBy          = userId,
                    Description        = documentMeta.Description,
                    CreatedDateUtc     = DateTime.UtcNow
                };
                _payrollBureauDataService.Create <EmployeeDocument>(employeeDocument);
                validationResult.Succeeded = true;
                return(validationResult);
            }
            catch (Exception ex)
            {
                validationResult.Succeeded = false;
                validationResult.Exception = ex;
            }
            return(validationResult);
        }