public void Add(Resturant model) { using (var dbcontext = new ResturantDBEntities()) { dbcontext.Resturants.Add(model); dbcontext.SaveChanges(); } }
public void Delete(Resturant model) { using (var dbcontext = new ResturantDBEntities()) { dbcontext.Resturants.Attach(model); dbcontext.Resturants.Remove(model); dbcontext.SaveChanges(); } }
public void Update(Resturant model) { using (var dbcontext = new ResturantDBEntities()) { foreach (var res in dbcontext.Resturants) { if (res.rs_id == model.rs_id) { res.Name = model.Name; res.Address = model.Address; res.City = model.City; res.State = model.State; res.FoodType = model.FoodType; break; } } dbcontext.SaveChanges(); } }
public static Models.Resturant DataToModel(Resturant data) { Models.Resturant r = new Models.Resturant(); r.Name = data.Name; r.Address = data.Address; r.City = data.City; r.State = data.State; r.FoodType = data.FoodType; r.Reviews = new List <Models.Review>(); foreach (var rev in data.Reviews) { var tmp = new Models.Review { Author = rev.Author, Rating = rev.Rating, Comment = rev.Comment }; r.Reviews.Add(tmp); } return(r); }