internal long AddEnroller(Enroller enroller, out string msg) { try { #region Null Validation List <ValidationResult> valResults; if (!EntityValidatorHelper.Validate(enroller, 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"); } msg = errorDetail.ToString(); return(-1); } #endregion #region Check Duplication //var station = GetStation(corporateInfo.StationId); //if (station == null || string.IsNullOrEmpty(station.StationName) || station.ClientStationId < 1) //{ // response.ResponseStatus.Message.FriendlyMessage = response.ResponseStatus.Message.TechnicalMessage = "Invalid Station Key"; // return response; //} if (IsDuplicate(enroller.ClientStationId, enroller.UserName, enroller.Email, enroller.EnrollerRegId, enroller.MobileNumber, out msg)) { return(0); } #endregion enroller.UserCode = Crypto.HashPassword(enroller.Password); enroller.Salt = EncryptionHelper.GenerateSalt(30, 50); enroller.Password = Crypto.GenerateSalt(16); enroller.TimeStampRegistered = DateTime.Now; enroller.Status = 1; var processedClientStation = _repository.Add(enroller); _uoWork.SaveChanges(); msg = ""; return(processedClientStation.EnrollerId); } catch (Exception ex) { msg = "Processing Error Occurred! Please try again later " + ex.GetBaseException().Message; BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddRole(Role role, out string msg) { try { if (IsDuplicate(role.Name, out msg)) { return(-1); } var processedRole = _repository.Add(role); _uoWork.SaveChanges(); msg = ""; if (processedRole.RoleId > 0) { if (CacheManager.GetCache("ccPortalRoleList") != null) { CacheManager.RemoveCache("ccPortalRoleList"); } GetRoles(); } return(processedRole.RoleId); } catch (Exception ex) { msg = ex.Message; BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddUserRole(UserRole userRole) { try { var processedUserRole = _repository.Add(userRole); _uoWork.SaveChanges(); return(processedUserRole.UserRoleId); } catch (Exception ex) { BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddUserLoginActivity(UserLoginActivity loginActivity) { try { var processedUserLoginActivity = _repository.Add(loginActivity); _uoWork.SaveChanges(); return(processedUserLoginActivity.UserLoginActivityId); } catch (Exception ex) { BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
internal long AddOrganization(Organization organization, out string msg) { try { #region Null Validation List <ValidationResult> valResults; if (!EntityValidatorHelper.Validate(organization, 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"); } msg = errorDetail.ToString(); return(-1); } #endregion #region Check Duplication if (IsDuplicate2(organization, out msg)) { return(0); } #endregion organization.TimeStampRegistered = DateTime.Now; //organization.Status = 1; var processedOrganization = _repository.Add(organization); _uoWork.SaveChanges(); msg = ""; return(processedOrganization.OrganizationId); } catch (Exception ex) { msg = "Processing Error Occurred! Please try again later " + ex.GetBaseException().Message; BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
internal long AddClientStation(ClientStation clientStation, out string msg) { try { clientStation.APIAccessKey = "3924156302"; List <ValidationResult> valResults; if (!EntityValidatorHelper.Validate(clientStation, 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"); } msg = errorDetail.ToString(); return(-1); } #region Get Organization Info //var clientOrg = new OrganizationRepository().GetOrganization(clientStation.OrganizationId); #endregion //var key = GenerateStationKey(clientStation.StationName, clientOrg.PhoneNumber, clientStation.StationId); var key = GenerateStationKey(clientStation.StationName, "08036975694", clientStation.StationId); if (string.IsNullOrEmpty(key) || key.Length != 10) { msg = "Unable to generate Station Key"; return(-1); } clientStation.APIAccessKey = key; clientStation.TimeStampRegistered = DateTime.Now; clientStation.Status = 1; var processedClientStation = _repository.Add(clientStation); _uoWork.SaveChanges(); msg = ""; return(processedClientStation.ClientStationId); } catch (Exception ex) { msg = "Processing Error Occurred! Please try again later " + ex.GetBaseException().Message; BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public static long Generate() { try { _uoWork = new DataKioskUoWork(/*You can specify you custom context here*/); _repository = new DataKioskRepository <SerialNumberKeeper>(_uoWork); Purge(); var processedScratchPin = _repository.Add(new SerialNumberKeeper()); _uoWork.SaveChanges(); return(processedScratchPin.SerialNumberKeeperId); } catch (Exception ex) { BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message); return(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); } }