示例#1
0
 private void AddLikes(NoteDB n, string user)
 {
     if (n.Likes == "无")
     {
         n.Likes = user;
     }
     else
     {
         n.Likes += ",";
         n.Likes += user;
     }
     db.Entry(n).State = EntityState.Modified;
     db.SaveChanges();
 }
    public async Task <Article> Add([FromBody] Article _Data)
    {
        Article ArticleInDB = null;

        if (_Data.Id != null)
        {
            ArticleInDB = context.Articles.Where(x => x.Id == _Data.Id).FirstOrDefault();
        }
        else
        {
            _Data.Id = Guid.NewGuid();
        }
        if (ArticleInDB != null)
        {
            ArticleInDB.Title = _Data.Title;
            ArticleInDB.Desc  = _Data.Desc;
        }
        else
        {
            await context.Articles.AddAsync(_Data);

            ArticleInDB = _Data;
        }
        context.SaveChanges();
        return(ArticleInDB);
    }
示例#3
0
        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 async Task <NoteData> Add([FromBody] NoteData _Data)
    {
        _Data.Id = Guid.NewGuid();
        await context.NoteDatas.AddAsync(_Data);

        context.SaveChanges();
        return(_Data);
    }
示例#5
0
        public ActionResult Create([Bind(Include = "ID,Title,Subject,Text,TimeSent")] Note note)
        {
            if (ModelState.IsValid)
            {
                db.Notes.Add(note);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(note));
        }
示例#6
0
        /*
         * Füllt die DB mit einem neuen Datensatz
         */
        private void FillDBWithNode(int id)
        {
            Note note = Note.CreateNew();

            note.ID    = id;
            note.Title = "Titel 1.Notiz";
            note.Text  = "Text der 1. Notiz";

            _dbContext.Add(note);
            _dbContext.SaveChanges();
        }
示例#7
0
        public IActionResult Edit(int?id, [Bind("ID,CreatedDate,Title,Text,Importance,FinishDate,Finished")] Note note)
        {
            ViewData["CurrentStyle"] = style.getCurrent();
            if (id != note.ID)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _noteDBContext.Update(note);
                    _noteDBContext.SaveChanges();
                }
                catch (DbUpdateConcurrencyException) { return(BadRequest()); }
                catch (DbUpdateException) { return(BadRequest()); }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(note));
        }
示例#8
0
        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 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());
        }
示例#10
0
        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();
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        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));
        }
示例#12
0
        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());
        }
示例#13
0
        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());
        }
示例#14
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
示例#15
0
        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++;
            }
        }