void IService1.DeleteCustomer(int customerID) // DeleteCustomer { try { using (VinylRecordsShopEntities context = new VinylRecordsShopEntities()) { tblCustomer customerToDelete = (from r in context.tblCustomers where r.CustomerID == customerID select r).First(); context.tblCustomers.Remove(customerToDelete); context.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
// ADD , EDIT I DELETE ZA CUSTOMER vwCustomer IService1.AddCustomer(vwCustomer customer) // AddCustomer { try { using (VinylRecordsShopEntities context = new VinylRecordsShopEntities()) { if (customer.CustomerID == 0) { // ZA ADD tblCustomer newCustomer = new tblCustomer(); newCustomer.Name = customer.Name; newCustomer.LastName = customer.LastName; newCustomer.Country = customer.Country; newCustomer.Address = customer.Address; newCustomer.City = customer.City; newCustomer.Mobile = customer.Mobile; context.tblCustomers.Add(newCustomer); context.SaveChanges(); customer.CustomerID = newCustomer.CustomerID; return(customer); } else { // ZA EDIT tblCustomer customerToEdit = (from r in context.tblCustomers where r.CustomerID == customer.CustomerID select r).First(); customerToEdit.Name = customer.Name; customerToEdit.LastName = customer.LastName; customerToEdit.Country = customer.Country; customerToEdit.Address = customer.Address; customerToEdit.City = customer.City; customerToEdit.Mobile = customer.Mobile; context.Entry(customerToEdit).State = EntityState.Modified; context.SaveChanges(); return(customer); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }