Esempio n. 1
0
        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));
            }
        }