public SaveResult <int> Create(Cryptocurrencies cur, int userId, string userName) { Cryptocurrencies tmp = FoundationDB.DB.Queryable <Cryptocurrencies>().Where(t => t.Name.Equals(cur.Name)).First(); if (tmp != null) { return(new SaveResult <int>(false, "The name already exists.", tmp.Id)); } cur.Withdrawal_Tier = cur.Withdrawal_Tier / 100; int newId = FoundationDB.CryptocurrencyDb.InsertReturnIdentity(cur); // Create ActionLog ActionLog actionLog = new ActionLog(); actionLog.IPAddress = GetClientIPAddress(); actionLog.AccountId = userId; actionLog.CreateTime = DateTime.UtcNow; actionLog.ModuleCode = typeof(CryptocurrenciesBLL).FullName + ".Create"; actionLog.Username = userName; actionLog.LogContent = "Create Cryptocurrencies " + cur.Id; ActionLogBLL ab = new ActionLogBLL(); ab.Create(actionLog); return(new SaveResult <int>(true, newId)); }
private SaveResult SaveEdit(Cryptocurrencies cur) { List <PriceInfos> list = new List <PriceInfos>(); if (cur.IsFixedPrice) { foreach (Currency item in FoundationDB.CurrencyDb.GetList()) { PriceInfos pi = new PriceInfos(); pi.CryptoID = cur.Id; pi.CurrencyID = item.ID; pi.LastUpdateDate = DateTime.Now; pi.Price = Convert.ToDecimal(Request.Form[item.Code]); list.Add(pi); } } CryptocurrenciesBLL ab = new CryptocurrenciesBLL(); return(ab.Update(cur, list, UserId, UserName)); }
private SaveResult <int> SaveCreate(Cryptocurrencies cur) { List <PriceInfos> list = new List <PriceInfos>(); CryptocurrenciesBLL ab = new CryptocurrenciesBLL(); PriceInfoAgent pia = new PriceInfoAgent(); var result = ab.Create(cur, UserId, UserName); if (cur.IsFixedPrice) { foreach (Currency item in FoundationDB.CurrencyDb.GetList()) { PriceInfos pi = new PriceInfos(); pi.CryptoID = result.Data; pi.CurrencyID = item.ID; pi.LastUpdateDate = DateTime.Now; pi.Price = Convert.ToDecimal(Request.Form[item.Code]); list.Add(pi); } pia.Insert(list); } return(result); }
public SaveResult Update(Cryptocurrencies cur, List <PriceInfos> priceList, int userId, string userName) { Cryptocurrencies tmp = FoundationDB.DB.Queryable <Cryptocurrencies>().Where(t => t.Name.Equals(cur.Name)).First(); if (tmp != null && cur.Id != tmp.Id) { return(new SaveResult(false, "The name already exists.")); } Cryptocurrencies oldCur = FoundationDB.CryptocurrencyDb.GetById(cur.Id); if (cur.IconURL != null) { oldCur.IconURL = cur.IconURL; } oldCur.Withdrawal_Tier = cur.Withdrawal_Tier / 100; oldCur.Withdrawal_Fee = cur.Withdrawal_Fee; oldCur.Sequence = cur.Sequence; oldCur.DecimalPlace = cur.DecimalPlace; oldCur.NeedTag = cur.NeedTag; oldCur.Name = cur.Name; oldCur.IsFixedPrice = cur.IsFixedPrice; oldCur.Code = cur.Code; oldCur.Status = cur.Status; oldCur.Enable = cur.Enable; oldCur.IsWhiteLabel = cur.IsWhiteLabel; StringBuilder sb = new StringBuilder(); if (cur.IsFixedPrice) { var pl = FoundationDB.DB.Queryable <PriceInfos>().Where(t => t.CryptoID == cur.Id).ToList(); if (pl.Count == 0) { FoundationDB.PriceInfoDb.InsertRange(priceList.ToArray()); } else { int count = 0; priceList.ForEach(data => { sb.Append(" Update dbo.PriceInfo " + "SET " + "[Price]=@Price" + count.ToString() + " WHERE [CryptoID]=@CryptoId" + count.ToString() + " and [CurrencyID] = @CurrencyID" + count.ToString() + "; "); count++; }); count = 0; SugarParameter[] Paras = new SugarParameter[(priceList.Count * 3)]; int paraCount = 0; priceList.ForEach(data => { Paras[count] = new SugarParameter("@Price" + paraCount.ToString(), priceList[paraCount].Price); count++; Paras[count] = new SugarParameter("@CryptoID" + paraCount.ToString(), priceList[paraCount].CryptoID); count++; Paras[count] = new SugarParameter("@CurrencyID" + paraCount.ToString(), priceList[paraCount].CurrencyID); count++; paraCount++; }); FoundationDB.DB.Ado.ExecuteCommand(sb.ToString(), Paras); } } // Create ActionLog ActionLog actionLog = new ActionLog(); actionLog.IPAddress = GetClientIPAddress(); actionLog.AccountId = userId; actionLog.CreateTime = DateTime.UtcNow; actionLog.ModuleCode = typeof(CryptocurrenciesBLL).FullName + ".Update"; actionLog.Username = userName; actionLog.LogContent = "Update Cryptocurrencies " + cur.Id; ActionLogBLL ab = new ActionLogBLL(); ab.Create(actionLog); return(new SaveResult(FoundationDB.CryptocurrencyDb.Update(oldCur))); }
public ActionResult Edit(int Id) { Cryptocurrencies cur = new Cryptocurrencies(); cur.Id = -1; List <PriceInfoViewModel> priceList = new List <PriceInfoViewModel>(); if (Id > 0) { cur = FoundationDB.CryptocurrencyDb.GetById(Id); cur.Withdrawal_Tier = cur.Withdrawal_Tier * 100; priceList = FoundationDB.DB.Queryable <Currency, PriceInfos>((c, pi) => new object[] { JoinType.Left, c.ID == pi.CurrencyID }).Where((c, pi) => pi.CryptoID == Id).Select((c, pi) => new PriceInfoViewModel { CurrencyName = c.Name, CurrencyCode = c.Code, Price = pi.Price }).ToList(); if (priceList.Count == 0) { foreach (Currency item in FoundationDB.CurrencyDb.GetList()) { PriceInfoViewModel pv = new PriceInfoViewModel(); pv.CurrencyName = item.Name; pv.CurrencyCode = item.Code; priceList.Add(pv); } } } else { foreach (Currency item in FoundationDB.CurrencyDb.GetList()) { PriceInfoViewModel pv = new PriceInfoViewModel(); pv.CurrencyName = item.Name; pv.CurrencyCode = item.Code; priceList.Add(pv); } } Dictionary <string, bool> roleDic = new Dictionary <string, bool>(); foreach (var item in EnumHelper.EnumToList <CryptoStatus>()) { roleDic.Add(item.EnumName, CheckRoleOpened((byte)cur.Status, (CryptoStatus)item.EnumValue)); } var statusList = new List <SelectListItem>(); statusList.Add(new SelectListItem() { Text = "Enable", Value = "1" }); statusList.Add(new SelectListItem() { Text = "Disable", Value = "0" }); ViewBag.StatusList = statusList; ViewBag.RoleDic = roleDic; ViewBag.PriceList = priceList; var boolList = new List <SelectListItem>(); boolList.Add(new SelectListItem() { Text = "True", Value = "1" }); boolList.Add(new SelectListItem() { Text = "False", Value = "0" }); ViewBag.BoolList = boolList; return(View(cur)); }
public ActionResult Save(Cryptocurrencies cur) { var roleStr = Request.Form["moduleperm"]; CryptoStatus role = new CryptoStatus(); if (!string.IsNullOrWhiteSpace(roleStr)) { roleStr.Split(',').ToList().ForEach(a => { role = role | (CryptoStatus)Enum.Parse(typeof(CryptoStatus), a); }); } cur.Status = role; //上传图片 HttpPostedFileBase IconFile = Request.Files["Icon"]; if (IconFile.ContentLength != 0) { cur.IconURL = new Guid(new Utils.FileUploader().UpImageToCDN(IconFile)); } SaveResult result = new SaveResult(); var statusList = new List <SelectListItem>(); statusList.Add(new SelectListItem() { Text = "Enable", Value = "1" }); statusList.Add(new SelectListItem() { Text = "Disable", Value = "0" }); ViewBag.StatusList = statusList; var boolList = new List <SelectListItem>(); boolList.Add(new SelectListItem() { Text = "True", Value = "1" }); boolList.Add(new SelectListItem() { Text = "False", Value = "0" }); ViewBag.BoolList = boolList; if (cur.Id > 0)//编辑 { SaveEdit(cur); Cryptocurrencies oldCur = FoundationDB.CryptocurrencyDb.GetById(cur.Id); Dictionary <string, bool> roleDic = new Dictionary <string, bool>(); foreach (var item in EnumHelper.EnumToList <CryptoStatus>()) { roleDic.Add(item.EnumName, CheckRoleOpened((byte)oldCur.Status, (CryptoStatus)item.EnumValue)); } ViewBag.RoleDic = roleDic; List <PriceInfoViewModel> priceList = new List <PriceInfoViewModel>(); priceList = FoundationDB.DB.Queryable <Currency, PriceInfos>((c, pi) => new object[] { JoinType.Left, c.ID == pi.CurrencyID }).Where((c, pi) => pi.CryptoID == cur.Id).Select((c, pi) => new PriceInfoViewModel { CurrencyName = c.Name, CurrencyCode = c.Code, Price = pi.Price }).ToList(); ViewBag.PriceList = priceList; return(View("Edit", oldCur)); } else//新增 { int newId = SaveCreate(cur).Data; Cryptocurrencies newCur = FoundationDB.CryptocurrencyDb.GetById(newId); Dictionary <string, bool> roleDic = new Dictionary <string, bool>(); foreach (var item in EnumHelper.EnumToList <CryptoStatus>()) { roleDic.Add(item.EnumName, CheckRoleOpened((byte)newCur.Status, (CryptoStatus)item.EnumValue)); } ViewBag.RoleDic = roleDic; List <PriceInfoViewModel> priceList = new List <PriceInfoViewModel>(); priceList = FoundationDB.DB.Queryable <Currency, PriceInfos>((c, pi) => new object[] { JoinType.Left, c.ID == pi.CurrencyID }).Where((c, pi) => pi.CryptoID == newId).Select((c, pi) => new PriceInfoViewModel { CurrencyName = c.Name, CurrencyCode = c.Code, Price = pi.Price }).ToList(); ViewBag.PriceList = priceList; return(View("Edit", newCur)); } }