-
-
Save fpopic/2425b5511446f429ee93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Linq; | |
| namespace Model | |
| { | |
| public class BoatDAL | |
| { | |
| public List<Boat> FetchAll() | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| return ctx.Boats.ToList(); | |
| } | |
| } | |
| public Boat Fetch(int boatId) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| return ctx.Boats.SingleOrDefault(b => b.Id == boatId); | |
| } | |
| } | |
| public void Insert(Boat newBoat) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| ctx.Boats.Add(newBoat); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| public void Update(Boat newBoat) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| //izbrisi stari sa istim id | |
| var oldBoat = ctx.Boats.Single(boat => boat.Id == newBoat.Id); | |
| ctx.Boats.Remove(oldBoat); | |
| //dodaj novi na isti id | |
| ctx.Boats.Add(newBoat); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| public void Delete(int id) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| var b = ctx.Boats.Single(boat => boat.Id == id); | |
| ctx.Boats.Remove(b); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment