Ejemplo n.º 1
0
 void IService1.DeleteOffice(int officeID) // DeleteOffice
 {
     try
     {
         using (VinylRecordsShopEntities context = new VinylRecordsShopEntities())
         {
             tblOffice officeToDelete = (from f in context.tblOffices where f.OfficeID == officeID select f).First();
             context.tblOffices.Remove(officeToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Ejemplo n.º 2
0
 // ADD , EDIT AND DETELE OFFICE
 vwOffice IService1.AddOffice(vwOffice office) // ADD OFFICE
 {
     try
     {
         using (VinylRecordsShopEntities context = new VinylRecordsShopEntities())
         {
             if (office.OfficeID == 0)
             {   //ZA ADD
                 tblOffice newOffice = new tblOffice();
                 newOffice.OfficeName = office.OfficeName;
                 newOffice.City       = office.City;
                 newOffice.Address    = office.Address;
                 newOffice.PostalCode = office.PostalCode;
                 newOffice.Phone      = office.Phone;
                 newOffice.Mobile     = office.Mobile;
                 context.tblOffices.Add(newOffice);
                 context.SaveChanges();
                 office.OfficeID = office.OfficeID;
                 return(office);
             }
             else
             { // ZA EDIT
                 tblOffice officeToEdit = (from f in context.tblOffices where f.OfficeID == office.OfficeID select f).First();
                 officeToEdit.OfficeName = office.OfficeName;
                 officeToEdit.City       = office.City;
                 officeToEdit.Address    = office.Address;
                 officeToEdit.PostalCode = office.PostalCode;
                 officeToEdit.Phone      = office.Phone;
                 officeToEdit.Mobile     = office.Mobile;
                 //officeToEdit.OfficeID = office.OfficeID;
                 context.Entry(officeToEdit).State = EntityState.Modified;
                 context.SaveChanges();
                 return(office);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }