Example #1
0
        // GET: logins/Create
        public ActionResult Create()
        {
            if (Session["memlist"] != null)
            {
                ViewData objlt   = (ViewData)Session["memlist"];
                member   members = new member();
                members          = objlt.Members;
                ViewBag.idcard   = members.memidcard;
                ViewBag.Readonly = true;
            }
            else
            {
                ViewBag.Readonly = false;
            }

            ViewBag.logmem  = new SelectList(db.member, "memidcard", "memname");
            ViewBag.logtype = new SelectList(db.type, "typecode", "typename");
            return(View());
        }
Example #2
0
        public ActionResult Create(login login)
        {
            if (Session["memlist"] != null)
            {
                if (login.passwordcheck == login.logpass)
                {
                    ViewData objlt   = (ViewData)Session["memlist"];
                    member   members = new member();
                    members = objlt.Members;


                    var chkidcard   = db.member.Where(x => x.memidcard == members.memidcard).FirstOrDefault().memidcard;
                    var chkidcard1  = db.login.Where(x => x.logmem == members.memidcard).FirstOrDefault();
                    var chkusername = db.login.Where(x => x.loguser == login.loguser).FirstOrDefault().loguser;
                    try
                    {
                        if (chkidcard1 != null)
                        {
                            ViewBag.Readonly = false;
                            ModelState.AddModelError("logmem", "รหัสบัตรประชาชนนี้เคยสมัครใช้งานแล้ว");
                            return(View(login));
                        }

                        if (chkusername != null)
                        {
                            ViewBag.Readonly = false;
                            ModelState.AddModelError("loguser", "มีชื่อผู้ใช้นี้ในระบบแล้ว");
                            return(View(login));
                        }
                    }
                    catch (Exception e)
                    {
                        ViewBag.Readonly = false;
                        ModelState.AddModelError("loguser", "มีชื่อผู้ใช้นี้ในระบบแล้ว");
                        return(View(login));
                    }
                    if (chkidcard != null)
                    {
                        login.logmem = chkidcard;

                        if (login.specialcode == "admin")
                        {
                            login.logtype = 1;
                        }
                        else if (login.specialcode == "emp")
                        {
                            login.logtype = 2;
                        }
                        else
                        {
                            login.logtype = 3;
                        }

                        db.login.Add(login);
                        db.SaveChanges();
                        Session.Remove("memlist");
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ViewBag.Readonly = false;
                    ModelState.AddModelError("logpass", "กรุณาใส่รหัสผ่านให้เหมือนกัน!");
                    ModelState.AddModelError("passwordcheck", "กรุณาใส่รหัสผ่านให้เหมือนกัน!");
                }
            }
            else
            {
                if (login.passwordcheck == login.logpass)
                {
                    var chkidcard1 = db.member.Where(x => x.memidcard == login.logmem).FirstOrDefault();
                    var chkidcard2 = db.login.Where(x => x.logmem == login.logmem).FirstOrDefault();
                    if (chkidcard1 != null && chkidcard2 == null)
                    {
                        var chkusername = db.login.Where(x => x.loguser == login.loguser).FirstOrDefault();

                        if (chkusername != null)
                        {
                            ViewBag.Readonly = false;
                            ModelState.AddModelError("loguser", "มีชื่อผู้ใช้นี้ในระบบแล้ว");
                            return(View(login));
                        }

                        if (login.specialcode == "admin")
                        {
                            login.logtype = 1;
                        }
                        else if (login.specialcode == "emp")
                        {
                            login.logtype = 2;
                        }
                        else
                        {
                            login.logtype = 3;
                        }

                        db.login.Add(login);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else if (chkidcard2 != null)
                    {
                        ViewBag.Readonly = false;
                        ModelState.AddModelError("logmem", "รหัสบัตรประชาชนนี้เคยสมัครใช้งานแล้ว");
                        return(View(login));
                    }
                    else
                    {
                        ViewBag.Readonly = false;
                        ModelState.AddModelError("logmem", "ไม่มีรหัสบัตรประชาชนนี้ในระบบ กรุณากลับไปสมัคร");
                        return(View(login));
                    }
                }
                else
                {
                    ViewBag.Readonly = false;
                    ModelState.AddModelError("logpass", "กรุณาใส่รหัสผ่านให้เหมือนกัน!");
                    ModelState.AddModelError("passwordcheck", "กรุณาใส่รหัสผ่านให้เหมือนกัน!");
                }
            }
            ViewBag.logmem  = new SelectList(db.member, "memidcard", "memname", login.logmem);
            ViewBag.logtype = new SelectList(db.type, "typecode", "typename", login.logtype);
            return(View(login));
        }