public void Add_SavesToDatabase()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "AddItem_ToDb")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var itemToAdd = new AddItemInputModel()
                {
                    Name = "Item", AcquiredFrom = "How to get", Usage = "None"
                };

                var service = new ItemsService(context);
                service.Add(itemToAdd);

                var expectedItem = new Item()
                {
                    Name = itemToAdd.Name, AcquiredFrom = itemToAdd.AcquiredFrom, Usage = itemToAdd.Usage
                };

                var itemFromDb = context.Items.First();

                Assert.NotEmpty(context.Items);
                Assert.Equal(expectedItem.Name, itemFromDb.Name);
                Assert.Equal(expectedItem.AcquiredFrom, itemFromDb.AcquiredFrom);
                Assert.Equal(expectedItem.Usage, itemFromDb.Usage);
            }
        }
Beispiel #2
0
        /// <summary>
        ///     提交添加
        /// </summary>
        private bool SubmintAdd()
        {
            var its = new LHItems
            {
                FCode  = txtFCode.Text.Trim(),
                FName  = txtFName.Text.Trim(),
                FSpec  = txtFSpec.Text.Trim(),
                FSpell = ChineseSpell.MakeSpellCode(txtFName.Text.Trim(), "",
                                                    SpellOptions.FirstLetterOnly).ToUpper(),
                FFlag = 1,

                //分类
                FCateId    = "2001",
                FSubCateId = ProjectItem.FId,

                FCompanyId = CurrentUser.AccountComId,
                FGroupNum  = txtFGroupNum.Text,
                FMemo      = txtFMemo.Text.Trim(),
                FRack      = txtFRack.Text.Trim(),

                //单位
                FUnit          = ddlUnit.SelectedValue,
                FPurchasePrice = Convert.ToDecimal(txtFPurchasePrice.Text.Trim()),
                FSalesPrice    = Convert.ToDecimal(txtFSalesPrice.Text.Trim()),
                FPieceWork1    = Convert.ToDecimal(txtFPieceWork1.Text.Trim()),
                FPieceWork2    = Convert.ToDecimal(txtFPieceWork2.Text.Trim()),
                FPieceWork3    = Convert.ToDecimal(txtFPieceWork3.Text.Trim()),
                FPieceWork4    = Convert.ToDecimal(txtFPieceWork4.Text.Trim()),
                FPieceWork5    = Convert.ToDecimal(txtFPieceWork5.Text.Trim()),
                FNetWeight     = Convert.ToDecimal(txtFNetWeight.Text.Trim()),//重量
            };

            return(ItemsService.Add(its));
        }
Beispiel #3
0
        /// <summary>
        ///     提交添加
        /// </summary>
        private bool SubmintAdd()
        {
            var its = new LHItems
            {
                FCode  = txtFCode.Text.Trim(),
                FName  = txtFName.Text.Trim(),
                FSpec  = txtFSpec.Text.Trim(),
                FSpell = ChineseSpell.MakeSpellCode(txtFName.Text.Trim(), "",
                                                    SpellOptions.FirstLetterOnly).ToUpper(),
                FFlag = 1,

                //分类
                FCateId    = "2000",
                FSubCateId = ProjectItem.FId,

                FCompanyId = CurrentUser.AccountComId,
                FGroupNum  = txtFGroupNum.Text,
                FMemo      = txtFMemo.Text.Trim(),
                FIsLiquid  = ddlFIsLiquid.SelectedValue,
                FRack      = txtFRack.Text.Trim(),
                //单位
                FUnit          = ddlUnit.SelectedValue,
                FPurchasePrice = Convert.ToDecimal(txtFPurchasePrice.Text.Trim()),
                FSalesPrice    = Convert.ToDecimal(txtFSalesPrice.Text.Trim()),
                //FPieceWork1 = 0,//Convert.ToDecimal(txtFPieceWork.Text.Trim()),
                FQty        = Convert.ToDecimal(txtFQty.Text.Trim()),
                cinvdefine1 = txtcinvdefine1.Text,
                FPieceWork1 = Convert.ToDecimal(txtFPieceWork1.Text.Trim())
            };

            //  包装物问题
            if (!ddlBottleNum.SelectedValue.Equals("-1"))
            {
                var bottle = ItemsMapBottleService.Where(p => p.FCode == ProductItem.FCode && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault();
                if (bottle != null)
                {
                    bottle.FBottleCode = ddlBottleNum.SelectedValue;
                    ItemsMapBottleService.SaveChanges();
                }
                else
                {
                    var bot = new LHItemsMapBottle
                    {
                        FCode       = ProductItem.FCode,
                        FBottleCode = ddlBottleNum.SelectedValue
                    };

                    ItemsMapBottleService.Add(bot);
                }
            }

            return(ItemsService.Add(its));
        }
Beispiel #4
0
 public ActionResult <int> Add(ItemsAddRequest model)
 {
     try
     {
         ItemsService service = new ItemsService();
         int          id      = service.Add(model);
         return(Ok(id));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message.ToString()));
     }
 }