Beispiel #1
0
 public HomeViewModel(IMvxNavigationService navigationService, IUserDialogs userDialogs, IBaseDataService dataService)
 {
     _navigationService = navigationService;
     _userDialogs       = userDialogs;
     _dataService       = dataService;
     _recordDatas       = _dataService.Query();
 }
Beispiel #2
0
        public ActionResult ProcessApproval(Approval approval)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (!User.Identity.IsAuthenticated)
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Your session has timed out. Please log in to continue";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }
                var userId          = User.Identity.GetUserId();
                var registeredUsers = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(e => e.Id == userId).Include("UserInfo").ToList();
                if (!registeredUsers.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please try again or contact the support team.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(approval.EnrollmentId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please refresg the page and try again";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (approval.ApprovalStatus < 1)
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please provide Approval Status";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var baseDatas = _baseDataService.Query(b => b.EnrollmentId == approval.EnrollmentId).Select().ToList();
                var baseData  = baseDatas[0];
                baseData.DateLastUpdated = DateTime.Now;
                baseData.ApprovalStatus  = approval.ApprovalStatus;
                _unitOfWork.SaveChanges();

                approval.DateProcessed = baseData.DateLastUpdated;

                approval.ProcessedById = registeredUsers[0].UserInfo.Id;

                if (string.IsNullOrEmpty(approval.ApprovalId))
                {
                    approval.ApprovalId = Guid.NewGuid().ToString();
                    _approvalService.Insert(approval);
                    _unitOfWork.SaveChanges();
                }
                else
                {
                    _approvalService.Update(approval);
                    _unitOfWork.SaveChanges();
                }

                acResponse.Code    = 5;
                acResponse.Message = "Approval Process was successfully completed";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                acResponse.Code    = -1;
                acResponse.Message = "An unknown error was encountered. Please try again.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
        public ActionResult NoPhoto()
        {
            var currentProject = GetProjectInSession();

            if (currentProject == null)
            {
                return(RedirectToAction("ProjectOptions", "Home"));
            }
            var projects = _projectService.Query(p => p.ProjectCode == currentProject.ProjectCode).Select().ToList();

            if (!projects.Any())
            {
                return(RedirectToAction("SiteActivation", "SiteActivator"));
            }

            var project = projects[0];

            if (project.LicenseExpiryDate < DateTime.Today)
            {
                Session["siteStatus"] = "expired";
                return(RedirectToAction("SiteActivation", "SiteActivator", new RouteValueDictionary(new KeyValuePair <string, string>("ProjectExpired", "true"))));
            }

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var userId          = User.Identity.GetUserId();
            var registeredUsers = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(e => e.Id == userId).Include("UserInfo").ToList();

            if (!registeredUsers.Any())
            {
                return(View(new List <BaseData>()));
            }

            var enrolledBy = registeredUsers[0].UserInfo.Id;
            var list       = new List <BaseData>();

            var appSettings = _appSettingService.Queryable().ToList();

            if (!appSettings.Any())
            {
                return(View(new List <BaseData>()));
            }
            var mainPath = appSettings[0].BiometricTemplatePath;

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

            var capturedDirs = Directory.GetDirectories(Server.MapPath(mainPath)).ToList();

            if (!capturedDirs.Any())
            {
                return(View(new List <BaseData>()));
            }

            var viewList = new List <BaseData>();

            if (User.IsInRole("Admin") || User.IsInRole("Site_Admin"))
            {
                list = _baseDataService.Query().Select().ToList();
            }
            else
            {
                if (!User.IsInRole("Enrollee"))
                {
                    list = _baseDataService.Query(t => t.CreatedBy == enrolledBy || t.LastUpdatedby == enrolledBy).Select().ToList();
                }
                else
                {
                    return(Redirect("Enrollment"));
                }
            }

            list.ForEach(d =>
            {
                var enrolleeFolder = capturedDirs.Find(e => e.Contains(d.EnrollmentId));
                if (enrolleeFolder != null)
                {
                    var enrollePath = Server.MapPath(mainPath + "/" + d.EnrollmentId);

                    var myFiles = Directory.GetFiles(enrollePath, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s))).ToList();
                    if (myFiles.Any())
                    {
                        var photos = myFiles.Where(f => f.Contains("photo_image")).ElementAt(0).ToList();
                        if (!photos.Any())
                        {
                            viewList.Add(d);
                        }
                    }
                    else
                    {
                        viewList.Add(d);
                    }
                }
                else
                {
                    viewList.Add(d);
                }
            });

            return(View(viewList));
        }
        public ActionResult GetCustomDataGroupFields_New(string baseDataId)
        {
            var genObj = new GenericObjectModel
            {
                CustomGroupViewModels = new List <CustomGroupViewModel>()
            };

            try
            {
                var currentProject = GetProjectInSession();
                if (string.IsNullOrEmpty(currentProject?.ProjectCode))
                {
                    return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet));
                }
                var projectCustomGroups = _projectCustomGroupService.Query(g => g.ProjectCode == currentProject.ProjectCode).Select().ToList();
                if (!projectCustomGroups.Any())
                {
                    return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet));
                }
                var baseDataList = _baseDataService.Query(b => b.EnrollmentId == baseDataId).Select().ToList();
                if (!baseDataList.Any())
                {
                    return(Json(genObj, JsonRequestBehavior.AllowGet));
                }

                var baseData = baseDataList[0];

                genObj.Name               = baseData.Firstname + " " + baseData.Surname;
                genObj.ProjectSiteId      = baseData.ProjectSiteId;
                genObj.EnrollmentId       = baseData.EnrollmentId;
                genObj.ProjectPrimaryCode = baseData.ProjectPrimaryCode;
                genObj.FormPath           = baseData.FormPath;

                var customGroups = new List <CustomGroupViewModel>();
                projectCustomGroups.ForEach(t =>
                {
                    var newGroups = _customGroupService.Query(d => d.CustomGroupId == t.CustomGroupId).Select(g => new CustomGroupViewModel
                    {
                        TableId       = g.TableId,
                        CustomGroupId = g.CustomGroupId,
                        GroupName     = g.GroupName,
                        TabIndex      = g.TabIndex
                    }).ToList();

                    if (newGroups.Any())
                    {
                        customGroups.Add(newGroups[0]);
                    }
                });


                if (!customGroups.Any())
                {
                    return(Json(genObj, JsonRequestBehavior.AllowGet));
                }

                customGroups.ForEach(c =>
                {
                    c.CustomFieldViewModels = new List <GenericViewModel>();

                    var customFields = _customFieldService.Query(g => g.CustomGroupId == c.CustomGroupId).Select().ToList();

                    if (customFields.Any())
                    {
                        customFields.ForEach(cFieldView =>
                        {
                            var customFieldTypes = _customFieldTypeService.Query(f => f.FieldTypeId == cFieldView.FieldTypeId).Select().ToList();
                            if (!customFieldTypes.Any())
                            {
                                return;
                            }

                            var customFieldType      = customFieldTypes[0];
                            var customFieldViewModel = new GenericViewModel
                            {
                                CustomList      = new CustomListViewModel(),
                                CustomFieldType = new CustomFieldType()
                            };

                            if (customFieldType.FieldTypeName == "List")
                            {
                                var customList = _customListService.Query(s => s.CustomListId == cFieldView.CustomListId && string.IsNullOrEmpty(s.ParentListId)).Select().ToList();
                                if (customList.Any())
                                {
                                    var list = customList[0];
                                    var l1   = new CustomListViewModel
                                    {
                                        CustomListName  = list.CustomListName,
                                        CustomListId    = list.CustomListId,
                                        HasChildren     = false,
                                        ParentListId    = list.ParentListId,
                                        CustomListDatas = new List <CustomListData>()
                                    };

                                    //var l1Data = _customListDataService.Query(s => s.CustomListId == l1.CustomListId).Select().ToList();

                                    //if (l1Data.Any())
                                    //{
                                    //    l1.CustomListDatas = l1Data;
                                    //}

                                    var childList = _customListService.Query(s => s.ParentListId == list.CustomListId).Select().ToList();
                                    if (childList.Any())
                                    {
                                        l1.HasChildren = true;
                                    }

                                    customFieldViewModel.TableId         = cFieldView.TableId;
                                    customFieldViewModel.CustomFieldId   = cFieldView.CustomFieldId;
                                    customFieldViewModel.CustomFieldName = cFieldView.CustomFieldName;
                                    customFieldViewModel.CustomFieldSize = cFieldView.CustomFieldSize;
                                    customFieldViewModel.CustomListId    = cFieldView.CustomListId;
                                    customFieldViewModel.ParentFieldId   = cFieldView.ParentFieldId;
                                    customFieldViewModel.CustomGroupId   = cFieldView.CustomGroupId;
                                    customFieldViewModel.FieldTypeId     = cFieldView.FieldTypeId;
                                    customFieldViewModel.TabIndex        = cFieldView.TabIndex;
                                    customFieldViewModel.Required        = cFieldView.Required;
                                    customFieldViewModel.CustomFieldType = customFieldType;
                                    customFieldViewModel.CustomList      = l1;
                                }
                            }
                            else
                            {
                                customFieldViewModel = new GenericViewModel
                                {
                                    TableId         = cFieldView.TableId,
                                    CustomFieldId   = cFieldView.CustomFieldId,
                                    CustomFieldName = cFieldView.CustomFieldName,
                                    CustomFieldSize = cFieldView.CustomFieldSize,
                                    ParentFieldId   = cFieldView.ParentFieldId,
                                    CustomListId    = cFieldView.CustomListId,
                                    CustomGroupId   = cFieldView.CustomGroupId,
                                    FieldTypeId     = cFieldView.FieldTypeId,
                                    TabIndex        = cFieldView.TabIndex,
                                    Required        = cFieldView.Required,
                                    CustomFieldType = customFieldType
                                };
                            }

                            c.CustomFieldViewModels.Add(customFieldViewModel);
                        });
                    }
                    genObj.CustomGroupViewModels.Add(c);
                });

                genObj.CustomGroupViewModels.ForEach(g =>
                {
                    g.CustomFieldViewModels = g.CustomFieldViewModels.OrderBy(f => f.TabIndex).ToList();
                });

                var ordered = genObj.CustomGroupViewModels.OrderBy(m => m.TabIndex).ToList();
                return(Json(ordered, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet));
            }
        }