public IHttpActionResult PostNewNotatka(NotatkaViewModel notatka)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Nieprawdiłowe dane"));
            }

            using (var dbContext = new NotatnikEntities())
            {
                var entity = new Notatka
                {
                    Tresc       = notatka.Tresc,
                    Tytul       = notatka.Tytul,
                    DataDodania = DateTime.Now
                };
                if (!string.IsNullOrEmpty(entity.Tytul) && !string.IsNullOrEmpty(entity.Tresc))
                {
                    dbContext.Notatka.Add(entity);
                    dbContext.SaveChanges();
                }
                else
                {
                    return(BadRequest("nieprawidłowe dane- tytuł lub treść notatki nie może być pusta"));
                }
            }

            return(Ok());
        }
Пример #2
0
        public Notatka Pobierz(long id)
        {
            try
            {
                Notatka rezultat = null;

                using (PracaMagisterskaEntities baza = new PracaMagisterskaEntities())
                {
                    rezultat = baza.Notatka.Where(x => x.Id == id).Single();
                }
                return(rezultat);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #3
0
 public long?Zapisz(Notatka notatka)
 {
     try
     {
         long?rezultat = null;
         using (PracaMagisterskaEntities baza = new PracaMagisterskaEntities())
         {
             baza.Entry(notatka).State = notatka.Id > 0 ? EntityState.Modified : EntityState.Added;
             baza.SaveChanges();
             rezultat = notatka.Id;
         }
         return(rezultat);
     }
     catch (Exception ex)
     {
         LogHelper.Log.Error(ex);
         return(null);
     }
 }
Пример #4
0
 public ActionResult ZapiszDetaleNotatki(EdytujNotatkeViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             NotatkaRepozytorium notatkaRepozytorium = new NotatkaRepozytorium();
             Notatka             notatka             = null;
             if (model.Id.HasValue)
             {
                 notatka = notatkaRepozytorium.Pobierz(model.Id.Value);
             }
             else
             {
                 notatka = new Notatka();
             }
             notatka.Temat        = model.Temat;
             notatka.Tresc        = model.Tresc;
             notatka.UzytkownikId = ((Uzytkownik)Session["uzytkownik"]).Id;
             notatka.DataDodania  = DateTime.Now;
             long?rezultatZapisu = notatkaRepozytorium.Zapisz(notatka);
             if (rezultatZapisu != null)
             {
                 return(RedirectToAction("ListaNotatek"));
             }
             else
             {
                 return(View("Error"));
             }
         }
         else
         {
             return(View("DetaleNotatki", model));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Log.Error(ex);
         return(View("Error"));
     }
 }
Пример #5
0
        public bool Usun(long id)
        {
            bool rezultat = false;

            try
            {
                using (PracaMagisterskaEntities baza = new PracaMagisterskaEntities())
                {
                    Notatka notatka = null;
                    notatka             = baza.Notatka.Where(x => x.Id == id).Single();
                    notatka.CzyUsuniete = true;
                    baza.SaveChanges();
                    rezultat = true;
                }
                return(rezultat);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #6
0
 public ActionResult DetaleNotatki(long?id)
 {
     try
     {
         EdytujNotatkeViewModel model = new EdytujNotatkeViewModel();
         NotatkaRepozytorium    notatkaRepozytorium = new NotatkaRepozytorium();
         if (id.HasValue == true)
         {
             Notatka pobranaNotatka = notatkaRepozytorium.Pobierz(id.Value);
             model.Id          = pobranaNotatka.Id;
             model.DataDodania = pobranaNotatka.DataDodania;
             model.Temat       = pobranaNotatka.Temat;
             model.Tresc       = pobranaNotatka.Tresc;
         }
         return(View("DetaleNotatki", model));
     }
     catch (Exception ex)
     {
         LogHelper.Log.Error(ex);
         return(View("Error"));
     }
 }