public bool Update(Org org) { using (var db = new FirewoodContext()) { var x = db.Orgs.Find(org.OrgID); x.OrgDepartment = org.OrgDepartment; x.OrgIntroduction = org.OrgIntroduction; x.OrgContact = org.OrgContact; return db.SaveChanges() == 1; } }
public bool Create(Org org) { org.RegisterTime = DateTime.Now; org.LastLogin = DateTime.Now; org.State = 1; using (var db = new FirewoodContext()) { db.Orgs.Add(org); return db.SaveChanges() == 1; } }
public bool UpdateInfo(Org org) { return orgHandler.Update(org); }
public bool Register(Org org) { if (IsBlankReg(org).Equals("ok")) { return orgHandler.Create(org); } else { return false; } }
/// <summary> /// 判断注册字段长度(社团名称、所属部门、简介、联系方式) /// </summary> /// <param name="org"></param> /// <returns></returns> public string IsBlankReg(Org org) { if (org.OrgName.Length == 0 || org.OrgName.Length > 20) { return "orgname"; } else if (org.OrgDepartment.Length == 0 || org.OrgDepartment.Length > 20) { return "orgdepartment"; } else if (org.OrgIntroduction.Length == 0 || org.OrgIntroduction.Length > 500) { return "orgintroduction"; } else if (org.OrgContact.Length == 0 || org.OrgContact.Length > 20) { return "orgcontact"; } else { return "ok"; } }
public ActionResult PostRegister(RegisterModels model, HttpPostedFileBase file) { if (!ModelState.IsValid) { return View("Register", model); } if (orgService.OrgNameRegistered(model.OrgName)) { ModelState.AddModelError("OrgName", "用户名已被注册咯~"); return View("Register", model); } Org org = new Org { OrgID = Guid.NewGuid(), OrgName = model.OrgName, OrgContact = model.OrgContact, OrgDepartment = model.OrgDepartment, OrgIntroduction = model.OrgIntro }; //图片不超过5M if (file == null && file.ContentLength > 1024 * 1024 * 5) { ModelState.AddModelError("", "请上传规定大小的图片"); return View("Register", model); } //验证通过后 string absolutePath = "E:\\web\\Firewood\\";// SiteConfig.SitePath; string path = GetPath("Org"); string fullPath = absolutePath + path; string url = path + org.OrgID.ToString() + ".png"; using (var stream = file.InputStream) { Image img = Image.FromStream(stream); var bmp = ResizeImg(img); if (!System.IO.Directory.Exists(fullPath)) System.IO.Directory.CreateDirectory(fullPath); bmp.Save(absolutePath+url, ImageFormat.Png); } org.OrgPic = url; if (orgService.Register(org)) { Session["Org"] = org; return Content("<script>alert('注册成功~');window.location.href='Search/Page/1'</script>"); } else { ModelState.AddModelError("", "注册异常"); return View("Register", model); } }