コード例 #1
0
        public long UpdateProductColumn(ProductColumnObject productColumn)
        {
            try
            {
                if (productColumn == null)
                {
                    return(-2);
                }


                using (var db = new ImportPermitEntities())
                {
                    if (db.ProductColumns.Count(k => k.CustomCodeId == productColumn.CustomCodeId && k.ProductId == productColumn.ProductId && k.ProductColumnId != productColumn.ProductColumnId) > 0)
                    {
                        return(-3);
                    }
                    var productColumnEntity = ModelMapper.Map <ProductColumnObject, ProductColumn>(productColumn);
                    if (productColumnEntity == null || productColumnEntity.ProductColumnId < 1)
                    {
                        return(-2);
                    }
                    db.ProductColumns.Attach(productColumnEntity);
                    db.Entry(productColumnEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(productColumn.ProductColumnId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #2
0
        private GenericValidator ValidateProductColumn(ProductColumnObject productColumn)
        {
            var gVal = new GenericValidator();

            try
            {
                if (productColumn.ProductId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select a Product.";
                    return(gVal);
                }

                if (productColumn.CustomCodeId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select Custom Code.";
                    return(gVal);
                }

                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Product Added Requirement Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
コード例 #3
0
        public ActionResult EditProductColumn(ProductColumnObject productColumn)
        {
            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 = ValidateProductColumn(productColumn);

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

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

                var oldproductColumn = Session["_productColumn"] as ProductColumnObject;

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

                oldproductColumn.CustomCodeId = productColumn.CustomCodeId;
                oldproductColumn.ProductId    = productColumn.ProductId;
                var docStatus = new ProductColumnServices().UpdateProductColumn(oldproductColumn);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Product Added Requirement already exists." : "Product Added Requirement could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldproductColumn.ProductColumnId;
                gVal.Error = "Product Added Requirement information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Product Added Requirement could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
 public long UpdateProductColumn(ProductColumnObject productColumn)
 {
     try
     {
         return(_productColumnManager.UpdateProductColumn(productColumn));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #5
0
        public ActionResult AddProductColumn(ProductColumnObject productColumn)
        {
            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 validationResult = ValidateProductColumn(productColumn);

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

                var appStatus = new ProductColumnServices().AddProductColumn(productColumn);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "Product Added Requirement could not be processed failed. Please try again." : "The Product Added Requirement already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Product Added Requirement was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Product Added Requirement processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }