public ActionResult GetAllCommissionData()
        {
            var context  = new CommissionEntities();
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var commissionData = context.CARS_CPR_COMMISSION_TAB.ToList();
            var response       = new Models.Response();

            if (commissionData == null)
            {
                //Used to make property name as camel case

                /*Microsoft.Data.OData.ODataError error = new Microsoft.Data.OData.ODataError()
                 * {
                 *  ErrorCode = "404",
                 *  Message = "Customer Not Fount"
                 * }
                 * return JsonConvert.SerializeObject(error, Formatting.None, settings);*///Returns students list as JSON
                response = new Models.Response()
                {
                    Success            = false,
                    JSON_RESPONSE_DATA = null,
                    Message            = "Customer Number provided yeilds no result."
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }

            var commissionDatalist = new List <Models.CommissionData>();

            foreach (var entry in commissionData)
            {
                var row = new Models.CommissionData()
                {
                    COMMISSION_ID    = entry.COMMISSION_ID,
                    CUSTOMER_NO      = entry.CUSTOMER_NO,
                    OUTSIDE_REP_NAME = entry.CARS_CPR_OUTSIDE_REP_TAB.OUTSIDE_REP,
                    REP_ID           = entry.REP_ID,
                    COMMISSION       = entry.COMMISSION
                };
                commissionDatalist.Add(row);
            }



            response = new Models.Response()
            {
                Success            = true,
                JSON_RESPONSE_DATA = JsonConvert.SerializeObject(commissionDatalist)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
            };
            return(this.Json(response, JsonRequestBehavior.AllowGet));
            //return JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings); //Returns students list as JSON
        }
        public ActionResult Save(Models.Request.Commission.Save saveModel)
        {
            var context  = new CommissionEntities();
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var response = new Models.Response();
            CARS_CPR_COMMISSION_TAB commissionEntry = null;

            Models.CommissionData commissionDataResponseObject = null;
            string repName = null;

            /*
             * Do checks here making sure input is as expectied
             */
            if (saveModel.COMMISSION_ID != null)
            {
                commissionEntry = context.CARS_CPR_COMMISSION_TAB.Where(x => x.COMMISSION_ID == saveModel.COMMISSION_ID).FirstOrDefault();
                if (commissionEntry == null)
                {
                    response = new Models.Response()
                    {
                        Success            = false,
                        JSON_RESPONSE_DATA = null, //JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                        Message            = "Data to edit does not exist."
                    };
                    return(this.Json(response, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    commissionEntry.COMMISSION = (decimal)saveModel.commission;
                    context.SaveChanges();

                    repName = context.CARS_CPR_OUTSIDE_REP_TAB.Where(x => x.REP_ID == commissionEntry.REP_ID).Select(x => x.OUTSIDE_REP).FirstOrDefault();
                    commissionDataResponseObject = new Models.CommissionData()
                    {
                        COMMISSION_ID    = commissionEntry.COMMISSION_ID,
                        CUSTOMER_NO      = commissionEntry.CUSTOMER_NO,
                        OUTSIDE_REP_NAME = repName, //here goest he actuat name after you retrieve it from db
                        REP_ID           = commissionEntry.REP_ID,
                        COMMISSION       = commissionEntry.COMMISSION
                    };
                    response = new Models.Response()
                    {
                        Success            = true,
                        JSON_RESPONSE_DATA = JsonConvert.SerializeObject(commissionDataResponseObject)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                    };
                    return(this.Json(response, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                commissionEntry = new CARS_CPR_COMMISSION_TAB()
                {
                    CUSTOMER_NO = saveModel.customerNumber,
                    REP_ID      = (decimal)saveModel.representativeId,
                    COMMISSION  = (decimal)saveModel.commission
                };

                context.CARS_CPR_COMMISSION_TAB.Add(commissionEntry);
                context.SaveChanges();

                commissionEntry.COMMISSION_ID = context.CARS_CPR_COMMISSION_TAB.Where(x => x.CUSTOMER_NO == commissionEntry.CUSTOMER_NO &&
                                                                                      x.REP_ID == commissionEntry.REP_ID && x.COMMISSION == commissionEntry.COMMISSION).Select(x => x.COMMISSION_ID).FirstOrDefault();

                repName = context.CARS_CPR_OUTSIDE_REP_TAB.Where(x => x.REP_ID == commissionEntry.REP_ID).Select(x => x.OUTSIDE_REP).FirstOrDefault();
                commissionDataResponseObject = new Models.CommissionData()
                {
                    COMMISSION_ID    = commissionEntry.COMMISSION_ID,
                    CUSTOMER_NO      = commissionEntry.CUSTOMER_NO,
                    OUTSIDE_REP_NAME = repName, //here goest he actuat name after you retrieve it from db
                    REP_ID           = commissionEntry.REP_ID,
                    COMMISSION       = commissionEntry.COMMISSION
                };


                response = new Models.Response()
                {
                    Success            = true,
                    JSON_RESPONSE_DATA = JsonConvert.SerializeObject(commissionDataResponseObject)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }


            //return JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings); //Returns students list as JSON
        }