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()); }
public IHttpActionResult PatchNotatka(NotatkaViewModel notatkaVM) { if (!notatkaVM.Id.HasValue) { return(BadRequest("Brak id notatki do edycji")); } using (var dbContext = new NotatnikEntities()) { var notatka = dbContext.Notatka.FirstOrDefault(n => n.Id == notatkaVM.Id.Value); if (notatka == null) { return(NotFound()); } if (!string.IsNullOrEmpty(notatkaVM.Tresc)) { notatka.Tresc = notatkaVM.Tresc; } if (!string.IsNullOrEmpty(notatkaVM.Tytul)) { notatka.Tytul = notatkaVM.Tytul; } //notatka.DataDodania = DateTime.Now; dbContext.SaveChanges(); return(Ok()); } }
public IHttpActionResult GetNotatakaById(int id) { NotatkaViewModel notatka = null; using (var dbContext = new NotatnikEntities()) { notatka = dbContext.Notatka .Where(n => n.Id == id) .Select(n => new NotatkaViewModel() { Id = n.Id, Tytul = n.Tytul, Tresc = n.Tresc, DataDodania = n.DataDodania }).FirstOrDefault <NotatkaViewModel>(); } if (notatka == null) { return(NotFound()); } return(Ok(notatka)); }
public glowna_View(ObservableCollection <NotatkaViewModel> lista_Notatki) { InitializeComponent(); viewModel = new NotatkaViewModel(); }
public glowna_View() { InitializeComponent(); viewModel = new NotatkaViewModel(); }