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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
Example #4
0
        public bool UpdateStationInfo(StationInfo corporateInfo, out string msg)
        {
            try
            {
                #region Model Validation

                // Validation

                List <ValidationResult> valResults;
                if (!EntityValidatorHelper.Validate(corporateInfo, 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(false);
                    }
                }

                #endregion

                var stationInfo = _repository.Update(corporateInfo);
                _uoWork.SaveChanges();
                msg = "";
                return(stationInfo.StationInfoId > 0);
            }
            catch (Exception ex)
            {
                msg = "Processing Error Occurred! Please try again later";
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }
Example #5
0
        public SettingRegRespObj AddBulkStaffMemo(RegBulkStaffMemoObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj?.StaffMemoItem == null || !regObj.StaffMemoItem.Any())
                {
                    response.Status.Message.FriendlyMessage  = "Empty Request Item! Please try again later";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                foreach (var reqitem in regObj.StaffMemoItem)
                {
                    if (!EntityValidatorHelper.Validate(reqitem, out var valItemResults))
                    {
                        var errorDetail = new StringBuilder();
                        if (!valItemResults.IsNullOrEmpty())
                        {
                            errorDetail.AppendLine("Following error occurred:");
                            valItemResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage));
                        }
                        else
                        {
                            errorDetail.AppendLine(
                                "Validation error occurred! Please check all supplied parameters and try again");
                        }
                        response.Status.Message.FriendlyMessage  = errorDetail.ToString();
                        response.Status.Message.TechnicalMessage = errorDetail.ToString();
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getStaffRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var staffMemoList = new List <StaffMemo>();
                var workflowList  = new List <WorkflowSetup>();
                var results       = staffMemoList.GroupBy(e => e.StaffMemoId, (key, g) => new
                {
                    StaffMemoId    = key,
                    StaffMemoItems = g.ToList()
                }).ToList();

                if (!results.Any())
                {
                    response.Status.Message.FriendlyMessage  = "Invalid Expense Item list";
                    response.Status.Message.TechnicalMessage = "Invalid Expense Item list";
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                foreach (var reqItem in results)
                {
                    if (reqItem.StaffMemoItems.Count > 1)
                    {
                        response.Status.Message.FriendlyMessage =
                            $"Duplicate Staff Memo Item {getStaffMemo(reqItem.StaffMemoItems[0].StaffId).MemoType.ToString()}";
                        response.Status.Message.TechnicalMessage =
                            $"Duplicate Staff Memo Item {getStaffMemo(reqItem.StaffMemoItems[0].StaffId).MemoType.ToString()}";
                        response.Status.IsSuccessful = false;
                        return(response);
                    }
                    staffMemoList.Add(new StaffMemo
                    {
                        StaffId           = reqItem.StaffMemoItems[0].StaffId,
                        Title             = reqItem.StaffMemoItems[0].Title,
                        MemoType          = reqItem.StaffMemoItems[0].MemoType,
                        MemoDetail        = reqItem.StaffMemoItems[0].MemoDetail,
                        IsReplied         = false,
                        RegisterBy        = regObj.AdminUserId,
                        ApprovedBy        = 0,
                        Status            = ApprovalStatus.Approved,
                        TimeStampRegister = DateMap.CurrentTimeStamp()
                    });
                    workFlowSourceId = staffMemoList[0].StaffMemoId;
                    workflowList.Add(new WorkflowSetup
                    {
                        Description           = reqItem.StaffMemoItems[0].Title,
                        InitiatorId           = regObj.AdminUserId,
                        InitiatorType         = WorkflowInitiatorType.HR,
                        Item                  = WorkflowItem.Staff_Memo,
                        WorkflowOrderId       = regObj.StaffMemoItem[0].WorkflowOrderId,
                        WorkflowSourceId      = workFlowSourceId,
                        LastTimeStampModified = DateMap.CurrentTimeStamp(),
                        StaffId               = reqItem.StaffMemoItems[0].StaffId,
                        TimeStampInitiated    = DateMap.CurrentTimeStamp(),
                        Status                = WorkflowStatus.Initiated
                    });
                }

                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.AddRange(staffMemoList);
                        _uoWork.SaveChanges();
                        if (added == null || !added.Any())
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }


                        var retVal = _workflowSetupRepository.AddRange(workflowList);
                        _uoWork.SaveChanges();
                        if (retVal == null || !retVal.Any())
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        response.Status.IsSuccessful     = true;
                        workflowList[0].WorkflowSourceId = staffMemoList[0].StaffMemoId;
                        db.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    catch (Exception ex)
                    {
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    return(response);
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
Example #6
0
        public CardRegRespObj AddCard(RegCardObj regObj)
        {
            var response = new CardRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                if (!DataCheck.IsNumeric(regObj.BatchKey))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Batch Key Invalid";
                    response.Status.Message.TechnicalMessage = "Batch Prefix Number Must be greater than 0";
                    return(response);
                }
                if (!DataCheck.IsNumeric(regObj.StartBatchId))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Invalid Start Batch Id";
                    response.Status.Message.TechnicalMessage = "Start Batch Id Is not numeric";
                    return(response);
                }
                if (!DataCheck.IsNumeric(regObj.StopBatchId))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Invalid Stop Batch Id";
                    response.Status.Message.TechnicalMessage = "Stop Batch Id Is not numeric";
                    return(response);
                }

                if ((int.Parse(regObj.StopBatchId) - int.Parse(regObj.StartBatchId)) + 1 != regObj.NumberOfBatches)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect StopBatchId/StartBatchId/NumberOfBatches";
                    response.Status.Message.TechnicalMessage = "Incorrect StopBatchId/StartBatchId/NumberOfBatches";
                    return(response);
                }
                if (regObj.QuantityPerBatch < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Quantity Per Batch Is Required";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Quantity Per Batch must be greater than zero!";
                    return(response);
                }
                //..................Continue here
                #region Batch Id Computation
                //var qtyPerBatchLength = regObj.QuantityPerBatch.
                #endregion

                //store date for Concurrency...
                var nowDateTime = DateMap.CurrentTimeStamp();
                var nowDate     = nowDateTime.Substring(0, nowDateTime.IndexOf(' '));
                var nowTime     = nowDateTime.Substring(nowDateTime.IndexOf('-') + 1);

                var cardItemList = new List <CardItem>();

                for (int i = int.Parse(regObj.StartBatchId); i < int.Parse(regObj.StopBatchId + 1); i++)
                {
                    cardItemList.Add(new CardItem
                    {
                        CardTypeId           = regObj.CardTypeId,
                        BatchId              = i.ToString(),
                        StartBatchNumber     = i.ToString() + "" + "000", //77001 000
                        StopBatchNumber      = i.ToString() + "" + "999", //77001999
                        DefectiveBatchNumber = "",
                        AvailableQuantity    = 0,
                        BatchQuantity        = 1000,
                        DeliveredQuantity    = 0,
                        MissingQuantity      = 0,
                        DefectiveQuantity    = 0,
                        IssuedQuantity       = 0,
                        RegisteredBy         = regObj.AdminUserId,
                        TimeStampRegisered   = nowDateTime,
                        TimeStampDelivered   = "",
                        TimeStampLastIssued  = "",
                        Status = CardStatus.Registered
                    });
                }

                var card = new Card
                {
                    CardTitle          = $"Card Production On {nowDate} At {nowTime}",
                    CardTypeId         = regObj.CardTypeId,
                    BatchKey           = regObj.BatchKey,
                    StartBatchId       = regObj.BatchKey + "000",
                    StopBatchId        = (Int32.Parse(regObj.BatchKey + "000") + (regObj.NumberOfBatches - 1)).ToString(),
                    NumberOfBatches    = regObj.NumberOfBatches,
                    QuantityPerBatch   = 1000,
                    TotalQuantity      = regObj.NumberOfBatches * regObj.QuantityPerBatch,
                    Status             = CardStatus.Registered,
                    TimeStampRegisered = nowDateTime,
                    CardItems          = cardItemList
                };

                var added = _repository.Add(card);
                _uoWork.SaveChanges();
                if (added.CardId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }

                response.Status.IsSuccessful = true;
                response.CardId = added.CardId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            return(response);
        }
        public JobLevelRespObj LoadJobLevels(CommonSettingSearchObj searchObj)
        {
            var response = new JobLevelRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(searchObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                //if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode, HelperMethods.getAllRoles(), ref response.Status.Message))
                //{
                //    return response;
                //}
                var thisJobLevels = GetJobLevels();
                if (!thisJobLevels.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No JobLevel Information found!";
                    response.Status.Message.TechnicalMessage = "No JobLevel  Information found!";
                    return(response);
                }

                if (searchObj.Status > -1)
                {
                    thisJobLevels = thisJobLevels.FindAll(p => p.Status == (ItemStatus)searchObj.Status);
                }

                var jobLevelItems = new List <JobLevelObj>();
                thisJobLevels.ForEachx(m =>
                {
                    jobLevelItems.Add(new JobLevelObj
                    {
                        JobLevelId  = m.JobLevelId,
                        Name        = m.Name,
                        Status      = (int)m.Status,
                        StatusLabel = m.Status.ToString().Replace("_", " ")
                    });
                });

                response.Status.IsSuccessful = true;
                response.JobLevels           = jobLevelItems;
                return(response);
            }

            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
        public SettingsRegResponseObj AddCardCommission(RegCardCommissionObj regObj)
        {
            var response = new SettingsRegResponseObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error occure!Unable to proceed to your Request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty/Invaild";
                    return(response);
                }

                if (regObj.LowerAmount == 0 || regObj.UpperAmount == 0)
                {
                    response.Status.Message.FriendlyMessage  = "Error occure!Lower/Upper Amount cannot be zero";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty/Invaild";
                    return(response);
                }

                if (regObj.LowerAmount > regObj.UpperAmount)
                {
                    response.Status.Message.FriendlyMessage  = "Error occure!LowerAmount cannot be greater than UpperAmount";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty/Invaild";
                    return(response);
                }

                var associatedCardType = GetCardTypeInfo(regObj.CardTypeId);

                if (associatedCardType == null)
                {
                    response.Status.Message.FriendlyMessage  = "Specified Card Type Info not available";
                    response.Status.Message.TechnicalMessage = "Specified Card Type Info not available";
                    return(response);
                }

                if (regObj.LowerAmount != associatedCardType.FaceValue)
                {
                    response.Status.Message.FriendlyMessage  = "Error occure!LowerAmount must be equal to face value";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty/Invaild";
                    return(response);
                }

                #region Lower Modulo

                if (regObj.LowerAmount % 2 == 0)
                {
                    if (regObj.LowerAmount % associatedCardType.FaceValue != 0)
                    {
                        response.Status.Message.FriendlyMessage  = $"Lower Amount must be a multiple of {associatedCardType.FaceValue}";
                        response.Status.Message.TechnicalMessage = $"Lower Amount must be a multiple of {associatedCardType.FaceValue}";
                        return(response);
                    }
                }
                else
                {
                    var lowerAmountCheck = regObj.LowerAmount + 1;

                    if (lowerAmountCheck % associatedCardType.FaceValue != 0)
                    {
                        response.Status.Message.FriendlyMessage  = $"Lower Amount must be a multiple of {associatedCardType.FaceValue}";
                        response.Status.Message.TechnicalMessage = $"Lower Amount must be a multiple of {associatedCardType.FaceValue}";
                        return(response);
                    }
                }
                #endregion

                #region Upper Modulo
                if (regObj.UpperAmount % 2 == 0)
                {
                    if (regObj.UpperAmount % associatedCardType.FaceValue != 0)
                    {
                        response.Status.Message.FriendlyMessage  = $"Upper Amount must be a multiple of {associatedCardType.FaceValue}";
                        response.Status.Message.TechnicalMessage = $"Upper Amount must be a multiple of {associatedCardType.FaceValue}";
                        return(response);
                    }
                }
                else
                {
                    var upperAmountCheck = regObj.UpperAmount + 1;

                    if (upperAmountCheck % associatedCardType.FaceValue != 0)
                    {
                        response.Status.Message.FriendlyMessage  = $"Upper Amount must be a multiple of {associatedCardType.FaceValue}";
                        response.Status.Message.TechnicalMessage = $"Upper Amount must be a multiple of {associatedCardType.FaceValue}";
                        return(response);
                    }
                }
                #endregion


                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                if (IsCardCommissionDuplicate(regObj.LowerAmount, regObj.UpperAmount, regObj.CommissionRatee,
                                              regObj.CardTypeId, 1, ref response))
                {
                    return(response);
                }

                var cardCommission = new CardCommission
                {
                    CommissionRatee = regObj.CommissionRatee,
                    CardTypeId      = regObj.CardTypeId,
                    LowerAmount     = regObj.LowerAmount,
                    UpperAmount     = regObj.UpperAmount,
                    Status          = (Status)regObj.Status
                };

                var added = _repository.Add(cardCommission);
                _uoWork.SaveChanges();
                if (added.CardCommissionId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }

                ResetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.CardCommissionId;
            }

            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            return(response);
        }
        public SettingRegRespObj UpdatekPIndex(EditKPIndexObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                var thiskPIndex = GetkPIndexInfo(regObj.KPIndexId);

                if (thiskPIndex == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Key Performance Indicator Information found for the specified KPIndex Id";
                    response.Status.Message.TechnicalMessage = "No Key Performance Indicator Information found!";
                    return(response);
                }

                if (IskPIndexDuplicate(regObj.Name, 2, ref response))
                {
                    return(response);
                }

                if (regObj.MinRating > regObj.MaxRating)
                {
                    response.Status.Message.FriendlyMessage  = "Minimum Rating cannot be higher than Maximum Rating";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                if (regObj.MinRating == regObj.MaxRating)
                {
                    response.Status.Message.FriendlyMessage  = "Minimum/Maximum Rating cannot be equal to each other";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                thiskPIndex.Name      = regObj.Name;
                thiskPIndex.Indicator = regObj.Indicator;
                thiskPIndex.MinRating = regObj.MinRating;
                thiskPIndex.MaxRating = regObj.MaxRating;
                thiskPIndex.Status    = (ItemStatus)regObj.Status;
                var added = _repository.Update(thiskPIndex);
                _uoWork.SaveChanges();

                if (added.KPIndexId < 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.KPIndexId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
Example #10
0
        public StaffMemoRespObj LoadStaffMemo(StaffMemoSearchObj searchObj)
        {
            var response = new StaffMemoRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(searchObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsStaffUserValid(searchObj.AdminUserId, searchObj.SysPathCode, searchObj.LoginIP,
                                                    false, out var staffInfo, ref response.Status.Message))
                {
                    return(response);
                }
                if (staffInfo == null || staffInfo.StaffId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Invalid Staff Information";
                    response.Status.Message.TechnicalMessage = "Invalid Staff Information";
                    return(response);
                }
                var thisStaffs = getStaffMemo(searchObj);
                if (thisStaffs == null || !thisStaffs.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Staff Information found!";
                    response.Status.Message.TechnicalMessage = "No Staff  Information found!";
                    return(response);
                }


                var staffMemoItems = new List <StaffMemoObj>();
                thisStaffs.ForEachx(m =>
                {
                    staffMemoItems.Add(new StaffMemoObj
                    {
                        StaffId           = m.StaffId,
                        FirstName         = new StaffRepository().getStaffInfo(m.StaffId).FirstName,
                        LastName          = new StaffRepository().getStaffInfo(m.StaffId).LastName,
                        StaffMemoId       = m.StaffMemoId,
                        Title             = m.Title,
                        MemoTypeId        = (int)m.MemoType,
                        MemoType          = m.MemoType.ToString().Replace("_", " "),
                        MemoDetail        = m.MemoDetail,
                        IsReplied         = m.IsReplied,
                        ApprovedBy        = m.ApprovedBy,
                        RegisterBy        = m.RegisterBy,
                        Status            = (int)m.Status,
                        StatusLabel       = m.Status.ToString().Replace("_", " "),
                        TimeStampRegister = m.TimeStampRegister
                    });
                });

                response.Status.IsSuccessful = true;
                response.StaffMemos          = staffMemoItems;
                return(response);
            }

            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
        public SettingsRegResponseObj AddCardType(RegCardTypeObj regObj)
        {
            var response = new SettingsRegResponseObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (regObj.FaceValue == 0)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Face Value cannot be Zero";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var valResult))
                {
                    var errorDetails = new StringBuilder();
                    if (!valResult.IsNullOrEmpty())
                    {
                        errorDetails.Append("The following error occured:");
                        valResult.ForEachx(m => errorDetails.Append(m.ErrorMessage));
                    }
                    else
                    {
                        errorDetails.Append(
                            "Validation Error Occured! Please check all supplied parameter and try again");
                    }

                    response.Status.Message.FriendlyMessage = errorDetails.ToString();
                    response.Status.Message.FriendlyMessage = errorDetails.ToString();
                    response.Status.IsSuccessful            = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                if (IsCardTypeDuplicate(regObj.Name, 1, ref response))
                {
                    return(response);
                }

                var card = new CardType
                {
                    Name      = regObj.Name,
                    FaceValue = regObj.FaceValue,
                    Status    = (Status)regObj.Status
                };

                var added = _repository.Add(card);
                _uoWork.SaveChanges();
                if (added.CardTypeId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }

                ResetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.CardTypeId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
        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);
            }
        }
        public CardTypeRespObj LoadCardType(SettingSearchObj searchObj)
        {
            var response = new CardTypeRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }


                if (!EntityValidatorHelper.Validate(searchObj, out var valResult))
                {
                    var errorDetails = new StringBuilder();
                    if (!valResult.IsNullOrEmpty())
                    {
                        errorDetails.Append("The following error occured:");
                        valResult.ForEachx(m => errorDetails.Append(m.ErrorMessage));
                    }
                    else
                    {
                        errorDetails.Append(
                            "Validation Error Occured! Please check all supplied parameter and try again");
                    }

                    response.Status.Message.FriendlyMessage = errorDetails.ToString();
                    response.Status.Message.FriendlyMessage = errorDetails.ToString();
                    response.Status.IsSuccessful            = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode,
                                               HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCardTypes = GetCardTypes();
                if (!thisCardTypes.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Card Type Information found!";
                    response.Status.Message.TechnicalMessage = "No Card Type  Information found!";
                    return(response);
                }

                if (searchObj.Status > -1)
                {
                    thisCardTypes = thisCardTypes.FindAll(m => m.Status == (Status)searchObj.Status);
                }

                var cardTypeItem = new List <CardTypeItemObj>();

                thisCardTypes.ForEachx(m =>
                {
                    cardTypeItem.Add(new CardTypeItemObj
                    {
                        Name            = m.Name,
                        FaceValue       = m.FaceValue,
                        CardStatus      = (int)m.Status,
                        CardStatusLabel = m.Status.ToString().Replace("_", "")
                    });
                });

                response.Status.IsSuccessful = true;
                response.CardTypes           = cardTypeItem;
                return(response);
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
        public BeneficiaryPaymentRegRespObj DeleteBeneficiaryPayment(DeleteBeneficiaryAccountTransactionObj regObj)
        {
            var response = new BeneficiaryPaymentRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, new[] { "PortalAdmin", "CRMAdmin", "CRMManager" }, ref response.Status.Message))
                {
                    return(response);
                }

                var thisBeneficiaryAccTrans = GetBeneficiaryAccTransactionInfo(regObj.BeneficiaryAccTransId);
                if (thisBeneficiaryAccTrans == null)
                {
                    response.Status.Message.FriendlyMessage  = "No Beneficiary Payment Information found for the specified BeneficiaryPayment Id";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Payment Information found!";
                    return(response);
                }

                thisBeneficiaryAccTrans.Status = Status.Deleted;

                var deleteBenAccTrans = _beneAccTransRepository.Update(thisBeneficiaryAccTrans);
                _uoWork.SaveChanges();
                if (deleteBenAccTrans.BeneficiaryAccountTransactionId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }

                response.Status.IsSuccessful            = true;
                response.PaymentId                      = deleteBenAccTrans.BeneficiaryAccountTransactionId;
                response.Status.Message.FriendlyMessage = "Deleted Successfully";
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
        public BeneficiaryPaymentRegRespObj AddBeneficiaryPayment(RegBeneficiaryPaymentObj regObj)
        {
            var response = new BeneficiaryPaymentRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var associatedBeneficiary = GetBeneficiaryInfo(regObj.BeneficiaryId);
                if (associatedBeneficiary == null)
                {
                    response.Status.Message.FriendlyMessage  = "Ooops ! Beneficiary Does not Exist!";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Information Found";
                    return(response);
                }

                if (associatedBeneficiary.Status != Status.Active)
                {
                    response.Status.Message.FriendlyMessage  = "Sorry!This Beneficiary Cannot Perform Any Transaction Yet! Please Contact Administrator";
                    response.Status.Message.TechnicalMessage = "Beneficiary Isn't Approved yet";
                    return(response);
                }
                var associatedBeneAccount = GetBeneficiaryAccountInfo(associatedBeneficiary.BeneficiaryAccountId);
                if (associatedBeneAccount == null)
                {
                    response.Status.Message.FriendlyMessage  = "Ooops ! Beneficiary Account Does not Exist!";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Account Information Found";
                    return(response);
                }

                if (!string.IsNullOrWhiteSpace(regObj.PaymentReference))
                {
                    if (DataCheck.IsNumeric(regObj.PaymentReference))
                    {
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Payment reference must be Numbers Only";
                        response.Status.Message.TechnicalMessage = "Payment Reference  is invalid";
                        return(response);
                    }

                    var associatedBenPayment = GetBeneficiaryPayment(new SettingSearchObj {
                        Status = -2
                    });
                    if (associatedBenPayment.Any())
                    {
                        if (associatedBenPayment.FindAll(payment => payment.PaymentReference == regObj.PaymentReference)
                            .Any())
                        {
                            response.Status.Message.FriendlyMessage  = "Error Occurred! Payment reference is Invalid";
                            response.Status.Message.TechnicalMessage = "Duplicate Error! Payment Reference  is Invalid!";
                            return(response);
                        }
                    }
                }

                //store date for Concurrency...
                var nowDateTime = DateMap.CurrentTimeStamp();
                var nowDate     = nowDateTime.Substring(0, nowDateTime.IndexOf(' '));
                var nowTime     = nowDateTime.Substring(nowDateTime.IndexOf('-') + 1);

                using (var db = _uoWork.BeginTransaction())
                {
                    #region Beneficiary Account Transaction Operation
                    var newBeneficiaryTransaction = new BeneficiaryAccountTransaction
                    {
                        BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId,
                        BeneficiaryId        = regObj.BeneficiaryId,
                        Amount              = regObj.AmountPaid,
                        PreviousBalance     = associatedBeneAccount.AvailableBalance,
                        NewBalance          = (associatedBeneAccount.AvailableBalance + regObj.AmountPaid),
                        TransactionSource   = TransactionSourceType.Account_TopUp,
                        TransactionType     = TransactionType.Credit,
                        Status              = Status.Active,
                        RegisteredBy        = regObj.AdminUserId,
                        TimeStampRegistered = nowDateTime,
                    };

                    var transactionAdded = _beneAccTransRepository.Add(newBeneficiaryTransaction);
                    _uoWork.SaveChanges();
                    if (transactionAdded.BeneficiaryAccountTransactionId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }

                    #endregion

                    #region Beneficiary Payment Operation

                    var newBeneficiaryPayment = new BeneficiaryPayment
                    {
                        BeneficiaryId        = regObj.BeneficiaryId,
                        BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId,
                        PaymentDate          = regObj.PaymentDate,
                        PaymentReference     = regObj.PaymentReference,
                        PaySource            = (PaySource)regObj.PaySource,
                        PaymentSourceName    = ((PaySource)regObj.PaySource).ToString().Replace("_", " "),
                        RegisteredBy         = regObj.AdminUserId,
                        TimeStampRegistered  = nowDateTime,
                        Status     = Status.Active,
                        AmountPaid = regObj.AmountPaid,
                        BeneficiaryAccountTransactionId = transactionAdded.BeneficiaryAccountTransactionId,
                    };

                    var paymentAdded = _repositiory.Add(newBeneficiaryPayment);
                    _uoWork.SaveChanges();
                    if (paymentAdded.BeneficiaryPaymentId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }
                    #endregion

                    #region Beneficiary Account Update

                    associatedBeneAccount.AvailableBalance      = transactionAdded.NewBalance;
                    associatedBeneAccount.CreditLimit           = 0;
                    associatedBeneAccount.LastTransactionAmount = transactionAdded.Amount;
                    associatedBeneAccount.LastTransactionType   = transactionAdded.TransactionType;
                    associatedBeneAccount.Status                   = Status.Active;
                    associatedBeneAccount.LastTransactionId        = transactionAdded.BeneficiaryAccountTransactionId;
                    associatedBeneAccount.LastTransactionTimeStamp = DateMap.CurrentTimeStamp();

                    var updateBeneAccount = _beneAccRepository.Update(associatedBeneAccount);
                    _uoWork.SaveChanges();
                    if (updateBeneAccount.BeneficiaryAccountId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }

                    #endregion

                    db.Commit();
                    response.Status.IsSuccessful            = true;
                    response.PaymentId                      = paymentAdded.BeneficiaryPaymentId;
                    response.Status.Message.FriendlyMessage = "Payment Successful";
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            return(response);
        }
        public BeneficiaryPaymentRespObj LoadBeneficiaryTransactionByDate(LoadBeneficiaryPaymentByDateObj regObj)
        {
            var response = new BeneficiaryPaymentRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisBeneficiaryPayment = GetBeneficiaryPayment(regObj.BeneficiaryId);
                if (!thisBeneficiaryPayment.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Beneficiary Payments  Information found!";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Payments  Information found!";
                    return(response);
                }

                var beneficiaryPaymentByDate = new List <BeneficiaryPaymentObj>();

                foreach (var m in thisBeneficiaryPayment)
                {
                    if (!string.IsNullOrWhiteSpace(regObj.BeginDate) || !string.IsNullOrWhiteSpace(regObj.EndDate))
                    {
                        var dateCreated = m.TimeStampRegistered;
                        var value       = dateCreated.IndexOf(' ');
                        if (value > 0)
                        {
                            dateCreated = dateCreated.Substring(0, value);
                        }
                        var realDate = DateTime.Parse(dateCreated);
                        if (realDate >= DateTime.Parse(regObj.BeginDate) && realDate <= DateTime.Parse(regObj.EndDate))
                        {
                            beneficiaryPaymentByDate.Add(new BeneficiaryPaymentObj
                            {
                                BeneficiaryId = m.BeneficiaryId,
                                BeneficiaryAccountTransactionId = m.BeneficiaryAccountTransactionId,
                                BeneficiaryAccountId            = m.BeneficiaryAccountId,
                                AmountPaid           = m.AmountPaid,
                                BeneficiaryPaymentId = m.BeneficiaryPaymentId,
                                PaymentDate          = m.PaymentDate,
                                PaymentReference     = m.PaymentReference,
                                Status              = (int)m.Status,
                                StatusLabel         = m.Status.ToString().Replace("_", " "),
                                PaymentSource       = (int)m.PaySource,
                                PaymentSourceName   = m.PaySource.ToString().Replace("_", " "),
                                RegisteredBy        = m.RegisteredBy,
                                TimeStampRegistered = m.TimeStampRegistered
                            });
                        }
                    }

                    else
                    {
                        beneficiaryPaymentByDate.Add(new BeneficiaryPaymentObj
                        {
                            BeneficiaryId = m.BeneficiaryId,
                            BeneficiaryAccountTransactionId = m.BeneficiaryAccountTransactionId,
                            BeneficiaryAccountId            = m.BeneficiaryAccountId,
                            AmountPaid           = m.AmountPaid,
                            BeneficiaryPaymentId = m.BeneficiaryPaymentId,
                            PaymentDate          = m.PaymentDate,
                            PaymentReference     = m.PaymentReference,
                            Status              = (int)m.Status,
                            StatusLabel         = m.Status.ToString().Replace("_", " "),
                            PaymentSource       = (int)m.PaySource,
                            PaymentSourceName   = m.PaySource.ToString().Replace("_", " "),
                            RegisteredBy        = m.RegisteredBy,
                            TimeStampRegistered = m.TimeStampRegistered
                        });
                    }
                }
                response.Status.IsSuccessful = true;
                response.BeneficiaryPayments = beneficiaryPaymentByDate;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(new BeneficiaryPaymentRespObj());
            }
        }
Example #17
0
        public SettingRegRespObj AddStaffMemo(RegStaffMemoObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getStaffRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var staffMemo = new StaffMemo
                {
                    StaffId           = regObj.StaffId,
                    Title             = regObj.Title,
                    MemoType          = (MemoType)regObj.MemoType,
                    MemoDetail        = regObj.MemoDetail,
                    IsReplied         = false,
                    RegisterBy        = regObj.AdminUserId,
                    ApprovedBy        = 0,
                    Status            = ApprovalStatus.Registered,
                    TimeStampRegister = DateMap.CurrentTimeStamp()
                };



                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.Add(staffMemo);
                        _uoWork.SaveChanges();
                        if (added.StaffMemoId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        workFlowSourceId = added.StaffMemoId;
                        var workflow = new WorkflowSetup
                        {
                            Description           = regObj.Title,
                            InitiatorId           = regObj.AdminUserId,
                            InitiatorType         = WorkflowInitiatorType.HR,
                            Item                  = WorkflowItem.Staff_Memo,
                            WorkflowOrderId       = regObj.WorkflowOrderId,
                            WorkflowSourceId      = workFlowSourceId,
                            LastTimeStampModified = DateMap.CurrentTimeStamp(),
                            StaffId               = regObj.StaffId,
                            TimeStampInitiated    = DateMap.CurrentTimeStamp(),
                            Status                = WorkflowStatus.Initiated
                        };

                        var retVal = _workflowSetupRepository.Add(workflow);
                        _uoWork.SaveChanges();
                        if (retVal.WorkflowSetupId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        response.Status.IsSuccessful = true;
                        response.SettingId           = added.StaffMemoId;
                        workflow.WorkflowSourceId    = added.StaffMemoId;
                        db.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    catch (Exception ex)
                    {
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    return(response);
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
        public CardDeliveryRegRespObj UpdateCardDelivery(EditCardDeliveryObj regObj)
        {
            var response = new CardDeliveryRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }
                var thisCardDelivery = GetCardDeliveryInfo(regObj.CardDeliveryId);
                if (thisCardDelivery == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }
                var associatedCard = GetCardInfo(regObj.CardId);
                if (associatedCard == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }

                var associatedCardItem = GetCardItemInfo(regObj.CardItemId);
                if (associatedCardItem == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card Item  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card Item Information Found";
                    return(response);
                }

                if (associatedCard.Status != CardStatus.Registered)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! This Card Item Is Not Available For Delivery";
                    response.Status.Message.TechnicalMessage = "Error Occurred! This Card Item Is Not Available For Delivery";
                    return(response);
                }

                //check validity of start/stop batch number

                if (regObj.DeliveredQuantity < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register An empty delivery ";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect quantity Delivered Data";
                    return(response);
                }

                if (DateTime.Parse(regObj.DeliveryDate) > DateTime.Now)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register A delivery before DeliveryDate";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect Delivery Date Data";
                    return(response);
                }

                using (var db = _uoWork.BeginTransaction())
                {
                    thisCardDelivery.DefectiveQuantity  = regObj.DefectiveQuantity > 0 ? regObj.DefectiveQuantity : thisCardDelivery.DefectiveQuantity;
                    thisCardDelivery.MissingQuantity    = regObj.MissingQuantity > 0 ? regObj.MissingQuantity : thisCardDelivery.MissingQuantity;
                    thisCardDelivery.DeliveredQuantity  = regObj.DeliveredQuantity > 0 ? regObj.DeliveredQuantity : thisCardDelivery.DeliveredQuantity;
                    thisCardDelivery.TimeStampDelivered = !string.IsNullOrWhiteSpace(regObj.DeliveryDate) ? regObj.DeliveryDate : thisCardDelivery.TimeStampDelivered;

                    var updateCardDelivery = _repository.Update(thisCardDelivery);
                    _uoWork.SaveChanges();
                    if (updateCardDelivery.CardDeliveryId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }
                    associatedCardItem.MissingQuantity   = regObj.MissingQuantity;
                    associatedCardItem.DefectiveQuantity = regObj.DefectiveQuantity;
                    associatedCardItem.DeliveredQuantity = regObj.DeliveredQuantity;
                    associatedCardItem.AvailableQuantity = regObj.DeliveredQuantity - (regObj.MissingQuantity + regObj.DefectiveQuantity);
                    associatedCardItem.DefectiveQuantity = regObj.DefectiveQuantity;

                    var updateCardItem = _cardItemRepository.Update(associatedCardItem);
                    _uoWork.SaveChanges();
                    if (updateCardItem.CardItemId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }

                    db.Commit();

                    response.Status.IsSuccessful            = true;
                    response.CardDeliveryId                 = updateCardDelivery.CardDeliveryId;
                    response.Status.Message.FriendlyMessage = "Card delivery Update Successfully";
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            return(response);
        }
Example #19
0
        public SettingRegRespObj ApproveStaffMemo(ApprovaStaffMemoObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }


                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getAdminRoles(), ref response.Status.Message))
                {
                    return(response);
                }


                //var searchObj = new StaffMemoSearchObj
                //{
                //    AdminUserId = 0,
                //    StaffMemoId = 0,
                //    StaffId = regObj.AdminUserId,
                //    Status = 0,
                //    SysPathCode = ""
                //};

                //retrieve previous contacts and validate with the new one
                var staffMemos = getStaffMemos(regObj.StaffId);

                if (staffMemos == null || !staffMemos.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Staff Memo Information found";
                    response.Status.Message.TechnicalMessage = "No Staff Memo Information found";
                    return(response);
                }
                var thisMemoFind         = staffMemos.Find(m => m.StaffMemoId == regObj.StaffMemoId);
                var staffWorkflowlog     = GetWorkflowLog(thisMemoFind.StaffId);
                var thisStaffWorkFlowLog = staffWorkflowlog.Find(m => m.StaffId == thisMemoFind.StaffId);
                if (thisMemoFind.StaffMemoId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "This Staff Memo Information not found";
                    response.Status.Message.TechnicalMessage = "This Staff Memo Request Information not found";
                    return(response);
                }
                if (thisStaffWorkFlowLog.StaffId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "This Staff Work flow Log  Information not found";
                    response.Status.Message.TechnicalMessage = "This Staff Work flow Log Information not found";
                    return(response);
                }


                thisMemoFind.MemoType   = (MemoType)regObj.MemoType;
                thisMemoFind.ApprovedBy = regObj.ApprovedBy;
                thisMemoFind.Status     = (ApprovalStatus)regObj.Status;

                thisStaffWorkFlowLog.WorkflowOrderItemId = regObj.WorkflowOrderItemId;
                thisStaffWorkFlowLog.ApprovalType        = WorkflowApprovalType.HR_Head;
                thisStaffWorkFlowLog.ProcessorId         = regObj.AdminUserId;
                thisStaffWorkFlowLog.Comment             = regObj.MemoDetail;
                thisStaffWorkFlowLog.LogTimeStamp        = DateMap.CurrentTimeStamp();
                thisStaffWorkFlowLog.Status = (ApprovalStatus)regObj.Status;

                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.Update(thisMemoFind);
                        _uoWork.SaveChanges();
                        if (added.StaffMemoId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }


                        var retVal = _workflowLogRepository.Update(thisStaffWorkFlowLog);
                        _uoWork.SaveChanges();
                        if (retVal.WorkflowLogId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        response.Status.IsSuccessful       = true;
                        response.SettingId                 = added.StaffMemoId;
                        thisStaffWorkFlowLog.WorkflowLogId = thisStaffWorkFlowLog.WorkflowLogId;
                        db.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        db.Rollback();
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    catch (Exception ex)
                    {
                        db.Rollback();
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
        public CardDeliveryRegRespObj AddCardDelivery(RegCardDeliveryObj regObj)
        {
            var response = new CardDeliveryRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var associatedCard = GetCardInfo(regObj.CardId);
                if (associatedCard == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }

                var associatedCardItem = GetCardItemInfo(regObj.CardItemId);
                if (associatedCardItem == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card Item  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card Item Information Found";
                    return(response);
                }

                if (associatedCard.Status != CardStatus.Registered)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! This Card Item Is Not Available For Delivery";
                    response.Status.Message.TechnicalMessage = "Error Occurred! This Card Item Is Not Available For Delivery";
                    return(response);
                }

                //check validity of start/stop batch number

                if ((int.Parse(regObj.StopBatchNumber) - int.Parse(regObj.StartBatchNumber) + 1) !=
                    associatedCard.QuantityPerBatch)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect StopBatchNumber/StartBatchNumber Data";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect StopBatchNumber/StartBatchNumber Data";
                    return(response);
                }

                if (regObj.BatchId != associatedCardItem.BatchId)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect BatchId";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect BatchId";
                    return(response);
                }
                if (regObj.DeliveredQuantity < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register An empty delivery ";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect quantity Delivered Data";
                    return(response);
                }

                if (regObj.DeliveredQuantity + associatedCardItem.DeliveredQuantity > associatedCardItem.BatchQuantity)
                {
                    if (associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity) > 0)
                    {
                        response.Status.Message.FriendlyMessage = $"Incorrect Quantity Delivered,{associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity)} is only available for delivery";
                    }
                    else if (associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity) == 0)
                    {
                        response.Status.Message.FriendlyMessage = $"This Delivery is Complete";
                    }

                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect Quantity Delivered";
                    return(response);
                }

                if (DateTime.Parse(regObj.TimeStampDelivered) > DateTime.Now)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register A delivery before DeliveryDate";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect Delivery Date Data";
                    return(response);
                }

                using (var db = _uoWork.BeginTransaction())
                {
                    var newCardDelivery = new CardDelivery
                    {
                        CardId             = regObj.CardId,
                        CardItemId         = regObj.CardItemId,
                        CardTypeId         = regObj.CardTypeId,
                        BatchId            = associatedCardItem.BatchId,
                        Status             = CardStatus.Registered,
                        ApprovedBy         = 0,
                        ApproverComment    = regObj.ApproverComment,
                        TimeStampApproved  = "",
                        DefectiveQuantity  = regObj.DefectiveQuantity,
                        TimeStampDelivered = regObj.TimeStampDelivered,
                        MissingQuantity    = regObj.MissingQuantity,
                        DeliveredQuantity  = regObj.DeliveredQuantity,
                        StartBatchNumber   = associatedCardItem.BatchId + "" + "000",
                        StopBatchNumber    = associatedCardItem.BatchId + "" + "999",
                        ReceivedBy         = regObj.AdminUserId,
                        TimeStampRegisered = DateMap.CurrentTimeStamp(),
                    };

                    var deliveryAdded = _repository.Add(newCardDelivery);
                    _uoWork.SaveChanges();
                    if (deliveryAdded.CardDeliveryId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }
                    associatedCardItem.MissingQuantity     += regObj.MissingQuantity;
                    associatedCardItem.DefectiveQuantity   += regObj.DefectiveQuantity;
                    associatedCardItem.DeliveredQuantity   += regObj.DeliveredQuantity;
                    associatedCardItem.AvailableQuantity   += regObj.DeliveredQuantity - (regObj.MissingQuantity + regObj.DefectiveQuantity);
                    associatedCardItem.TimeStampDelivered   = deliveryAdded.TimeStampRegisered;
                    associatedCardItem.DefectiveBatchNumber = regObj.DefectiveBatchNumber;
                    associatedCardItem.Status = CardStatus.Registered;

                    var updateCardItem = _cardItemRepository.Update(associatedCardItem);
                    _uoWork.SaveChanges();
                    if (updateCardItem.CardItemId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }


                    associatedCard.Status = CardStatus.Registered;
                    var updateCard = _cardRepository.Update(associatedCard);
                    _uoWork.SaveChanges();
                    if (updateCard.CardId < 1)
                    {
                        db.Rollback();
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                        response.Status.Message.TechnicalMessage = "Unable to save to database";
                        return(response);
                    }
                    db.Commit();

                    response.Status.IsSuccessful            = true;
                    response.CardDeliveryId                 = deliveryAdded.CardDeliveryId;
                    response.Status.Message.FriendlyMessage = "Card Delivery Added Successfully";
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }

            return(response);
        }
        public SettingRegRespObj UpdateCompany(EditCompanyObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCompany = getCompanyInfo(regObj.CompanyId);

                if (thisCompany == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Company Information found for the specified Company Id";
                    response.Status.Message.TechnicalMessage = "No Company Information found!";
                    return(response);
                }

                if (IsCompanyDuplicate(regObj.Name, 2, ref response))
                {
                    return(response);
                }
                thisCompany.Name = regObj.Name;
                thisCompany.BusinessDescription = regObj.BusinessDescription;
                thisCompany.Address             = regObj.Address;
                thisCompany.CompanyType         = (CompanyType)regObj.CompanyType;
                thisCompany.Email  = regObj.Email;
                thisCompany.Status = (ItemStatus)regObj.Status;
                var added = _repository.Update(thisCompany);
                _uoWork.SaveChanges();

                if (added.CompanyId < 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.CompanyId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
        public CardDeliveryRegRespObj ApproveCardDelivery(ApproveCardDeliveryObj regObj)
        {
            var response = new CardDeliveryRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getMgtExecutiveRoles(), ref response.Status.Message))
                {
                    return(response);
                }
                var thisCardDelivery = GetCardDeliveryInfo(regObj.CardDeliveryId);
                if (thisCardDelivery == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }
                var associatedCard = GetCardInfo(thisCardDelivery.CardId);
                if (associatedCard == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }

                var associatedCardItem = GetCardItemInfo(thisCardDelivery.CardItemId);
                if (associatedCardItem == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card Item  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card Item Information Found";
                    return(response);
                }

                if (regObj.IsApproved && regObj.IsDenied || regObj.IsApproved && regObj.IsDenied)
                {
                    response.Status.Message.FriendlyMessage  = "Sorry This CardDelivery Cannot be  Approved/Defected! Please Try Again Later";
                    response.Status.Message.TechnicalMessage = " IsApproved and IsDefected is both true/false";
                    return(response);
                }

                if (regObj.IsApproved)
                {
                    using (var db = _uoWork.BeginTransaction())
                    {
                        thisCardDelivery.ApprovedBy        = regObj.AdminUserId;
                        thisCardDelivery.TimeStampApproved = regObj.TimeStampApproved;
                        thisCardDelivery.ApproverComment   = regObj.ApproverComment;
                        thisCardDelivery.Status            = CardStatus.Available;

                        var updateDelivery = _repository.Update(thisCardDelivery);
                        _uoWork.SaveChanges();
                        if (updateDelivery.CardDeliveryId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }

                        associatedCardItem.Status = CardStatus.Available;

                        var updateCardItem = _cardItemRepository.Update(associatedCardItem);
                        _uoWork.SaveChanges();
                        if (updateDelivery.CardItemId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }

                        associatedCard.Status = CardStatus.Available;

                        var updateCard = _cardRepository.Update(associatedCard);
                        _uoWork.SaveChanges();
                        if (updateDelivery.CardId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        db.Commit();
                        response.Status.IsSuccessful            = true;
                        response.CardDeliveryId                 = updateDelivery.CardDeliveryId;
                        response.Status.Message.FriendlyMessage = "Card Delivery Approved Successfully";
                    }

                    if (regObj.IsDenied)
                    {
                        using (var db = _uoWork.BeginTransaction())
                        {
                            thisCardDelivery.ApprovedBy        = regObj.AdminUserId;
                            thisCardDelivery.TimeStampApproved = regObj.TimeStampApproved;
                            thisCardDelivery.ApproverComment   = regObj.ApproverComment;
                            thisCardDelivery.Status            = CardStatus.Unavalable;

                            var updateDelivery = _repository.Update(thisCardDelivery);
                            _uoWork.SaveChanges();
                            if (updateDelivery.CardDeliveryId < 1)
                            {
                                db.Rollback();
                                response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                                response.Status.Message.TechnicalMessage = "Unable to save to database";
                                return(response);
                            }

                            associatedCardItem.Status            = CardStatus.Unavalable;
                            associatedCardItem.AvailableQuantity = 0;

                            var updateCardItem = _cardItemRepository.Update(associatedCardItem);
                            _uoWork.SaveChanges();
                            if (updateDelivery.CardItemId < 1)
                            {
                                db.Rollback();
                                response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                                response.Status.Message.TechnicalMessage = "Unable to save to database";
                                return(response);
                            }

                            db.Commit();
                            response.Status.IsSuccessful            = true;
                            response.CardDeliveryId                 = updateDelivery.CardDeliveryId;
                            response.Status.Message.FriendlyMessage = "Defected Successfully";
                        }
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
        public CardCommissionRespObj LoadCardcommission(SettingSearchObj searchObj)
        {
            var response = new CardCommissionRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(searchObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode, new[] { "PortalAdmin", "CRMAdmin", "CRMManager" }, ref response.Status.Message))
                {
                    return(response);
                }

                var thisCardCommission = GetCardCommissions();
                if (!thisCardCommission.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Card Type Information found!";
                    response.Status.Message.TechnicalMessage = "No Card Type  Information found!";
                    return(response);
                }

                if (searchObj.Status > 1)
                {
                    thisCardCommission = thisCardCommission.FindAll(m => m.Status == (Status)searchObj.Status).ToList();
                }
                var thisCardCommissionItem = new List <CardCommissionItemObj>();

                thisCardCommission.ForEachx(m =>
                {
                    thisCardCommissionItem.Add(new CardCommissionItemObj
                    {
                        CardCommissionId = m.CardCommissionId,
                        CommissionRate   = m.CommissionRatee,
                        CardTypeId       = m.CardTypeId,
                        CardTypeName     = new CardCommissionRepository().GetCardTypeInfo(m.CardTypeId).Name,
                        LowerAmount      = m.LowerAmount,
                        UpperAmount      = m.UpperAmount,
                        Status           = (int)m.Status,
                        Statuslabel      = m.Status.ToString().Replace("_", "")
                    });
                });

                response.Status.IsSuccessful = true;
                response.CardCommissions     = thisCardCommissionItem;
                return(response);
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }
        public CardDeliveryRespObj LoadCardDeliveryByDate(LoadCardDeliveryByDate searchObj)
        {
            var response = new CardDeliveryRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(searchObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCardDelivery = GetCardDelivies(searchObj.CardId);
                if (!thisCardDelivery.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Card Delivery  Information found!";
                    response.Status.Message.TechnicalMessage = "No Card Delivery  Information found!";
                    return(response);
                }

                var CardDeliveryByDate = new List <CardDeliveryObj>();

                foreach (var m in thisCardDelivery)
                {
                    if (!string.IsNullOrWhiteSpace(searchObj.BeginDate) && !string.IsNullOrWhiteSpace(searchObj.EndDate))
                    {
                        var dateCreated = m.TimeStampRegisered;
                        var value       = dateCreated.IndexOf(' ');
                        if (value > 0)
                        {
                            dateCreated = dateCreated.Substring(0, value);
                        }
                        var realDate = DateTime.Parse(dateCreated);
                        if (realDate >= DateTime.Parse(searchObj.BeginDate) &&
                            realDate >= DateTime.Parse(searchObj.EndDate))
                        {
                            CardDeliveryByDate.Add(new CardDeliveryObj
                            {
                                CardDeliveryId      = m.CardDeliveryId,
                                CardId              = m.CardId,
                                CardIdLabel         = new CardRepository().GetCardInfo(m.CardId).CardTitle,
                                BatchId             = m.BatchId,
                                CardItemId          = m.CardItemId,
                                CardTypeId          = m.CardTypeId,
                                DeliveryDate        = m.TimeStampDelivered,
                                StartBatchNumber    = m.StartBatchNumber,
                                StopBatchNumber     = m.StopBatchNumber,
                                DefectiveQuantity   = m.DefectiveQuantity,
                                MissingQuantity     = m.MissingQuantity,
                                QuantityDelivered   = m.DeliveredQuantity,
                                RecievedBy          = m.ReceivedBy,
                                ApprovedBy          = m.ApprovedBy,
                                ApproverComment     = m.ApproverComment,
                                TimeStampRegistered = m.TimeStampRegisered,
                                Status              = (int)m.Status,
                                StatusLabel         = m.Status.ToString().Replace("_", " "),
                                TimeStampApproved   = m.TimeStampApproved
                            });
                        }
                    }

                    else
                    {
                        CardDeliveryByDate.Add(new CardDeliveryObj
                        {
                            CardDeliveryId      = m.CardDeliveryId,
                            CardId              = m.CardId,
                            CardIdLabel         = new CardRepository().GetCardInfo(m.CardId).CardTitle,
                            BatchId             = m.BatchId,
                            CardItemId          = m.CardItemId,
                            CardTypeId          = m.CardTypeId,
                            DeliveryDate        = m.TimeStampDelivered,
                            StartBatchNumber    = m.StartBatchNumber,
                            StopBatchNumber     = m.StopBatchNumber,
                            DefectiveQuantity   = m.DefectiveQuantity,
                            MissingQuantity     = m.MissingQuantity,
                            QuantityDelivered   = m.DeliveredQuantity,
                            RecievedBy          = m.ReceivedBy,
                            ApprovedBy          = m.ApprovedBy,
                            ApproverComment     = m.ApproverComment,
                            TimeStampRegistered = m.TimeStampRegisered,
                            Status              = (int)m.Status,
                            StatusLabel         = m.Status.ToString().Replace("_", " "),
                        });
                    }
                }

                response.Status.IsSuccessful = true;
                response.CardDeliveries      = CardDeliveryByDate;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(new CardDeliveryRespObj());
            }
        }
Example #25
0
        public SettingRegRespObj DeleteInstitution(DeleteInstitutionObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getStaffRoles(),
                                               ref response.Status.Message))
                {
                    return(response);
                }
                var thisInstitution = GetInstitutionInfo(regObj.InstitutionId);

                if (thisInstitution == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Institution Information found for the specified Institution Id";
                    response.Status.Message.TechnicalMessage = "No Institution Information found!";
                    return(response);
                }
                thisInstitution.Name =
                    thisInstitution.Name + "_Deleted_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
                thisInstitution.Status = ItemStatus.Deleted;
                var added = _repository.Update(thisInstitution);
                _uoWork.SaveChanges();

                if (added.InstitutionId < 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.InstitutionId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
Example #26
0
        public SettingsRegResponseObj DeleteCard(DeleteCardObj regObj)
        {
            var response = new SettingsRegResponseObj()
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCard = GetCardInfo(regObj.CardId);
                if (thisCard == null)
                {
                    response.Status.Message.FriendlyMessage  = "No Card Production Information found for the specified Card Id";
                    response.Status.Message.TechnicalMessage = "No Card Production Information found!";
                    return(response);
                }

                if (thisCard.Status != CardStatus.Registered)
                {
                    response.Status.Message.FriendlyMessage  = "Sorry This Card Production Is Not Valid For Delete! Please Try Again Later";
                    response.Status.Message.TechnicalMessage = " Supply Requisition Status is either already Active/Issued/Retired!";
                    return(response);
                }

                thisCard.CardTitle =
                    thisCard.CardTitle + "_Deleted_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
                thisCard.Status = CardStatus.Defective;

                var added = _repository.Update(thisCard);
                _uoWork.SaveChanges();
                if (added.CardId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }


                response.Status.IsSuccessful = true;
                response.SettingId           = added.CardId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
Example #27
0
        internal ResponseStatus UpdateOrganization(Organization organizationRegObj)
        {
            var response = new ResponseStatus
            {
                IsSuccessful = false,
                Message      = new ResponseMessage(),
                ReturnedId   = 0
            };

            try
            {
                #region Null Validation

                if (organizationRegObj.Equals(null))
                {
                    response.Message.FriendlyMessage = response.Message.TechnicalMessage = "Error Occurred! Unable to proceed with your registration";
                    return(response);
                }

                List <ValidationResult> valResults;
                if (!EntityValidatorHelper.Validate(organizationRegObj, 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.Message.FriendlyMessage = response.Message.TechnicalMessage = errorDetail.ToString();
                    return(response);
                }

                #endregion

                #region Get This Organization
                var thisOrganization = GetOrganization(organizationRegObj.OrganizationId);
                if (thisOrganization == null || thisOrganization.OrganizationId < 1)
                {
                    response.Message.FriendlyMessage = response.Message.TechnicalMessage = "Invalid Organization Information";
                    return(response);
                }
                #endregion

                string msg;
                if (IsDuplicate2(organizationRegObj, out msg, 1))
                {
                    response.Message.FriendlyMessage = response.Message.TechnicalMessage = msg;
                    return(response);
                }

                thisOrganization.Name        = organizationRegObj.Name;
                thisOrganization.Email       = organizationRegObj.Email;
                thisOrganization.Address     = organizationRegObj.Address;
                thisOrganization.PhoneNumber = organizationRegObj.PhoneNumber;
                thisOrganization.Status      = organizationRegObj.Status;

                var processedOrganization = _repository.Update(thisOrganization);
                _uoWork.SaveChanges();
                if (processedOrganization.OrganizationId < 1)
                {
                    response.Message.FriendlyMessage = response.Message.TechnicalMessage = "Process Failed! Please try again later";
                    return(response);
                }

                response.IsSuccessful = true;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message.FriendlyMessage =
                    "Unable to complete your request due to error! Please try again later";
                response.Message.TechnicalMessage = "Error" + ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(response);
            }
        }
        public StationRespObj RemoteLogin(RemoteStationLoginObj loginObj)
        {
            var response = new StationRespObj
            {
                ResponseStatus = new ResponseStatus
                {
                    Message      = new ResponseMessage(),
                    IsSuccessful = false,
                }
            };

            try
            {
                #region Null Validation

                List <ValidationResult> valResults;
                if (!EntityValidatorHelper.Validate(loginObj, 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.ResponseStatus.Message.FriendlyMessage = response.ResponseStatus.Message.TechnicalMessage = errorDetail.ToString();
                    return(response);
                }

                #endregion

                string msg;
                var    enroller = LoginEnroller(loginObj.UserName, loginObj.Password, out msg);
                if (enroller == null || string.IsNullOrEmpty(enroller.EnrollerRegId) || enroller.EnrollerId < 1)
                {
                    response.ResponseStatus.Message.FriendlyMessage = response.ResponseStatus.Message.TechnicalMessage = "Invalid Station Operator Info";
                    return(response);
                }

                var station = new ClientStationRepository().GetStation(enroller.ClientStationId);
                if (station == null || station.ClientStationId < 1)
                {
                    response.ResponseStatus.Message.FriendlyMessage = response.ResponseStatus.Message.TechnicalMessage = "Invalid Station Info";
                    return(response);
                }

                enroller.DeviceId            = loginObj.DeviceId;
                enroller.DeviceIP            = loginObj.DeviceIP;
                enroller.Status              = 2;
                enroller.TimeStampAuthorized = DateTime.Now;
                var processedClientStationEnroller = _repository.Update(enroller);
                _uoWork.SaveChanges();

                if (processedClientStationEnroller.EnrollerId < 1)
                {
                    response.ResponseStatus.Message.FriendlyMessage = response.ResponseStatus.Message.TechnicalMessage = "Process Failed! Unable to process operator authorize information";
                    return(response);
                }

                response.ResponseStatus.IsSuccessful = true;
                response.APIAccessKey       = station.APIAccessKey;
                response.ClientStationId    = enroller.ClientStationId;
                response.ResidentialAddress = enroller.Address;
                response.Surname            = enroller.Surname;
                response.FirstName          = enroller.FirstName;
                response.Othernames         = enroller.OtherNames;
                response.Sex          = enroller.Sex;
                response.Email        = enroller.Email;
                response.MobileNumber = enroller.MobileNumber;
                //response.OrganizationId = enroller.OrganizationId;
                response.EnrollerRegId = enroller.EnrollerRegId;
                response.EnrollerId    = enroller.EnrollerId;
                response.StationId     = station.StationId;
                response.StationName   = station.StationName;
                //response.UserName = corporateInfo.UserName;
                response.ResponseStatus.ReturnedId   = enroller.EnrollerId;
                response.ResponseStatus.IsSuccessful = true;
                response.StationStatus  = station.Status;
                response.EnrollerStatus = enroller.Status;
                //response.ResponseStatus.ReturnedValue = retId;
                //response.DeviceId = station.DeviceId;
                return(response);
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Message.FriendlyMessage  = "Processing Error Occurred! Please try again later " + ex.Message;
                response.ResponseStatus.Message.TechnicalMessage = ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(response);
            }
        }
        public SettingRegRespObj AddJobLevel(RegJobLevelObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                if (IsJobLevelDuplicate(regObj.Name, 1, ref response))
                {
                    return(response);
                }

                var jobLevel = new JobLevel
                {
                    Name   = regObj.Name,
                    Status = (ItemStatus)regObj.Status
                };

                var added = _repository.Add(jobLevel);

                _uoWork.SaveChanges();

                if (added.JobLevelId < 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Error Occurred! Unable to complete your request. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.JobLevelId;
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
Example #30
0
        public CardRespObj LoadCards(SettingSearchObj searchObj)
        {
            var response = new CardRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (searchObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(searchObj, out var 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.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCard = GetCards(searchObj);
                if (!thisCard.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Card Production Information found!";
                    response.Status.Message.TechnicalMessage = "No Card Production  Information found!";
                    return(response);
                }

                var cards = new List <CardObj>();
                foreach (var m in thisCard)
                {
                    var cardItem = new List <CardItemObj>();

                    var CardItemList = getCardItems(m.CardId);
                    if (!CardItemList.Any())
                    {
                        response.Status.Message.FriendlyMessage  = "No Card Item Production Information found!";
                        response.Status.Message.TechnicalMessage = "No Card Item Production  Information found!";
                        return(response);
                    }

                    foreach (var item in CardItemList)
                    {
                        cardItem.Add(new CardItemObj
                        {
                            CardItemId            = item.CardItemId,
                            CardId                = item.CardId,
                            CardTypeId            = item.CardTypeId,
                            BatchId               = item.BatchId,
                            BatchStartNumber      = item.StartBatchNumber,
                            BatchStopNumber       = item.StopBatchNumber,
                            AvailableQuantity     = item.AvailableQuantity,
                            BatchQuantity         = item.BatchQuantity,
                            DefectiveBatchNumbers = item.DefectiveBatchNumber,
                            DefectiveQuantity     = item.DefectiveQuantity,
                            DeliveredQuantity     = item.DeliveredQuantity,
                            IssuedQuantity        = item.IssuedQuantity,
                            MissingQuantity       = item.MissingQuantity,
                            RegisteredBy          = item.RegisteredBy,
                            Status                = (int)item.Status,
                            StatusLabel           = item.Status.ToString().Replace("_", " "),
                            TimeStampDelivered    = item.TimeStampDelivered,
                            TimeStampIssued       = item.TimeStampLastIssued,
                            TimeStampRegistered   = item.TimeStampRegisered
                        });
                    }

                    cards.Add(new CardObj()
                    {
                        CardId              = m.CardId,
                        CardTypeId          = m.CardTypeId,
                        CardTitle           = m.CardTitle,
                        BatchKey            = m.BatchKey,
                        StartBatchId        = m.StartBatchId,
                        StopBatchId         = m.StopBatchId,
                        NoOfBatches         = m.NumberOfBatches,
                        QuantityPerBatch    = m.QuantityPerBatch,
                        TotalQuantity       = m.TotalQuantity,
                        TimeStampRegistered = m.TimeStampRegisered,
                        Status              = (int)m.Status,
                        StatusLabel         = m.Status.ToString().Replace("_", " "),
                        CardItems           = cardItem
                    });
                }

                response.Status.IsSuccessful = true;
                response.Cards = cards;
                return(response);
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
        }