public ActionResult DeleteProductColour(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                var delStatus = new ProductColourServices().DeleteProductColour(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "ProductColour could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "ProductColour Information was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult EditProductColour(ProductColourObject productColour)
        {
            var gVal = new GenericValidator();

            try
            {
                if (!ModelState.IsValid)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Plese provide all required fields and try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var stat = ValidateProductColour(productColour);

                if (stat.Code < 1)
                {
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_productColour"] == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var oldproductColour = Session["_productColour"] as ProductColourObject;

                if (oldproductColour == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                oldproductColour.Name = productColour.Name.Trim();
                //oldproductColour.CountryCode = productColour.CountryCode;
                var docStatus = new ProductColourServices().UpdateProductColour(oldproductColour);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "ProductColour already exists." : "ProductColour information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldproductColour.Id;
                gVal.Error = "ProductColour information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "ProductColour information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult GetProductColourObjects(JQueryDataTableParamModel param)
        {
            try
            {
                IEnumerable <ProductColourObject> filteredParentMenuObjects;
                int countG;

                var pagedParentMenuObjects = GetProductColours(param.iDisplayLength, param.iDisplayStart, out countG);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredParentMenuObjects = new ProductColourServices().Search(param.sSearch);
                }
                else
                {
                    filteredParentMenuObjects = pagedParentMenuObjects;
                }

                if (!filteredParentMenuObjects.Any())
                {
                    return(Json(new List <ProductColourObject>(), JsonRequestBehavior.AllowGet));
                }

                //var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <ProductColourObject, string> orderingFunction = (c => c.Name);

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredParentMenuObjects = sortDirection == "asc" ? filteredParentMenuObjects.OrderBy(orderingFunction) : filteredParentMenuObjects.OrderByDescending(orderingFunction);

                var displayedPersonnels = filteredParentMenuObjects;

                var result = from c in displayedPersonnels
                             select new[] { Convert.ToString(c.Id), c.Name };
                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = filteredParentMenuObjects.Count(),
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <ProductColourObject>(), JsonRequestBehavior.AllowGet));
            }
        }
        public List <ProductColourObject> GetProductColours()
        {
            try
            {
                var productColour = new ProductColourServices().GetProductColours();


                Session["_productColour"] = productColour;

                return(new List <ProductColourObject>());
            }
            catch (Exception)
            {
                return(new List <ProductColourObject>());
            }
        }
        public ActionResult AddProductColour(ProductColourObject productColour)
        {
            var gVal = new GenericValidator();

            try
            {
                if (!ModelState.IsValid)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Plese provide all required fields and try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var importerInfo = GetLoggedOnUserInfo();
                if (importerInfo.Id < 1)
                {
                    gVal.Error = "Your session has timed out";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var validationResult = ValidateProductColour(productColour);

                if (validationResult.Code == 1)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var appStatus = new ProductColourServices().AddProductColour(productColour);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "ProductColour upload failed. Please try again." : "The ProductColour Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "ProductColour was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "ProductColour processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult GetProductColour(long id)
        {
            try
            {
                var productColour = new ProductColourServices().GetProductColour(id);
                if (productColour == null || productColour.Id < 1)
                {
                    return(Json(new ProductColourObject(), JsonRequestBehavior.AllowGet));
                }

                Session["_productColour"] = productColour;

                return(Json(productColour, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new ProductColourObject(), JsonRequestBehavior.AllowGet));
            }
        }