-
-
Save fpopic/a42ee70cdc5514b4796f 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 Boat Fetch(string boatName) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| return ctx.Boats.SingleOrDefault(b => b.BoatName.Equals(boatName)); | |
| } | |
| } | |
| public void Insert(int id, string boatName, int countryId, decimal length, int ownerId) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| var b = new Boat | |
| { | |
| Id = id, | |
| BoatName = boatName, | |
| CountryId = countryId, | |
| Length = length, | |
| OwnerId = ownerId | |
| }; | |
| ctx.Boats.Add(b); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| public void Update(int id, string boatName, int countryId, decimal length, int ownerId) | |
| { | |
| using (var ctx = new RPPP14Entities()) | |
| { | |
| var b = ctx.Boats.Single(boat => boat.Id == id); | |
| b.BoatName = boatName; | |
| b.CountryId = countryId; | |
| b.Length = length; | |
| b.OwnerId = ownerId; | |
| 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