예제 #1
0
        public UploadClientStation ValidateUploadClientAccess(string stationId, string stationName, string accessKey, out string msg)
        {
            try
            {
                var stationInfo = GetStation(stationId);
                if (stationInfo == null || stationInfo.ClientStationId < 1)
                {
                    msg = "Unregistered / Invalid Authorization Access";
                    return(null);
                }
                if (
                    string.Compare(stationInfo.APIAccessKey.Trim(), accessKey.Trim(),
                                   StringComparison.CurrentCultureIgnoreCase) != 0 ||
                    string.Compare(stationInfo.StationId.Trim(), stationId.Trim(),
                                   StringComparison.CurrentCultureIgnoreCase) != 0 ||
                    string.Compare(stationInfo.StationName.Trim(), stationName.Trim(),
                                   StringComparison.CurrentCultureIgnoreCase) != 0)
                {
                    msg = "Unregistered / Invalid Authorization Access";
                    return(null);
                }
                //if (stationInfo.Status != 2)
                //{
                //    msg = "Unauthorized Access!";
                //    return null;
                //}

                var orgName = _organizationRepository.GetById(stationInfo.OrganizationId).Name;
                var retInfo = new UploadClientStation
                {
                    ClientStationId    = stationInfo.ClientStationId,
                    StationId          = stationInfo.StationId,
                    StationName        = stationInfo.StationName,
                    APIAccessKey       = stationInfo.APIAccessKey,
                    StateId            = stationInfo.StateId,
                    LocalAreaId        = stationInfo.LocalAreaId,
                    OrganizationId     = stationInfo.OrganizationId,
                    OrganizationName   = orgName,
                    RegisteredByUserId = stationInfo.RegisteredByUserId
                };

                msg = "";
                return(retInfo);
            }
            catch (Exception ex)
            {
                msg = "Unable to validate Station Access";
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
예제 #2
0
        public BulkBeneficiaryRegResponseObj AddBulkBeneficiary(BulkBeneficiaryRegObj beneficiaryRegObjs, UploadClientStation station)
        {
            var response = new BulkBeneficiaryRegResponseObj
            {
                MainStatus = new ResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new ResponseMessage()
                },
                BeneficiaryRegResponses = new List <BeneficiaryRegResponseObj>()
            };

            try
            {
                return(_beneficiaryRepository.AddBulkBeneficiary(beneficiaryRegObjs, station));
            }
            catch (Exception ex)
            {
                response.MainStatus.Message.FriendlyMessage  = "Processing Error Occurred! Please try again later";
                response.MainStatus.Message.TechnicalMessage = "Error: " + ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(response);
            }
        }
예제 #3
0
        public BulkBeneficiaryRegResponseObj AddBulkBeneficiary(BulkBeneficiaryRegObj beneficiaryRegObjs, UploadClientStation station)
        {
            var response = new BulkBeneficiaryRegResponseObj
            {
                MainStatus = new ResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new ResponseMessage
                    {
                        FriendlyMessage  = "",
                        TechnicalMessage = ""
                    }
                },
                BeneficiaryRegResponses = new List <BeneficiaryRegResponseObj>()
            };

            try
            {
                List <ValidationResult> valResults;
                if (!EntityValidatorHelper.Validate(beneficiaryRegObjs, out valResults))
                {
                    var errorDetail = new StringBuilder();
                    if (!valResults.IsNullOrEmpty())
                    {
                        errorDetail.AppendLine("Following error occurred:");
                        valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage));
                    }
                    else
                    {
                        errorDetail.AppendLine("Validation error occurred! Please check all supplied parameters and try again");
                    }

                    response.MainStatus.Message.FriendlyMessage = response.MainStatus.Message.TechnicalMessage = errorDetail.ToString();
                    return(response);
                }

                if (beneficiaryRegObjs.BeneficiaryRegObjs.IsNullOrEmpty())
                {
                    response.MainStatus.Message.FriendlyMessage  = "Data List is empty!";
                    response.MainStatus.Message.TechnicalMessage = "Data List is empty!";
                    return(response);
                }

                //var valSettings = new DataValidationSettingRepository().GetDataValidationSettings();
                //if (valSettings.IsNullOrEmpty())
                //{
                //    response.MainStatus.Message.FriendlyMessage = "Invalid Data Validation Setting";
                //    response.MainStatus.Message.TechnicalMessage = "Unable to retrieve Data Validation Parameters";
                //    return null;
                //}

                foreach (var item in beneficiaryRegObjs.BeneficiaryRegObjs)
                {
                    var thisResponse = new BeneficiaryRegResponseObj
                    {
                        Status = new ResponseStatus
                        {
                            IsSuccessful = false,
                            Message      = new ResponseMessage
                            {
                                FriendlyMessage  = "",
                                TechnicalMessage = ""
                            }
                        },
                        BeneficiaryId = item.BeneficiaryId,
                        MobileNumber  = item.MobileNumber,
                    };

                    try
                    {
                        valResults = new List <ValidationResult>();
                        if (!EntityValidatorHelper.Validate(item, out valResults))
                        {
                            var errorDetail = new StringBuilder();
                            if (!valResults.IsNullOrEmpty())
                            {
                                errorDetail.AppendLine("Following error occurred:");
                                valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage));
                            }
                            else
                            {
                                errorDetail.AppendLine("Validation error occurred! Please check all supplied parameters and try again");
                            }

                            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = errorDetail.ToString();
                            response.BeneficiaryRegResponses.Add(thisResponse);
                            continue;
                        }

                        var regStatus = (RegStatus)Enum.Parse(typeof(RegStatus), item.Status.ToString(CultureInfo.InvariantCulture));

                        #region Delete

                        //try
                        //{
                        //    if (regStatus == RegStatus.Deleted)
                        //    {

                        //        if (!valSettings.Find(m => (string.Compare(m.Name.Trim(), "Can_Delete_Record", StringComparison.CurrentCultureIgnoreCase) == 0)).ValidationValue)
                        //        {
                        //            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Data Deleting Feature is currently turned off! Unable to delete this record on the remote server";
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        if (item.BusinessInfoRemoteId < 1)
                        //        {
                        //            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Invalid Remote Record Id! Unable to complete operation on this record";
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        var buzInfo = GetBusinessInfoItem(item.BusinessInfoRemoteId);
                        //        if (buzInfo == null)
                        //        {
                        //            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "No Remote Record Found! The specified Remote Id did not return any record";
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }
                        //        buzInfo.Status = RegStatus.Deleted;
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    thisResponse.Status.Message.FriendlyMessage = "Unable to process this record due to error";
                        //    thisResponse.Status.Message.TechnicalMessage = "Error: " + ex.Message;
                        //    BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                        //    response.BeneficiaryRegResponses.Add(thisResponse);
                        //    continue;
                        //}

                        #endregion
                        #region Edit
                        //try
                        //{
                        //    if (regStatus == RegStatus.Edited)
                        //    {



                        //        if (!valSettings.Find(m => (string.Compare(m.Name.Trim(), "Can_Edit_Record", StringComparison.CurrentCultureIgnoreCase) == 0)).ValidationValue)
                        //        {
                        //            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Data Editing Feature is currently turned off! Unable to update this record on the remote server";
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        if (item.BusinessInfoRemoteId < 1)
                        //        {
                        //            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Invalid Remote Record Id! Unable to complete operation on this record";
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        var bizInfo = loadBusinessInfo(item, businessRegObjs.LocalAreaId, valSettings, ref thisResponse.Status);
                        //        if (bizInfo == null)
                        //        {
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        if (!doValidation(bizInfo, 2, valSettings, ref thisResponse.Status))
                        //        {
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //            continue;
                        //        }

                        //        using (var db = _uoWork.BeginTransaction())
                        //        {
                        //            var processedBusinessInfo = _repository.Update(bizInfo);
                        //            _uoWork.SaveChanges();
                        //            if (processedBusinessInfo.BusinessInfoId < 1)
                        //            {
                        //                db.Rollback();
                        //                thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Update process failed!";
                        //                response.BusinessRegResponses.Add(thisResponse);
                        //                continue;
                        //            }

                        //            var ownerInfo = bizInfo.BusinessOwnerInfo;
                        //            var ownerRet = _ownerRepository.Update(ownerInfo);
                        //            _uoWork.SaveChanges();

                        //            if (ownerRet.BusinessOwnerInfoId < 1)
                        //            {
                        //                db.Rollback();
                        //                thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Processing Failed! Please try again later";
                        //                response.BusinessRegResponses.Add(thisResponse);
                        //                continue;
                        //            }

                        //            db.Commit();
                        //            thisResponse.Status.IsSuccessful = true;
                        //            thisResponse.BusinessInfoRemoteId = bizInfo.BusinessInfoId;
                        //            thisResponse.BusinessOwnerInfoRemoteId = ownerInfo.BusinessOwnerInfoId;
                        //            response.BusinessRegResponses.Add(thisResponse);
                        //        }
                        //        continue;
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    thisResponse.Status.Message.FriendlyMessage = "Unable to process this record due to error";
                        //    thisResponse.Status.Message.TechnicalMessage = "Error: " + ex.Message;
                        //    ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        //    response.BusinessRegResponses.Add(thisResponse);
                        //    continue;
                        //}

                        #endregion
                        #region New Record


                        #region Saving Image

                        string msg;
                        var    org           = station.OrganizationName;
                        var    stationId     = station.StationId;
                        var    enrollerRegId = station.EnrollerRegId;
                        //var image = Utils.BeneficiaryRegObj.Image;

                        var imgResPath = EnrollHelper.PrepareImagePath(org, stationId, enrollerRegId, out msg);
                        if (imgResPath.IsNullOrEmpty() || !msg.IsNullOrEmpty())
                        {
                            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = msg;
                            response.BeneficiaryRegResponses.Add(thisResponse);
                            continue;
                        }

                        var bytes = Convert.FromBase64String(item.ImageByteString);
                        File.WriteAllBytes(@imgResPath, bytes);
                        var imgFileName = Path.GetFileName(imgResPath);

                        #region Biometric

                        //var listOfArrays = new List<byte[]>();
                        //var array = listOfArrays
                        //                .SelectMany(a => a)
                        //                .ToArray();


                        var fingerPrintByteArray = item.FingerPrintTemplate
                                                   .SelectMany(a => a)
                                                   .ToArray();

                        //var bio = new BiometricData
                        //{
                        //    FingerPrintTemplates = item.FingerPrintTemplate,
                        //    ImageFileName = Path.GetFileName(imgResPath),
                        //    ImagePath = "~/" + imgResPath
                        //};
                        //string _bio = JsonConvert.SerializeObject(bio);


                        #endregion

                        #endregion

                        var ben = new Beneficiary
                        {
                            Surname              = item.Surname,
                            FirstName            = item.FirstName,
                            Othernames           = item.Othernames,
                            Sex                  = item.Sex,
                            MaritalStatus        = item.MaritalStatus,
                            OccupationId         = item.OccupationId,
                            DateOfBirth          = item.DateOfBirth,
                            ResidentialAddress   = item.ResidentialAddress,
                            OfficeAddress        = item.OfficeAddress,
                            LocalAreaId          = item.LocalAreaId,
                            StateId              = item.StateId,
                            ImageFileName        = imgFileName,
                            ImagePath            = "~/" + imgResPath,
                            RemoteImageFileName  = item.ImageFileName,
                            BeneficiaryRemoteId  = item.BeneficiaryId,
                            FingerPrintTemplates = fingerPrintByteArray,
                            //Biometric = _bio,

                            SurnameHashed     = UniqueHashing.GetStandardHash(item.Surname.Trim().Replace(" ", "").ToLower()),
                            FirstNameHashed   = UniqueHashing.GetStandardHash(item.FirstName.Trim().Replace(" ", "").ToLower()),
                            OtherNameHashed   = UniqueHashing.GetStandardHash(item.Othernames.Trim().Replace(" ", "").ToLower()),
                            MobileNoHashed    = UniqueHashing.GetStandardHash(item.MobileNumber.Trim().Replace(" ", "").ToLower()),
                            DateOfBirthHashed = UniqueHashing.GetStandardHash(item.DateOfBirth.Trim().Replace(" ", "").ToLower()),

                            Status              = regStatus,
                            EnrollerId          = station.EnrollerId,
                            ClientStationId     = station.ClientStationId,
                            TimeStampRegistered = DateTime.Now,
                        };

                        if (!doValidation(ben, 1, ref thisResponse.Status))
                        {
                            response.BeneficiaryRegResponses.Add(thisResponse);
                            continue;
                        }

                        var retVal = _repository.Add(ben);
                        _uoWork.SaveChanges();
                        if (retVal.BeneficiaryId < 1)
                        {
                            thisResponse.Status.Message.FriendlyMessage = thisResponse.Status.Message.TechnicalMessage = "Processing Failed! Please try again later";
                            response.BeneficiaryRegResponses.Add(thisResponse);
                            continue;
                        }

                        thisResponse.Status.IsSuccessful = true;
                        thisResponse.BeneficiaryRemoteId = retVal.BeneficiaryId;
                        response.BeneficiaryRegResponses.Add(thisResponse);
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        thisResponse.Status.Message.FriendlyMessage  = "Processing Error Occurred! Please try again later";
                        thisResponse.Status.Message.TechnicalMessage = "Error: " + ex.Message;
                        BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                        response.BeneficiaryRegResponses.Add(thisResponse);
                    }
                }


                response.MainStatus.IsSuccessful = true;
                return(response);
            }
            catch (Exception ex)
            {
                response.MainStatus.Message.FriendlyMessage  = "Processing Error Occurred! Please try again later";
                response.MainStatus.Message.TechnicalMessage = "Error: " + ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(response);
            }
        }