Exemple #1
0
        public IActionResult Create(AssetType newAsset)
        {
            try
            {
                TypeManager.Add(newAsset);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }


        }
Exemple #2
0
        void saveButton_Click(object sender, EventArgs e)
        {
            TransactionType toSave = new TransactionType()
            {
                Id         = mLoadedType != null && mLoadedType.Id > 0 ? mLoadedType.Id : -1,
                Vendor     = vendorText.Text,
                Category   = categoryText.Text,
                Identifier = identifierText.Text,
                IdentifierCaseSensitive = caseSensitiveCheckbox.Checked,
                IdentifierMustStart     = startsWithCheckbox.Checked
            };

            TypeManager.Add(toSave);
            mLoadedType = toSave;

            //Scan all transactions and see where the new type can be applied
            List <Transaction> matches = FindMatches(toSave.Identifier, toSave.IdentifierMustStart, toSave.IdentifierCaseSensitive);

            foreach (Transaction transaction in matches)
            {
                transaction.TypeId = toSave.Id;
            }
            StatementManager.SaveAllToCache();

            mUpdateCallback?.Invoke();

            RefreshUi();

            string description = $"{toSave.Vendor}: {toSave.Identifier}";

            foreach (DataGridViewRow row in existingGrid.Rows)
            {
                if (row.Cells[1].Value != null && row.Cells[1].Value.Equals(description))
                {
                    row.Selected = true;
                    break;
                }
            }
        }
Exemple #3
0
      public ActionResult Add(AddCTCViewModel ctc)
      {
          int id;

          if (!IsEnglish(ctc.Name))
          {
              ModelState.AddModelError("Name", "请输入英文代称"); return(View(ctc));
          }
          try
          {
              _vir.FindVirID(ctc.Name);

              ModelState.AddModelError("Name", "已存在该货币,且只可存在一种结算货币");
          }
          catch
          {
          }
          if (ModelState.IsValid)
          {
              Response _response = null;
              //添加的是结算货币 还需添加至货币体系
              if (ctc.ID == 5)
              {
                  Core.Type type = new Core.Type();
                  type.TypeName = ctc.Name;
                  _response     = _type.Add(type);
                  VirtualCurrency vir = new VirtualCurrency();
                  vir.Name        = ctc.Name;
                  vir.TypeID      = ctc.ID;
                  vir.Description = ctc.Name + "/" + ctc.Name;
                  _response       = _vir.Add(vir);
                  id = vir.VirCurID;
              }  //添加的是交易对 直接添加至货币体系
              else
              {
                  VirtualCurrency vir = new VirtualCurrency();
                  vir.Name        = ctc.Name;
                  vir.TypeID      = ctc.ID;
                  vir.Description = ctc.Name + "/" + _type.Find(ctc.ID).TypeName;
                  _response       = _vir.Add(vir);
                  id = vir.VirCurID;
              }
              //都需要为每一个用户添加新的钱包
              List <int> users  = _user.FindList().Select(u => u.UserID).ToList();
              Wallet     wallet = new Wallet();
              foreach (var item in users)
              {
                  wallet.Amount   = 0;
                  wallet.UserID   = item;
                  wallet.VirCurID = id;
                  _wallet.Add(wallet);
              }
              //为新加的货币添加每日情况表
              PriceInDay pr = new PriceInDay {
                  CoinToCoin  = ctc.Name + "/" + _type.Find(ctc.ID).TypeName,
                  AmountInDay = 0,
                  Price       = 0,
                  VolumeInDay = 0,
                  MaxInDay    = 0,
                  MinInDay    = 0,
                  Up          = 0
              };
              _pr.Add(pr);

              if (_response.Code == 1)
              {
                  return(View("Prompt", new Prompt()
                    {
                        Title = "添加货币成功",
                        Message = "您已成功添加了货币【" + _response.Data.Name + "】",
                        Buttons = new List <string> {
                            "<a href=\"" + Url.Action("Index", "Coin") + "\" class=\"btn btn-default\">交易对管理</a>",
                            "<a href=\"" + Url.Action("Add", "Coin") + "\" class=\"btn btn-default\">继续添加</a>"
                        }
                    }));
              }
              else
              {
                  ModelState.AddModelError("", _response.Message);
              }
          }
          //这里还需初始化一次 如果不跳转页面
          var _types = new TypeManager().FindList();

          List <SelectListItem> _listItems = new List <SelectListItem>(_types.Count());

          foreach (var _type in _types)
          {
              _listItems.Add(new SelectListItem()
                {
                    Text = _type.TypeName, Value = _type.ID.ToString()
                });                                                                                         //这里的属性名要与view中的model属性一致
          }
          ViewBag.Types = _listItems;
          return(View(ctc));
      }