/// <summary> /// Delete records in shippers table /// </summary> /// <param name="param">param</param> /// <param name="param">param</param> public void Delete(WebApiParams param) { using (NorthwindEntities context = new NorthwindEntities()) { // Creating object to store the result set. object dynObj; // Gets the Shipper record using Linq to Entities based on ShipperID Shipper objShipper = context.Shippers.FirstOrDefault(x => x.ShipperID == param.ShipperId); if (objShipper != null) { // Deletes Shipper entity from the context object. context.Shippers.Remove(objShipper); } // Saves all changes made in the context object to the database. dynObj = context.SaveChanges(); param.Obj = dynObj; } }
/// <summary> /// Insert record in Shippers table /// </summary> /// <param name="param">param</param> /// <param name="param">param</param> public void Insert(WebApiParams param) { using (NorthwindEntities context = new NorthwindEntities()) { // Creating object to store the result set. object dynObj; // Creating Shipper object. Shipper objShipper = new Shipper(); // Set vlaues to the Shipper Entity. if (!string.IsNullOrWhiteSpace(param.CompanyName)) { objShipper.CompanyName = param.CompanyName; objShipper.Phone = param.Phone; // Adds Shipper Entity to the context object. context.Shippers.Add(objShipper); } // Saves all changes made in the context object to the database. dynObj = context.SaveChanges(); param.Obj = dynObj; } }
/// <summary> /// Update records in shippers table /// </summary> /// <param name="param">param</param> /// <param name="param">param</param> public void Update(WebApiParams param) { using (NorthwindEntities context = new NorthwindEntities()) { // Creating object to store the result set. object dynObj; // Gets the Shipper record using Linq to Entities based on ShipperID Shipper objShipper = context.Shippers.FirstOrDefault(x => x.ShipperID == param.ShipperId); if (objShipper != null) { // Set vlaues to the Shipper Entity. if (!string.IsNullOrWhiteSpace(param.CompanyName)) { objShipper.CompanyName = param.CompanyName; } if (!string.IsNullOrWhiteSpace(param.Phone)) { objShipper.Phone = param.Phone; } } // Saves all changes made in the context object to the database. dynObj = context.SaveChanges(); param.Obj = dynObj; } }