コード例 #1
0
        public ActionResult Add(ProductModel model)
        {
            if (ModelState.IsValid)
            {
                string fileName = "";
                if (model.Image != null)
                {
                    fileName           = DateTime.Now.ToFileTime() + Path.GetExtension(model.Image.FileName);
                    model.ProductImage = "~/UploadFiles/Products/" + fileName;
                }

                int result = model.Add(model);

                if (result > 0)
                {
                    if (model.Image != null)
                    {
                        model.Image.SaveAs(Server.MapPath(model.ProductImage));
                    }

                    return(RedirectToAction("Index"));
                }
            }

            model.BrandList = new BrandModel().GetList();
            return(View(model));
        }
コード例 #2
0
 public ActionResult Add(ProductModel model)
 {
     if (ModelState.IsValid)
     {
         model.Add();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
コード例 #3
0
        protected override string Add(string input)
        {
            logger.Info($"Attempt to add Product({input})...");
            string[] parameters = input.Split('|');
            Product  result     = model.Add(parameters[1],
                                            int.Parse(parameters[0]),
                                            int.Parse(parameters[2]),
                                            int.Parse(parameters[3]),
                                            int.Parse(parameters[4]));

            logger.Info($"Product({input}) was created successfully.");
            var table = CreateTable();

            AddRow(table, result);
            return(Globalization.UIGlobalization.ObjectAddAlert + "\n" + table.ToString());
        }
コード例 #4
0
        private void AddProduct()
        {
            if (!ValidateInputFields())
            {
                RaiseNotification("Alert", "Please enter all the required fields");
                return;
            }
            var product = new Product();

            try
            {
                product.ProductName       = ProductName;
                product.ProductSearchId   = Convert.ToInt32(ProductSearchId);
                product.ProductUoM        = SelectedUOM;
                product.ProductCategoryId = SelectedTaxRate;
                //product.PriceList = new List<Price>()
                //{ new Price() { SellingPrice = Convert.ToDouble(this.SellingPrice) } };
                product.ProductDescription = ProductDescription;
                var taxRate = new Tax()
                {
                    TaxId = SelectedTaxRate
                };
                product.ProductTax = taxRate;
                _productModel.Add(product);
                log.Info(String.Format("New product {0} added successfully", ProductDescription));
            }
            catch (Exception ex)
            {
                log.Error(product, ex);
                RaiseNotification("Error", "Failed to add the new product");
            }
            finally
            {
                RaiseNotification("Success", string.Format("Successfully added new product '{0}'", ProductDescription));
                ResetUI();
            }
        }
コード例 #5
0
        public string Add(Product product)
        {
            var result = ProductModel.Add(product);

            return(JsonConvert.SerializeObject(result));
        }
コード例 #6
0
ファイル: ModifyProModel.cs プロジェクト: ngochoanhbr/dahuco
        protected void btnok_Click(object sender, System.EventArgs e)
        {
            if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString()))
            {
                base.ShowMsg("Không có thẩm quyền");
            }
            else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString()))
            {
                base.ShowMsg("Không có thẩm quyền");
            }
            else
            {
                ProductModelInfo productModelInfo = new ProductModelInfo();
                if (base.IsEdit)
                {
                    productModelInfo = ProductModel.GetCacheModelById(base.OpID);
                }
                productModelInfo.ModelName = WebUtils.GetString(this.TextBox1.Text);
                productModelInfo.TableName = "shop_P_" + WebUtils.GetString(this.TextBox2.Text);
                productModelInfo.ModelDesc = WebUtils.GetString(this.TextBox3.Text);
                productModelInfo.Creator   = base.LoginAccount.AccountName;
                if (string.IsNullOrEmpty(productModelInfo.ModelName))
                {
                    base.ShowMsg("模型名称不能为空");
                }
                else if (string.IsNullOrEmpty(this.TextBox2.Text))
                {
                    base.ShowMsg("数据表名不能为空");
                }
                else
                {
                    if (base.Action.Equals(ActionType.Add.ToString()))
                    {
                        productModelInfo.Sort          = ProductModel.MaxSort + 1;
                        productModelInfo.AutoTimeStamp = System.DateTime.Now;
                        ModelAddState modelAddState  = ProductModel.Add(productModelInfo);
                        ModelAddState modelAddState2 = modelAddState;
                        switch (modelAddState2)
                        {
                        case ModelAddState.Error:
                            base.ShowMsg("添加产品模型失败");
                            break;

                        case ModelAddState.ModelNameExists:
                            base.ShowMsg("产品模型名称已经存在");
                            break;

                        case ModelAddState.TableNameIsUsing:
                            base.ShowMsg("已经存在相同的自定义表名称");
                            break;

                        case ModelAddState.TableExists:
                            base.ShowMsg("自定义表已经存在");
                            break;

                        case ModelAddState.CreateTableError:
                            base.ShowMsg("创建自定义表失败");
                            break;

                        default:
                            if (modelAddState2 == ModelAddState.Success)
                            {
                                PageBase.log.AddEvent(base.LoginAccount.AccountName, "添加产品模型[" + productModelInfo.ModelName + "] thành công");
                                MessageUtils.DialogCloseAndParentReload(this);
                            }
                            break;
                        }
                    }
                    if (base.Action.Equals(ActionType.Modify.ToString()))
                    {
                        if (ProductModel.Update(productModelInfo))
                        {
                            PageBase.log.AddEvent(base.LoginAccount.AccountName, "修改产品模型[" + productModelInfo.ModelName + "] thành công");
                            MessageUtils.DialogCloseAndParentReload(this);
                        }
                        else
                        {
                            base.ShowMsg("修改产品模型失败");
                        }
                    }
                }
            }
        }