public void CreateUpdate() { int PrinterOperationID = Convert.ToInt32(ID); using (ContextModel db = new ContextModel()) { if (PrinterOperationID == 0) { PrinterOperation printer = new PrinterOperation { PrinterOperationID = Convert.ToInt32(ID), PrinterID = Convert.ToInt32(PrinterIDTB.Text), PrinterStatudID = Convert.ToInt32(StatusCB.SelectedValue), OperationData = DateTime.Now }; db.PrinterOperation.Add(printer); } else { var mpToUpdate = db.PrinterOperation.SingleOrDefault(pm => pm.PrinterOperationID == PrinterOperationID); if (mpToUpdate != null) { mpToUpdate.PrinterID = Convert.ToInt32(PrinterIDTB.Text); mpToUpdate.PrinterStatudID = Convert.ToInt32(StatusCB.SelectedValue); mpToUpdate.OperationData = Convert.ToDateTime(DateTime.Now); } } db.SaveChanges(); } }
public void createPrinterOperation(MetroLabel IDLab, string printerID, MetroComboBox printerStatus) { PrinterOperationID = Convert.ToInt32(IDLab.Text); using (ContextModel db = new ContextModel()) { if (PrinterOperationID == 0) { PrinterOperation printer = new PrinterOperation { PrinterID = Int32.Parse(printerID), PrinterStatudID = Convert.ToInt32(printerStatus.SelectedValue), OperationData = DateTime.Now }; db.PrinterOperation.Add(printer); } else { var mpToUpdate = db.PrinterOperation.SingleOrDefault(pm => pm.PrinterOperationID == PrinterOperationID); if (mpToUpdate != null) { mpToUpdate.PrinterStatudID = Convert.ToInt32(printerStatus.SelectedValue); mpToUpdate.OperationData = Convert.ToDateTime(DateTime.Now); } } db.SaveChanges(); } }