public ActionResult PostRegister(string phone, string Password, string Validate) { //if (!phone.MatchAndNotNull(RegularUtil.Phone)) return Error("手机号错误"); var cookie = Request.Cookies["PostRegister_valicode"]; if (cookie == null) { return Error("验证码错误."); } var cookieValue = cookie.Value; if (Validate.Hash().Hash() != cookieValue) { ModelState.AddModelError("", "验证码错误!"); return Error("验证码错误."); } try { Vol model = new Vol(); model.RealNameState = 1; model.State = 1; model.Type = "志愿者"; model.LoveBankScore = 0; model.Score = 0; model.Source = 2;//来源未2标示是爱心银行网站 model.Phone = phone; model.PassWord = Password; using (LoveBankDBContext db = new LoveBankDBContext()) { var tv = db.T_Vol; if (tv.Count(x => x.Phone == model.Phone) > 0) { return Error("该手机号已经存在"); } db.Add<Vol>(model); db.SaveChanges(); } _authenticationService.SignIn(model.ID.ToString(), false); ViewData["Jump"] = Url.Action("Index", "Home"); //return Redirect("~/"); return RedirectToAction("RegSuccess"); } catch (Exception ex) { return Error(ex.Message); } }
public ActionResult PostVolBindNFC(Vol model) { if (string.IsNullOrEmpty(model.NFC) || model.NFC.Length != 10) { return Error("卡号不对,请重新操作"); } using (LoveBankDBContext db = new LoveBankDBContext()) { var t_v = db.T_Vol; Vol vol = t_v.FirstOrDefault(x => x.ID == model.ID); if (vol == null) { return Error("用户不存在,请核实后从新操作"); } if (t_v.Count(x => x.NFC == model.NFC) > 0) { return Error("该NFC卡已经被绑定"); } vol.NFC = model.NFC; db.Update(vol); db.SaveChanges(); } return Success("绑定成功"); }
public ActionResult PostAddVolExcel() { HttpPostedFileBase Volfile = Request.Files["volInfoExcel"]; FileInfo file2 = new FileInfo(Volfile.FileName); string FileName = Server.MapPath("..//Tmp") + "//" + AdminUser.ID + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + file2.Extension; //string FileName = @"C:\工作项目资料\爱心银行项目\志愿者导入模板.xls"; FileHelper.Upload(Volfile, FileName); ExcelHelper eh = new ExcelHelper(FileName, ""); DataTable dt = eh.InputFromExcel(); List<Vol> volList = new List<Vol>(); using (LoveBankDBContext db = new LoveBankDBContext()) { for (int i = 0; i < dt.Rows.Count; i++) { Vol tmp = new Vol(); tmp.Phone = dt.Rows[i]["手机号"].ToString(); if (db.T_Vol.Count(x => x.Phone == tmp.Phone) > 0) { return Error("批量导入失败,手机号是:" + tmp.Phone + "、姓名是" + tmp.RealName + "的自愿者已经存在"); } tmp.RealName = dt.Rows[i]["姓名"].ToString(); tmp.VolType = (VolType)Enum.Parse(typeof(VolType), dt.Rows[i]["志愿者类型"].ToString()); tmp.Sex = dt.Rows[i]["性别"].ToString(); tmp.State = 1; tmp.Score = 50; tmp.ThsScore = 20; tmp.LoveBankScore = 0; tmp.Type = "志愿者"; tmp.PassWord = "******"; tmp.DepId = AdminUser.DeptId; tmp.VID = tmp.Phone; tmp.Source = 1; if (volList.Count(x => x.Phone == tmp.Phone) > 0) { return Error("批量导入失败,Excel表格中手机号重复:" + tmp.Phone + "、姓名是" + tmp.RealName + ""); } volList.Add(tmp); } db.T_Vol.AddRange(volList); db.SaveChanges(); } System.IO.File.Delete(FileName); return Success("批量导入成功"); }
public ActionResult PostEdit(Vol model) { Vol dbEntity = DbProvider.D<Vol>().FirstOrDefault(x => x.Phone == model.Phone && x.ID != model.ID); if (dbEntity != null && dbEntity.Phone != null) { Error("该手机号已经存在"); } Vol vol = DbProvider.D<Vol>().FirstOrDefault(x => x.ID == model.ID); vol.Phone = model.Phone; vol.RealName = model.RealName; vol.Sex = model.Sex; vol.Age = model.Age; vol.Address = model.Address; vol.DepId = model.DepId; vol.VolType = model.VolType; DbProvider.SaveChanges(); return Success("编辑保存成功"); }
public ActionResult PostAdd(Vol model, string volHeadImgBase64) { if (!string.IsNullOrEmpty(volHeadImgBase64)) { byte[] headerimgByte = Convert.FromBase64String(volHeadImgBase64.Substring(23)); model.VolHeadImg = headerimgByte; } using (LoveBankDBContext db = new LoveBankDBContext()) { var tv = db.T_Vol; if (tv.Count(x => x.Phone == model.Phone) > 0) { return Success("该手机号已经存在"); } model.RealNameState = 1; model.State = 1; model.Type = "志愿者"; model.LoveBankScore = 0; model.Score = 0; model.Source = 1;//来源未1标示是爱心银行 model.AddUserId = AdminUser.ID; db.Add<Vol>(model); db.SaveChanges(); return Success("操作成功"); } }