public IActionResult EditS(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()); using (var db = new NoteDataContext()) { var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(model.NoteNo)); if (model.UserNo == note.UserNo) { db.Entry(model).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(RedirectToAction("Index", "Note")); } } else { return(RedirectToAction("EditError", "Note")); } } return(View()); }
public IActionResult Login(LoginViewModel model) { // ID,비밀번호 -필수 if (ModelState.IsValid) { using (var db = new NoteDataContext()) { //Linq - 메서드 체이닝 // => : A Go to B var user = db.Users.FirstOrDefault(u => u.UserId.Equals(model.UserId) && u.UserPassword.Equals(model.UserPassword)); if (user == null) { //로그인에 실패했을때 ModelState.AddModelError(string.Empty, "사용자 ID 혹은 비밀번호가 올바르지 않습니다."); } else { //로그인에 성공했을 때 //HttpContext.Session.SetInt32(key, value); HttpContext.Session.SetInt32("USER_LOGIN_KEY", user.UserNo); return(RedirectToAction("Loginsuccess", "Home")); //로그인 성공 페이지로 이동 } } } return(View(model)); }
public IActionResult Register(User model) { if (ModelState.IsValid) { using (var db = new NoteDataContext()) { db.Users.Add(model); // 메모리까지 올림 db.SaveChanges(); // Commit } return(RedirectToAction("Index", "Home")); } return(View(model)); }
/// <summary> /// 게시판 상세 /// </summary> /// <param name="noteNo"></param> /// <returns></returns> public IActionResult Detail(int noteNo) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { //로그인이 안된 상태 return(RedirectToAction("Login", "Account")); } using (var db = new NoteDataContext()) { var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(noteNo)); HttpContext.Session.SetInt32("NOTE_KEY", note.NoteNo); return(View(note)); } }
/// <summary> /// 게시판 리스트 /// </summary> /// <returns></returns> public IActionResult Index() { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { //로그인이 안된 상태 return(RedirectToAction("Login", "Account")); } using (var db = new NoteDataContext()) { var list = db.Notes.ToList(); return(View(list)); } }
/// <summary> /// 게시물 수정 /// </summary> /// <returns></returns> public IActionResult Edit(Note model) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { //로그인이 안된 상태 return(RedirectToAction("Login", "Account")); } int noteNo = int.Parse(HttpContext.Session.GetInt32("NOTE_KEY").ToString()); using (var db = new NoteDataContext()) { var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(noteNo)); return(View(note)); } }
/// <summary> /// 게시물 삭제 /// </summary> /// <returns></returns> public IActionResult Delete(Note model) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { //로그인이 안된 상태 return(RedirectToAction("Login", "Account")); } model.NoteNo = int.Parse(HttpContext.Session.GetInt32("NOTE_KEY").ToString()); using (var db = new NoteDataContext()) { //Note note = db.Notes.Find(model); db.Notes.Remove(model); if (db.SaveChanges() > 0) { return(RedirectToAction("Index", "Note")); } } return(View(model)); }
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 NoteDataContext()) { db.Notes.Add(model); if (db.SaveChanges() > 0) { return(RedirectToAction("Index", "Note")); } } ModelState.AddModelError(string.Empty, "게시물을 저장할 수 없습니다."); } return(View(model)); }
public NoteService(NoteDataContext dataContext) { _dataContext = dataContext; }
public NoteService(NoteDataContext context, IMapper mapper, IPropertyMappingService propertyMappingService) { _context = context; _propertyMappingService = propertyMappingService; }
public QuickNotesController(NoteDataContext db) { _db = db; }