public ActionResult CodeAdd(PINCode model) { int id = 0; if (!String.IsNullOrEmpty(Request["id"].Trim())) { id = Convert.ToInt32(Request["id"].Trim()); } model.Id = id; codeAddOrEdit(model); Response.Write("<script> alert('操作成功!');parent.close1(true);</script> "); return(null); }
public void CreateCard() { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"]; using (ATMContext context = new ATMContext(settings.ConnectionString)) { Card card = new Card(); card.Number = "1234528415234582"; context.Cards.Add(card); context.SaveChanges(); PINCode pin = new PINCode(); pin.CardID = 1; pin.Code = GetCodeHash("1234"); context.PINCodes.Add(pin); context.SaveChanges(); } }
public ActionResult CodeAdd() { int id = 0; if (!String.IsNullOrEmpty(Request["id"].Trim())) { id = Convert.ToInt32(Request["id"].Trim()); } int topicId = Convert.ToInt32(Request["topicId"].Trim()); if (id > 0) { List <PINCode> list = KShortData.Get <List <PINCode> >(KShortDataKeyFactory.PinCodeKey + "_" + topicId, KShortDataDomainFactory.PinCodeDomain); return(View(list.Find(u => u.Id == id))); } PINCode model = new PINCode(); model.TopicId = topicId; return(View(model)); }
private bool codeAddOrEdit(PINCode model) { if (model.TopicId <= 0) { KJs.alert("错误"); return(false); } lock (lockThis) { model.Answer = model.Answer.Trim(); string[] answers = model.Answer.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (answers == null || answers.Length == 0) { KJs.alert("没有填写答案或答案格式不正确"); return(false); } string answer = ""; foreach (string str in answers) { try { answer += Convert.ToInt32(str) + ","; } catch (Exception e) { KJs.alert("答案格式不正确"); return(false); } } if (String.IsNullOrEmpty(answer)) { KJs.alert("答案格式不正确"); return(false); } else { model.Answer = answer.Substring(0, answer.Length - 1); } List <PINCode> list = KShortData.Get <List <PINCode> >(KShortDataKeyFactory.PinCodeKey + "_" + model.TopicId, KShortDataDomainFactory.PinCodeDomain); if (model.Id > 0 && list != null && list.FindIndex(u => u.Id == model.Id) >= 0) { int index = list.FindIndex(u => u.Id == model.Id); list[index] = model; KShortData.Set <List <PINCode> >(KShortDataKeyFactory.PinCodeKey + "_" + model.TopicId, KShortDataDomainFactory.PinCodeDomain, list); return(true); } else { if (list == null) { list = new List <PINCode>(); } if (model.Id == 0) { if (list.Count == 0) { model.Id = 1; } else { model.Id = 1 + list.Max(u => u.Id); } } list.Add(model); list = list.OrderBy(u => u.Id).ToList(); KShortData.Set <List <PINCode> >(KShortDataKeyFactory.PinCodeKey + "_" + model.TopicId, KShortDataDomainFactory.PinCodeDomain, list); return(true); } } }