Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i am using angularjs and webapi. in the entering fields i have one dropdown for channels, one text for from amount one, another dropdown for conditions(<=,>=), one text box for to amount, one more text box for fee amount. The scenario is when i select one channel and enterin from value and to value and fee amount its storing database. if i enter another from amount and to amount for same channel id, the from amount should next value of previous entered to amount. and also from amount always greater than to amount. i want angularjs validations for each channel for above scenario. Please help me out. I tried for the below code but its not working properly.

What I have tried:

JavaScript
$scope.SaveFixedFee = function () {

            $scope.validate = false;
            if ($scope.AddFixedfeeForm.$valid) {
                angular.forEach($scope.lsteComfixedfeelist, function (value, key) {
                    if (value.ChannelId == $scope.channelid) {
                        if (value.Condition.indexOf("=") != -1) {


                            if (($scope.frmamt >= value.FromAmount && $scope.frmamt <= value.ToAmount) || ($scope.toamt >= value.FromAmount && $scope.toamt <= value.ToAmount)) {
                                alert("Please check the from and to amount");
                                $scope.validate = true;
                            }
                        }
                        else {
                            if (($scope.frmamt > value.FromAmount && $scope.frmamt < value.ToAmount) || ($scope.toamt > value.FromAmount && $scope.toamt <= value.ToAmount)) {
                                alert("Please check the from and to amount");
                                $scope.validate = true;
                            }                        }
                        if (value.Condition.indexOf(">") != -1) {
                            if ((parseInt($scope.frmamt) - 1) != parseInt(value.ToAmount)) {
                                $scope.validate1 = true;
                            }
                        }
                        else {
                            if (parseInt($scope.frmamt) != parseInt(value.ToAmount)) {
                                $scope.validate2 = true;
                            }
                        }
                    }
                })
                if ($scope.validate) {
                    alert("false");
                    return false;
                }
                if ($scope.validate1) {
                    alert("false1");
                    return false;
                }
                if ($scope.validate2) {
                    alert("false2");
                    return false;
                }
                if ((parseInt($scope.frmamt) > parseInt($scope.toamt)) || (parseInt($scope.frmamt) >= parseInt($scope.toamt))) {

                    alert("from amount should less than the to amount");
                    return false;
                }


                //if ($scope.validate()) {
                //    return false;
                //}
                var Requestboy = {
                    'ChannelId': $scope.channelid,
                    'FromAmount': $scope.frmamt,
                    'ToAmount': $scope.toamt,
                    'FixedFee': $scope.feeamt,
                    'Condition': $scope.condition,
                    'CreatedBy': $scope.LoginRoleId

                }

                $http.post(serviceBasePath + '/api/Product/addFixedFee', Requestboy).then(function (response) {
                    if (response.data.indexOf("Successfully") != -1) {
                        alert("Successfully Updated");
                        $state.reload();
                    }
                    else {
                        alert(response.data);
                        return false;
                    }

                }, function (error) {
                    alert("Something Went Wrong");
                    return false;
                })
            }


        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900