// GET: /<controller>/ public IActionResult Index() { getDB.GetSeoul(DateTime.Now); getDB.GetPolice(DateTime.Now, DateTime.Now, 100); List <string> cateList = new List <string>(); using (NoteDBContext db = new NoteDBContext()) { var dv = db.Found; foreach (var a in dv) { cateList.Add(a.Found_BigCate); } } cateList = cateList.Distinct().ToList(); List <SelectListItem> selectlist = new List <SelectListItem>(); foreach (string s in cateList) { selectlist.Add(new SelectListItem { Value = s, Text = s }); } SearchValue sv = new SearchValue(); sv.cateList = selectlist; return(View(sv)); }
public IActionResult Search(SearchValue model, int page = 1) { List <Found> founds = new List <Found>(); using (NoteDBContext db = new NoteDBContext()) { var dbList = db.Found; var searchList = from a in dbList where a.Found_DateTime >= model.Start_date where a.Found_DateTime <= model.End_date where a.Found_BigCate == model.Value select a; searchList = searchList.OrderByDescending(data => data.Found_DateTime); foreach (var found in searchList) { founds.Add(new Found { Found_id = found.Found_id, Found_data = found.Found_data, Found_BigCate = found.Found_BigCate, Found_DateTime = found.Found_DateTime, Found_Description = found.Found_Description, Found_GetPosition = found.Found_GetPosition, Found_ImageURL = found.Found_ImageURL, Found_Name = found.Found_Name, Found_SmallCate = found.Found_SmallCate }); } } ViewBag.sDate = model.Start_date; ViewBag.eDate = model.End_date; ViewBag.cateValue = model.Value; return(View(founds.ToPagedList(page, 10))); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new NoteDBContext( serviceProvider.GetRequiredService <DbContextOptions <NoteDBContext> >())) { // Look for any notes if (context.Note.Any()) { return; // DB has been seeded } context.Note.AddRange( new Note { CreatedDate = DateTime.Parse("2018-9-2"), Title = "Erste Notiz", Text = "Das ist der Text der ersten Note", Importance = 5, FinishDate = DateTime.Parse("2017-9-2"), Finished = true }, new Note { CreatedDate = DateTime.Parse("2018-1-9"), Title = "Zweite Notiz", Text = "Das ist der Text der zweiten Note", Importance = 1, FinishDate = DateTime.Parse("2018-11-9") } ); context.SaveChanges(); } }
public IActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { using (var db = new NoteDBContext()) { // Linq - method chaining //var usre = db.Users // .FirstOrDefault(u=>u.UserID == model.UserID && u.UserPassword == model.UserPassword); var user = db.Users .FirstOrDefault(u => u.UserID.Equals(model.UserID) && u.UserPassword.Equals(model.UserPassword)); if (user != null) { // HttpContext.Session.SetInt32(key, value); HttpContext.Session.SetInt32("USER_LOGIN_KEY", user.UserNo); return(RedirectToAction("LoginSuccess", "Home")); } } ModelState.AddModelError(string.Empty, "ID 혹은 비밀번호가 올바르지 않습니다."); } return(View(model)); }
public HomeController(NoteDBContext noteDBContext, IStyle style, ISortOrder sortOrder, IFilter filter) { _noteDBContext = noteDBContext; _style = style; _sortOrder = sortOrder; _filter = filter; }
/// <summary> /// 게시물 삭제 /// </summary> /// <returns></returns /// public IActionResult Delete(Note model) { using (var db = new NoteDBContext()) { var note = db.Notes.Where(n => n.NoteNo.Equals(model.NoteNo)).FirstOrDefault(); return(View(note)); } }
public IActionResult Detail(int found_id) { using (var db = new NoteDBContext()) { var note = db.Found.FirstOrDefault(n => n.Found_id.Equals(found_id)); return(View(note)); } return(View()); }
public NoteAppUnitTests() { services = new ServiceCollection(); services.AddDbContext <NoteDBContext>(opt => opt.UseInMemoryDatabase()); services.AddSingleton <IStyle>(sortOrder => new Style()); services.AddSingleton <ISortOrder>(sortOrder => new SortOrder()); services.AddSingleton <IFilter>(filter => new Filter()); _serviceProvider = services.BuildServiceProvider(); _dbContext = _serviceProvider.GetService <NoteDBContext>(); }
public IActionResult Index() { int count; using (NoteDBContext db = new NoteDBContext()) { var list = from c in db.Found select c; count = list.Count(); } ViewBag.count = count; return(View()); }
/// <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 NoteDBContext()) { var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(noteNo)); return(View(note)); } return(View()); }
/// <summary> /// 게시판 리스트 /// </summary> /// <returns></returns> // GET: /<controller>/ public IActionResult Index(int page = 1) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new NoteDBContext()) { var list = db.Notes.ToList().OrderByDescending(p => p.NoteNo); return(View(list.ToPagedList(page, 5))); } return(View()); }
public IActionResult Register(User model) { if (ModelState.IsValid) { // Java try(sqlsession) {} catch() {} // C# using (var db = new NoteDBContext()) { db.Users.Add(model); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); } return(View()); }
public void GetSeoul(DateTime today) { string url_Seoul = "http://openapi.seoul.go.kr:8088/76676170526a7268313032484a736978/xml/lostArticleInfo/" + 1 + "/" + 1000 + "/"; XmlDocument xdoc = new XmlDocument(); xdoc.Load(url_Seoul); XmlNodeList xnodeList = xdoc.DocumentElement.SelectNodes("/lostArticleInfo/row"); foreach (XmlNode xnode in xnodeList) { if (xnode["STATUS"].InnerText != "수령") { if (DateTime.Compare(today.AddDays(-7), Convert.ToDateTime(xnode["REG_DATE"].InnerText)) <= 0) { Found found_Seoul = new Found(); found_Seoul.Found_DateTime = Convert.ToDateTime(xnode["REG_DATE"].InnerText); found_Seoul.Found_BigCate = xnode["CATE"].InnerText; found_Seoul.Found_Name = xnode["GET_NAME"].InnerText; found_Seoul.Found_GetPosition = xnode["GET_POSITION"].InnerText; found_Seoul.Found_data = "서울시"; using (var db = new NoteDBContext()) { var data = db.Found .FirstOrDefault(d => d.Found_DateTime.Equals(found_Seoul.Found_DateTime) && d.Found_BigCate.Equals(found_Seoul.Found_BigCate) && d.Found_Name.Equals(found_Seoul.Found_Name) && d.Found_GetPosition.Equals(found_Seoul.Found_GetPosition) && d.Found_data.Equals(found_Seoul.Found_data) ); if (data == null) { db.Found.Add(found_Seoul); db.SaveChanges(); } } } } } }
public IActionResult Edit(Note model) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } model.UserNo = Int32.Parse(HttpContext.Session.GetInt32("USER_LOGIN_KEY").ToString()); using (var db = new NoteDBContext()) { db.Entry(model).CurrentValues.SetValues(model); db.Update(model); db.SaveChanges(); return(Redirect("Index")); } ModelState.AddModelError(string.Empty, "게시물을 저장할 수 없습니다."); return(View(model)); }
public IActionResult Delete(int noteNo) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new NoteDBContext()) { var note = db.Notes.FirstOrDefault(n => n.NoteNo.Equals(noteNo)); db.Notes.Remove(note); db.SaveChanges(); return(Redirect("Index")); } ModelState.AddModelError(string.Empty, "게시물을 삭제할 수 없습니다."); return(View()); }
public IActionResult Seoul_xmlToDB() { string url = "http://openapi.seoul.go.kr:8088/76676170526a7268313032484a736978/xml/lostArticleInfo/" + 1 + "/" + 1000 + "/"; XmlDocument xdoc = new XmlDocument(); xdoc.Load(url); XmlNodeList xnodeList = xdoc.DocumentElement.SelectNodes("/lostArticleInfo/row"); foreach (XmlNode xnode in xnodeList) { if (xnode["STATUS"].InnerText != "수령") { if (DateTime.Compare(Convert.ToDateTime("2020-01-01"), Convert.ToDateTime(xnode["REG_DATE"].InnerText)) <= 0) { Lost_seoul lost_Seoul = new Lost_seoul(); lost_Seoul.Lost_seoul_DateTime = xnode["REG_DATE"].InnerText; lost_Seoul.Lost_seoul_Cate = xnode["CATE"].InnerText; lost_Seoul.Lost_seoul_Name = xnode["GET_NAME"].InnerText; lost_Seoul.Lost_seoul_GetArea = xnode["GET_AREA"].InnerText; lost_Seoul.Lost_Seoul_GetPosition = xnode["GET_POSITION"].InnerText; using (var db = new NoteDBContext()) { db.Lost_seoul.Add(lost_Seoul); db.SaveChanges(); } } } } return(View()); }
public IActionResult Add(Note model) { if (HttpContext.Session.GetInt32("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } model.UserNo = Int32.Parse(HttpContext.Session.GetInt32("USER_LOGIN_KEY").ToString()); if (ModelState.IsValid) { using (var db = new NoteDBContext()) { db.Notes.Add(model); if (db.SaveChanges() > 0) { db.SaveChanges(); return(Redirect("Index")); } } ModelState.AddModelError(string.Empty, "게시물을 저장할 수 없습니다."); } return(View(model)); }
public NoteController(NoteDBContext noteDBContext, IStyle style) { this._noteDBContext = noteDBContext; this.style = style; }
public NoteController(NoteDBContext _context) { context = _context; }
public NoteRepository(NoteDBContext _db) { _dbContext = _db; }
public void GetPolice(DateTime startdate, DateTime enddate, int show_size) { int index = 0; int totalCount = 0; string url_Police = "http://apis.data.go.kr/1320000/LosfundInfoInqireService/getLosfundInfoAccToClAreaPd?serviceKey=QM218VcrO%2BoL6AOKYNgiEK9fQDAeHaoS3%2F8n8PWz3xVM84Dxv24YMuIAJbmrUFsk2b4HancEzvLVCyNBPsIIyw%3D%3D" + "&START_YMD=" + startdate.ToString("yyyyMMdd") + "&END_YMD=" + enddate.ToString("yyyyMMdd") + "&pageNo=" + index + 1 + "&numOfRows=" + show_size; XmlDocument xdoc = new XmlDocument(); xdoc.Load(url_Police); totalCount = Convert.ToInt32(xdoc.GetElementsByTagName("totalCount")[0].InnerText); while (index * show_size < totalCount) { index++; url_Police = "http://apis.data.go.kr/1320000/LosfundInfoInqireService/getLosfundInfoAccToClAreaPd?serviceKey=QM218VcrO%2BoL6AOKYNgiEK9fQDAeHaoS3%2F8n8PWz3xVM84Dxv24YMuIAJbmrUFsk2b4HancEzvLVCyNBPsIIyw%3D%3D" + "&START_YMD=" + startdate.ToString("yyyyMMdd") + "&END_YMD=" + DateTime.Now.ToString("yyyyMMdd") + "&pageNo=" + index + "&numOfRows=" + show_size; xdoc.Load(url_Police); XmlNodeList xnodeList = xdoc.DocumentElement.SelectNodes("/response/body/items/item"); foreach (XmlNode xnode in xnodeList) { Found found_police = new Found(); found_police.Found_data = "경찰청"; found_police.Found_GetPosition = xnode["depPlace"].InnerText; found_police.Found_ImageURL = xnode["fdFilePathImg"].InnerText; found_police.Found_Name = xnode["fdPrdtNm"].InnerText; found_police.Found_Description = xnode["fdSbjt"].InnerText; found_police.Found_DateTime = Convert.ToDateTime(xnode["fdYmd"].InnerText); string cate = xnode["prdtClNm"].InnerText; string[] catelist = cate.Split(" > "); found_police.Found_BigCate = catelist[0]; found_police.Found_SmallCate = catelist[1]; if (!(found_police.Found_BigCate == "기타물품" && found_police.Found_SmallCate == "기타" && found_police.Found_Name == "기타물품")) { using (var db = new NoteDBContext()) { //var data = db.Found.Where(d=> d.Found_Name.ToString().Equals(found_police.Found_Name.ToString()) && // d.Found_Description.ToString().Equals(found_police.Found_Description.ToString()) && // d.Found_DateTime.ToString().Equals(found_police.Found_DateTime.ToString()) && // d.Found_GetPosition.ToString().Equals(found_police.Found_GetPosition.ToString())) // .FirstOrDefault(); var da = from d in db.Found where d.Found_Name == found_police.Found_Name where d.Found_Description == found_police.Found_Description where d.Found_DateTime == found_police.Found_DateTime where d.Found_GetPosition == found_police.Found_GetPosition select d; if (!da.Any()) { db.Found.Add(found_police); db.SaveChanges(); } } } } index++; } }
public NoteContextsController(NoteDBContext context) { _context = context; }
public ArticleController(NoteDBContext _context) { context = _context; }