示例#1
0
        public IEnumerable <CustomSelectListItem> ListRoles(string userName)
        {
            using (var context = new AspnetDBContext())
            {
                foreach (var item in from rec in context.aspnet_Roles
                         where rec.Description == null || rec.Description.Length == 0
                         orderby rec.RoleName
                         select rec)
                {
                    CustomSelectListItem selectItem = new CustomSelectListItem()
                    {
                        Text = item.RoleName, Value = item.RoleName, Selected = (userName != null && Roles.IsUserInRole(userName, item.RoleName))
                    };

                    selectItem.Children = new MultiSelectList(
                        (from rec in context.aspnet_Roles
                         where rec.Description == item.RoleName
                         orderby rec.RoleName
                         select rec),
                        "RoleName",
                        "RoleName",
                        null);

                    //foreach (var child in from rec in context.aspnet_Roles
                    //                      where rec.Description == item.RoleName
                    //                      orderby rec.RoleName
                    //                      select rec)
                    //{
                    //    selectItem.Child.Add(new CustomSelectListItem() { Text = child.RoleName, Value = child.RoleName, Selected = (userName != null && Roles.IsUserInRole(userName, child.RoleName)) });
                    //}
                    yield return(selectItem);
                }
            }
        }
示例#2
0
        public IActionResult Add(Note model)
        {
            if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null)
            {
                //로그인이 안된 상태
                return(RedirectToAction("Login", "Account"));
            }
            model.UserNo = int.Parse(HttpContext.Session.GetInt32("USER_LOGIN_KEY").ToString());

            if (ModelState.IsValid)
            {
                using (var db = new AspnetDBContext())
                {
                    db.Notes.Add(model);


                    if (db.SaveChanges() > 0)      // commit
                    {
                        return(Redirect("Index")); // 동일한컨트롤러로갈때
                    }
                }
                ModelState.AddModelError(string.Empty, "게시물을 저장할수 없습니다.");
            }
            return(View(model));
        }
 public IActionResult Register(User model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new AspnetDBContext())
         {
             db.Users.Add(model);
             db.SaveChanges();
         }
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }
示例#4
0
 public IActionResult Detail(int noteNo)
 {
     if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null)
     {
         //로그인이 안된 상태
         return(RedirectToAction("Login", "Account"));
     }
     using (var db = new AspnetDBContext())
     {
         var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(noteNo));
         return(View(note));
     }
 }
示例#5
0
 // GET: /<controller>/
 /// <summary>
 /// 게시판 리스트 출력
 /// </summary>
 /// <returns></returns>
 public IActionResult Index()
 {
     if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null)
     {
         //로그인이 안된 상태
         return(RedirectToAction("Login", "Account"));
     }
     using (var db = new AspnetDBContext())
     {
         var list = db.Notes.ToList();
         return(View(list));
     }
 }
 public IActionResult Login(LoginViewModel model)
 {
     //id, pw - 필수
     if (ModelState.IsValid)
     {
         using (var db = new AspnetDBContext())
         {
             var user = db.Users.FirstOrDefault(u => u.UserId.Equals(model.UserId) &&
                                                u.UserPassword.Equals(model.UserPassword));
             if (user != null)
             {
                 //로그인 성공
                 HttpContext.Session.SetInt32("USER_LOGIN_KEY", user.UserNo);
                 return(RedirectToAction("LoginSuccess", "Home"));
             }
         }
         ModelState.AddModelError(string.Empty, "사용자 ID 혹은 비밀번호가 올바르지 않습니다.");
     }
     return(View());
 }