コード例 #1
0
        public ActionResult DoDelete(int id)
        {
            AjaxResponse r = new AjaxResponse();

            try
            {
                var p = _productRepository.GetById(id);
                if (p == null)
                {
                    throw new Exception("Product does not exist!");
                }

                _productRepository.Delete(p);
                _productRepository.SubmitChanges();

                r.Status = true;
                r.Message = "Product is deleted";
            }
            catch (Exception ex)
            {
                Error("Error deleting product #" + id, ex);
                r.Message = ex.Message;
            }

            return Json(r);
        }
コード例 #2
0
        public ActionResult DoDecorate(int id)
        {
            AjaxResponse r = new AjaxResponse();

            try
            {
                if (String.IsNullOrEmpty(Request["bg"]))
                {
                    throw new ArgumentNullException("Background color is not specified");
                }
                //var p = _productRepository.GetById(id);
                //if (p == null)
                //{
                //    throw new ArgumentNullException("Product does not exist. ID: " + id);
                //}
                var pd = _productRepository.GetDetailsById(id);
                if (pd == null)
                {
                    throw new ArgumentNullException("Details does not exist for Product ID: " + id);
                }

                var decorator = new ProductDecoratorColor();
                decorator.BackgroundColor = HttpUtility.HtmlEncode(Request["bg"].Trim());
                decorator.Color = "#000";
                decorator.Remarks = "";
                decorator.ProductId = pd.ProductId;
                decorator.SizeName = pd.ParameterValue;

                pd.DataJson = Newtonsoft.Json.JsonConvert.SerializeObject(decorator);
                _productRepository.Update(pd);
                _productRepository.SubmitChanges();

                r.Status = true;
                r.Message = "Product details are decorated";
            }
            catch (Exception ex)
            {
                r.Message = "Error decorating product";
                if (Request.IsLocal)
                {
                    r.Message = string.Concat(r.Message, Environment.NewLine, ex.ToString());
                }
            }

            return Json(r);
        }