public static void CRUDExample(CorrigoService service) { if (service == null) { return; } Console.WriteLine("WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable"); WoLastAction wola = Create.Execute(service); CorrigoEntity[] lastActions = Read.RetrieveByQuery(service); if (lastActions != null && lastActions.Length > 0) { WoLastAction lastAction = Read.Retrieve(service, lastActions[0].Id); // WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable Delete.Execute(service, lastActions[0].Id); // WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable Update.Restore(service, lastAction); // WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable Update.Execute(service, lastAction); } }
public static void Restore(CorrigoService service, WoLastAction toRestore) { if (toRestore == null || service == null) { return; } Console.WriteLine(); Console.WriteLine($"Restoring WoLastAction with id={toRestore.Id}"); var restoreResult = service.Execute(new RestoreCommand { EntitySpecifier = new EntitySpecifier { Id = toRestore.Id, EntityType = EntityType.WoLastAction } }); if (restoreResult == null) { Console.WriteLine("Update of WoLastAction failed"); return; } if (restoreResult.ErrorInfo != null && !string.IsNullOrEmpty(restoreResult.ErrorInfo.Description)) { Console.WriteLine(restoreResult.ErrorInfo.Description); Console.WriteLine("Restore of WoLastAction failed"); return; } Console.WriteLine("WoLastAction is restored"); }
// WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable public static WoLastAction Execute(CorrigoService service) { Console.WriteLine(); Debug.Print("Creating WoLastAction"); Console.WriteLine("Creating WoLastAction"); var toCreate = new WoLastAction { WorkOrderId = 1, EmergencyReason = new WoActionReasonLookup() }; var resultData = service.Execute(new CreateCommand { Entity = toCreate }); if (resultData == null) { Debug.Print("Creation of new WoLastAction failed"); Console.WriteLine("Creation of new WoLastAction failed"); Console.WriteLine(); return(null); } var commandResponse = resultData as OperationCommandResponse; int?id = (commandResponse != null && commandResponse.EntitySpecifier != null) ? commandResponse.EntitySpecifier.Id : null; if (id.HasValue && resultData.ErrorInfo == null) { toCreate.Id = id.Value; Debug.Print($"Created new WoLastAction with Id={id.ToString()}"); Console.WriteLine($"Created new WoLastAction with Id={id.ToString()}"); Console.WriteLine(); return(toCreate); } Debug.Print("Creation of new WoLastAction failed"); Console.WriteLine("Creation of new WoLastAction failed"); Console.WriteLine(); if (resultData.ErrorInfo != null && !string.IsNullOrEmpty(resultData.ErrorInfo.Description)) { Debug.Print(resultData.ErrorInfo.Description); Console.WriteLine(resultData.ErrorInfo.Description); } return(null); }
public static int?Execute(CorrigoService service, int woid) { var action = new WoLastAction { WorkOrderId = woid, LastAction = new WoActionLog { Id = 5 }, EmergencyReason = new WoActionReasonLookup { Id = 1289 }, Reason = new WoActionReasonLookup { Id = 1289 }, BillStatus = BillStatus.NotBilled, Invoice = new Invoice { Id = 269 }, BilledTotal = new MoneyValue { Value = 156m, CurrencyTypeId = CurrencyType.USD }, XNumber = "123" }; //WoLastModificationCommand ? var command = new CreateCommand { Entity = action }; var response = service.Execute(command) as OperationCommandResponse; var printOut = response?.ErrorInfo?.Description; printOut = !string.IsNullOrWhiteSpace(printOut) ? $"{nameof(WoLastAction)} creation failure reason: {printOut}" : $"Successfully created {nameof(WoLastAction)} instance for WorkOrder with id {woid}."; Debug.Print(printOut); return(response?.EntitySpecifier?.Id); }
// WoLastAction is Readonly - NonCreatable, NonDeletable, NonUpdatable public static void Execute(CorrigoService service, WoLastAction toUpdate) { if (toUpdate == null || service == null) { return; } toUpdate.BilledTotal = new MoneyValue { Value = 0, CurrencyTypeId = CurrencyType.USD }; Console.WriteLine(); Console.WriteLine($"Updating WoLastAction with id={toUpdate.Id}"); var resultUpdate = service.Execute(new UpdateCommand { Entity = toUpdate, PropertySet = new PropertySet { Properties = new[] { "BilledTotal" } } }); if (resultUpdate == null) { Console.WriteLine("Update of WoLastAction failed"); return; } if (resultUpdate.ErrorInfo != null && !string.IsNullOrEmpty(resultUpdate.ErrorInfo.Description)) { Console.WriteLine(resultUpdate.ErrorInfo.Description); Console.WriteLine("Update of WoLastAction failed"); return; } Console.WriteLine("WoLastAction is updated"); }
public static WoLastAction Retrieve(CorrigoService service, int id) { Console.WriteLine(); Console.WriteLine($"Retrieve WoLastAction with id={id}"); CorrigoEntity result = null; try { result = service.Retrieve( new EntitySpecifier { EntityType = EntityType.WoLastAction, Id = id }, new PropertySet { Properties = new string[] { "*", "LastAction.*", "LastAction.Actor.*", "EmergencyReason.*", "Reason.*", "Invoice.*", "BilledTotal.*", } } //new AllProperties() ); } catch (Exception e) { if (!string.IsNullOrEmpty(e.Message)) { Console.WriteLine(e.Message); } } if (result == null) { Console.WriteLine("Retrieve failed"); return(null); } WoLastAction toReturn = result as WoLastAction; if (toReturn == null) { Console.WriteLine("Retrieve failed"); return(null); } int padRightNumber = 45; Console.WriteLine(string.Concat("WoLastAction.Id=".PadRight(padRightNumber), toReturn.Id.ToString())); Console.WriteLine(string.Concat("WoLastAction.WorkOrderId=".PadRight(padRightNumber), toReturn.WorkOrderId.ToString())); var wo = service.Retrieve(new EntitySpecifier { EntityType = EntityType.WorkOrder, Id = toReturn.WorkOrderId }, new AllProperties()) as WorkOrder; if (wo != null) { Console.WriteLine(string.Concat("WorkOrder.Number= ".PadRight(padRightNumber), $"'{wo.Number}'")); } if (toReturn.EmergencyReason != null) { Console.WriteLine(string.Concat("WoLastAction.EmergencyReason.Id=".PadRight(padRightNumber), toReturn.EmergencyReason.Id.ToString())); Console.WriteLine(string.Concat("WoLastAction.EmergencyReason.DisplayAs=".PadRight(padRightNumber), toReturn.EmergencyReason.DisplayAs ?? "")); Console.WriteLine(string.Concat("WoLastAction.EmergencyReason.ReasonId=".PadRight(padRightNumber), toReturn.EmergencyReason.ReasonId.ToString())); } if (toReturn.Reason != null) { Console.WriteLine(string.Concat("WoLastAction.Reason.Id=".PadRight(padRightNumber), toReturn.Reason.Id.ToString())); Console.WriteLine(string.Concat("WoLastAction.Reason.DisplayAs=".PadRight(padRightNumber), toReturn.Reason.DisplayAs ?? "")); Console.WriteLine(string.Concat("WoLastAction.Reason.ReasonId=".PadRight(padRightNumber), toReturn.Reason.ReasonId.ToString())); } Console.WriteLine(string.Concat("WoLastAction.BillStatus=".PadRight(padRightNumber), toReturn.BillStatus.ToString())); if (toReturn.Invoice != null) { Console.WriteLine(string.Concat("WoLastAction.Invoice.Id=".PadRight(padRightNumber), toReturn.Invoice.Id.ToString())); Console.WriteLine(string.Concat("WoLastAction.Invoice.Comments=".PadRight(padRightNumber), toReturn.Invoice.Comments ?? "")); Console.WriteLine(string.Concat("WoLastAction.Invoice.Number=".PadRight(padRightNumber), toReturn.Invoice.Number ?? "")); } Console.WriteLine(string.Concat("WoLastAction.BilledTotal.Value= ".PadRight(padRightNumber), toReturn.BilledTotal?.Value.ToString() ?? "")); Console.WriteLine(string.Concat("WoLastAction.Xnumber= ".PadRight(padRightNumber), toReturn.XNumber ?? "")); Console.WriteLine(); return(toReturn); }