예제 #1
0
        public ActionResult Get()
        {
            if (objAutorized.ValidateTokenResult == null)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid access."
                }));
            }
            if (objAutorized.ValidateTokenResult.isValid == false)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = objAutorized.ValidateTokenResult.error_message
                }));
            }

            ProductDBAccess     obj         = ProductDBAccess.getInstance;
            List <ProductTable> objListData = obj.GetALLProduct();

            return(Ok(
                       new ProductResponse.SelectData()
            {
                data = objListData,
                error_code = Convert.ToInt32(ErrorCode.Success),
                message = "Product data found."
            }
                       ));
        }
예제 #2
0
        public ActionResult Delete(int ProductId)
        {
            try
            {
                if (objAutorized.ValidateTokenResult == null)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid access."
                    }));
                }
                if (objAutorized.ValidateTokenResult.isValid == false)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objAutorized.ValidateTokenResult.error_message
                    }));
                }
                if (ProductId < 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid product id."
                    }));
                }

                ProductDBAccess obj = ProductDBAccess.getInstance;
                List <ProductResponse.DeleteData> objListData = obj.DeleteProduct(ProductId);
                if (objListData.Count == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "No data found."
                    }));
                }

                if (objListData[0].RowEffect == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objListData[0].message
                    }));
                }

                return(Ok(new ProductResponse.DeleteData()
                {
                    error_code = Convert.ToInt32(ErrorCode.Success),
                    message = objListData[0].message,
                    RowEffect = objListData[0].RowEffect
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = ex.Message
                }));
            }
        }
예제 #3
0
 public ActionResult Get(int id)
 {
     try
     {
         if (objAutorized.ValidateTokenResult == null)
         {
             return(Ok(new CommonResponse()
             {
                 error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid access."
             }));
         }
         if (objAutorized.ValidateTokenResult.isValid == false)
         {
             return(Ok(new CommonResponse()
             {
                 error_code = Convert.ToInt32(ErrorCode.Failure), message = objAutorized.ValidateTokenResult.error_message
             }));
         }
         ProductDBAccess     obj         = ProductDBAccess.getInstance;
         List <ProductTable> objListData = obj.GetProductById(id);
         if (objListData.Count == 0)
         {
             return(Ok(new CommonResponse()
             {
                 error_code = Convert.ToInt32(ErrorCode.Failure), message = "Product not found."
             }));
         }
         return(Ok(
                    new ProductResponse.SelectData()
         {
             data = objListData,
             error_code = Convert.ToInt32(ErrorCode.Success),
             message = "Product data found."
         }
                    ));
     }
     catch (Exception ex)
     {
         return(Ok(new CommonResponse()
         {
             error_code = Convert.ToInt32(ErrorCode.Failure), message = ex.Message
         }));
     }
 }
예제 #4
0
        public ActionResult Put(ProductUpdateParam objProductUpdateParam)
        {
            try
            {
                if (objAutorized.ValidateTokenResult == null)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid access."
                    }));
                }
                if (objAutorized.ValidateTokenResult.isValid == false)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objAutorized.ValidateTokenResult.error_message
                    }));
                }
                ProductTable objProduct = new ProductTable();
                objProduct.ProductId       = objProductUpdateParam.ProductId;
                objProduct.ProdCatId       = objProductUpdateParam.ProdCatId;
                objProduct.ProdName        = objProductUpdateParam.ProdName;
                objProduct.ProdDescription = objProductUpdateParam.ProdDescription;
                ValidationContext vc    = new ValidationContext(objProduct);
                var  validationsResults = new List <ValidationResult>();
                bool correct            = Validator.TryValidateObject(objProduct, vc, validationsResults, true);
                if (!correct)
                {
                    string errorMessage = "";
                    foreach (var item in validationsResults.Select(ov => ov.ErrorMessage))
                    {
                        errorMessage = string.Concat(errorMessage, item);
                    }
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = errorMessage
                    }));
                }
                ProductDBAccess obj = ProductDBAccess.getInstance;
                List <ProductResponse.UpdateData> objListData = obj.UpdateProduct(objProduct);
                if (objListData.Count == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "No data update."
                    }));
                }

                if (objListData[0].RowEffect == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objListData[0].message
                    }));
                }

                return(Ok(new ProductResponse.UpdateData()
                {
                    error_code = Convert.ToInt32(ErrorCode.Success),
                    message = objListData[0].message,
                    RowEffect = objListData[0].RowEffect
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = ex.Message
                }));
            }
        }
예제 #5
0
 public clsProduct()
 {
     productDb = new ProductDBAccess();
 }