Beispiel #1
0
        public HttpResponseMessage Delete(int id)
        {
            string loggedInUserID = User.Identity.GetUserId();
            Not    not            = db.Notlar.FirstOrDefault(x => x.ApplicationUserID == loggedInUserID && x.ID == id);
            string baslik         = not.Baslik;

            db.Notlar.Remove(not);
            db.SaveChanges();

            NotIslemBilgiDto mesaj = new NotIslemBilgiDto()
            {
                ID    = id,
                Mesaj = baslik + "baslikli not silindi."
            };

            return(Request.CreateResponse(HttpStatusCode.OK, mesaj));
        }
Beispiel #2
0
        public HttpResponseMessage Save(NotKaydetDto not)
        {
            string           loggedInUserID = User.Identity.GetUserId();
            NotIslemBilgiDto mesaj          = new NotIslemBilgiDto();

            //gelen not isimli parameter üzerinde koşul yaziyorum

            if (not.ID == 0) //yeni kayıt
                             //gelen id daha oluşturulamadiysa yeni kayit aksi halde else te güncelleme yapicam
            {
                Not n = new Not();
                n.ApplicationUserID = loggedInUserID;
                n.EklenmeTarihi     = DateTime.Now;
                n.Baslik            = not.Baslik;
                n.Icerik            = not.Icerik;

                db.Notlar.Add(n);
                db.SaveChanges();

                mesaj.ID    = n.ID;
                mesaj.Mesaj = "Eklendi(" + n.EklenmeTarihi.Value.ToLongDateString() + ")";
            }
            else//güncelleme
            {
                Not n = db.Notlar.FirstOrDefault(x => x.ApplicationUserID == loggedInUserID && x.ID == not.ID);

                if (n == null)//bulamadi diyelim id yi o yüzden if içerisinde kontrol ediyorum
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Bir Hata Oluştu..."));
                }

                n.Baslik = not.Baslik;
                n.Icerik = not.Icerik;
                n.SonGüncellemeTarihi = DateTime.Now;

                db.SaveChanges();

                mesaj.ID    = n.ID;
                mesaj.Mesaj = "Güncellendi (" + n.SonGüncellemeTarihi.Value.ToLongDateString() + ")";
            }

            return(Request.CreateResponse(HttpStatusCode.OK, mesaj));

            //artık güncelleme mi kayıt mi yapti mesaj içerisinde duruyor
        }
Beispiel #3
0
        public HttpResponseMessage Save(NotKaydetDto not)
        {
            string           loggedInUserID = User.Identity.GetUserId();
            NotIslemBilgiDto mesaj          = new NotIslemBilgiDto();

            if (not.ID == 0) //yeni kayıt
            {
                Not n = new Not();
                n.ApplicationUserID = loggedInUserID;
                n.EklenmeTarihi     = DateTime.Now;
                n.Baslik            = not.Baslik;
                n.Icerik            = not.Icerik;

                db.Notlar.Add(n);
                db.SaveChanges();

                mesaj.ID    = n.ID;
                mesaj.Mesaj = "Eklendi (" + n.EklenmeTarihi.Value.ToLongTimeString() + ")";
            }
            else //güncelleme
            {
                Not n = db.Notlar.FirstOrDefault(x => x.ApplicationUserID == loggedInUserID && x.ID == not.ID);

                if (n == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Bir hata oluştu!"));
                }

                n.Baslik = not.Baslik;
                n.Icerik = not.Icerik;
                n.SonGuncellenmeTarihi = DateTime.Now;

                db.SaveChanges();

                mesaj.ID    = n.ID;
                mesaj.Mesaj = "Güncellendi(" + n.SonGuncellenmeTarihi.Value.ToLongDateString() + ")";
            }
            return(Request.CreateResponse(HttpStatusCode.OK, mesaj));
        }