private List <BeneficiaryPayment> GetBeneficiaryPayment(SettingSearchObj searchObj)
        {
            try
            {
                if (searchObj.Status == -2)
                {
                    var sql = new StringBuilder();
                    sql.Append($"SELECT * FROM \"NewVPlusSales\".\"BeneficiaryPayment\"");

                    var agentInfo = _repositiory.RepositoryContext().Database
                                    .SqlQuery <BeneficiaryPayment>(sql.ToString()).ToList();
                    return(!agentInfo.Any() ? new List <BeneficiaryPayment>() : agentInfo);
                }

                else
                {
                    var sql2 = new StringBuilder();
                    sql2.Append($"SELECT * FROM \"NewVPlusSales\".\"BeneficiaryPayment\" WHERE \"Status\" = {searchObj.Status}");

                    var agentInfo = _repositiory.RepositoryContext().Database
                                    .SqlQuery <BeneficiaryPayment>(sql2.ToString()).ToList();
                    return(!agentInfo.Any() ? new List <BeneficiaryPayment>() : agentInfo);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(new List <BeneficiaryPayment>());
            }
        }
        private List <Card> GetCards(SettingSearchObj searchObj)
        {
            try
            {
                var sql = new StringBuilder();
                if (searchObj.Status == -2)
                {
                    sql.Append(
                        $"SELECT * FROM \"NewVPlusSale\".\"Card\" WHERE \"Status\" != {(int)CardStatus.Defective} AND \"Status\" !={(int)CardStatus.Deleted} ");
                }
                else
                {
                    sql.Append(
                        $"SELECT * FROM \"NewVPlusSale\".\"Card\" WHERE \"Status\" != {searchObj.Status} ");
                }

                var agentInfo = _repository.RepositoryContext().Database.SqlQuery <Card>(sql.ToString()).ToList();

                return(!agentInfo.Any() ? new List <Card>() : agentInfo);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(new List <Card>());
            }
        }
        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 StaffRoleRespObj LoadStaffRole(SettingSearchObj searchObj)
        {
            var response = new StaffRoleRespObj
            {
                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 thisRoles = GetRoles();
                if (!thisRoles.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Role Information found!";
                    response.Status.Message.TechnicalMessage = "No Role  Information found!";
                    return(response);
                }

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

                var roleItems = new List <StaffRoleObj>();
                thisRoles.ForEachx(m =>
                {
                    roleItems.Add(new StaffRoleObj
                    {
                        StaffRoleId = m.StaffRoleId,
                        Name        = m.Name,
                        Status      = (int)m.Status,
                        StatusLabel = m.Status.ToString().Replace("_", " ")
                    });
                });

                response.Status.IsSuccessful = true;
                response.StaffRoles          = roleItems;
                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);
            }
        }
Beispiel #5
0
 public static StaffRoleRespObj LoadStaffRoles(SettingSearchObj regObj)
 {
     return(new StaffRoleRepository().LoadStaffRole(regObj));
 }
        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);
            }
        }