Beispiel #1
0
        private BiometricModel GetBioDataFromFolder(string enrollmentId, string mainPath)
        {
            try
            {
                var folderPath = mainPath + "/" + enrollmentId;

                var enrollePath = Server.MapPath(folderPath);

                var ext = new List <string> {
                    ".jpg"
                };

                if (!Directory.Exists(enrollePath))
                {
                    return(new BiometricModel());
                }

                var myFiles = Directory.GetFiles(enrollePath, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s))).ToList();
                if (!myFiles.Any())
                {
                    return(new BiometricModel());
                }

                var bioModel = new BiometricModel
                {
                    PhotoPath   = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("photo_image")).ElementAt(0)).Replace("~", ""),
                    LeftLittle  = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("LFLittle")).ElementAt(0)).Replace("~", ""),
                    LeftRing    = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("LFRing")).ElementAt(0)).Replace("~", ""),
                    LeftMiddle  = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("LFMiddle")).ElementAt(0)).Replace("~", ""),
                    LeftIndex   = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("LFIndex")).ElementAt(0)).Replace("~", ""),
                    LeftThumb   = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("LFThumb")).ElementAt(0)).Replace("~", ""),
                    RightThumb  = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("RFThumb")).ElementAt(0)).Replace("~", ""),
                    RightIndex  = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("RFIndex")).ElementAt(0)).Replace("~", ""),
                    RightMiddle = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("RFMiddle")).ElementAt(0)).Replace("~", ""),
                    RightRing   = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("RFRing")).ElementAt(0)).Replace("~", ""),
                    RightLittle = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("RFLittle")).ElementAt(0)).Replace("~", ""),
                    Signature   = GenericHelpers.MapPath(myFiles.Where(f => f.Contains("sign_image")).ElementAt(0)).Replace("~", "")
                };

                return(bioModel);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new BiometricModel());
            }
        }
        public ActionResult GenerateLicense(string projectCode)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (string.IsNullOrEmpty(projectCode))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "The selected Project information could not be accessed. Please try again later";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var projects = _projectService.Query(p => p.ProjectCode == projectCode).Select().ToList();

                if (!projects.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "The selected Project information could not be accessed. Please try again later";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var fieldTypes = _customFieldTypeService.Queryable().ToList();
                if (!fieldTypes.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Project Custom Fields could not be retrieved. Please ensure all required setups are handled appropriately before proceeding.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var projectCustomGroups = _projectCustomGroupService.Query(g => g.ProjectCode == projectCode).Select().ToList();
                if (!projectCustomGroups.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Project Custom Groups could not be retrieved. Please ensure all required setups are handled appropriately before proceeding.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var projectCustomFields = _projectCustomFieldService.Query(g => g.ProjectCode == projectCode).Select().ToList();
                if (!projectCustomFields.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Project Custom Fields could not be retrieved. Please ensure all required setups are handled appropriately before proceeding.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var project = projects[0];

                var projectLicense = new ProjectLicense
                {
                    ProjectName         = project.ProjectName,
                    ProjectDescription  = project.ProjectDescription,
                    ProjectCode         = project.ProjectCode,
                    LicenseExpiryDate   = project.LicenseExpiryDate,
                    DateCreated         = project.DateCreated,
                    ProjectCustomGroups = projectCustomGroups.ToArray(),
                    ProjectCustomFields = projectCustomFields.ToArray()
                };

                var customGroups   = new List <CustomGroup>();
                var customFields   = new List <CustomField>();
                var customList     = new List <CustomList>();
                var customListData = new List <CustomListData>();

                projectCustomGroups.ForEach(c =>
                {
                    var groups = _customGroupService.Query(l => l.CustomGroupId == c.CustomGroupId).Select().ToList();

                    if (groups.Any())
                    {
                        if (!customGroups.Exists(g => g.CustomGroupId == groups[0].CustomGroupId))
                        {
                            customGroups.Add(groups[0]);
                        }
                    }
                });

                projectCustomFields.ForEach(c =>
                {
                    var fields = _customFieldService.Query(l => l.CustomFieldId == c.CustomFieldId).Select().ToList();

                    if (!fields.Any())
                    {
                        return;
                    }

                    var customField = fields[0];
                    var customLists = _customListService.Query(l => l.CustomListId == customField.CustomListId).Select().ToList();
                    var cGroups     = _customGroupService.Query(l => l.CustomGroupId == customField.CustomGroupId).Select().ToList();

                    if (cGroups.Any())
                    {
                        if (!customGroups.Exists(a => a.CustomGroupId == cGroups[0].CustomGroupId))
                        {
                            customGroups.Add(cGroups[0]);
                        }

                        if (customLists.Any())
                        {
                            var cListItem = customLists[0];

                            if (!customList.Exists(a => a.CustomListId == cListItem.CustomListId))
                            {
                                customList.Add(cListItem);
                                var list = _customListDataService.Query(d => d.CustomListId == cListItem.CustomListId).Select().ToList();
                                if (list.Any())
                                {
                                    list.ForEach(l =>
                                    {
                                        if (!customListData.Exists(a => a.CustomListDataId == l.CustomListDataId))
                                        {
                                            customListData.Add(l);
                                        }
                                    });
                                }
                            }
                        }

                        customFields.Add(customField);
                    }
                });

                projectLicense.CustomFields     = customFields.ToArray();
                projectLicense.CustomGroups     = customGroups.ToArray();
                projectLicense.CustomLists      = customList.ToArray();
                projectLicense.CustomListData   = customListData.ToArray();
                projectLicense.CustomFieldTypes = fieldTypes.ToArray();

                const string folderPath = "~/TempProjectSetUp";

                var filePath = Server.MapPath(folderPath + "/" + projectLicense.ProjectName.Replace(" ", "-") + ".json");

                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }

                System.IO.File.WriteAllText(filePath, JsonConvert.SerializeObject(projectLicense));

                acResponse.Code         = 5;
                acResponse.DownloadLink = GenericHelpers.MapPath(filePath);
                acResponse.Message      = "Project License was successfully generated.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e.StackTrace, e.Source, e.Message);
                acResponse.Code    = -1;
                acResponse.Message = "The selected Project information could not be accessed. Please try again later";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }