private Instance CreateInstanceFromTemplate(Application appInfo, Instance instanceTemplate, int ownerId, DateTime creationTime, string userId) { Instance createdInstance = new Instance() { InstanceOwnerId = ownerId.ToString(), CreatedBy = userId, CreatedDateTime = creationTime, LastChangedBy = userId, LastChangedDateTime = creationTime, AppId = appInfo.Id, Org = appInfo.Org, VisibleDateTime = DateTimeHelper.ConvertToUniversalTime(instanceTemplate.VisibleDateTime), DueDateTime = DateTimeHelper.ConvertToUniversalTime(instanceTemplate.DueDateTime), Labels = instanceTemplate.Labels, PresentationField = instanceTemplate.PresentationField, InstanceState = new InstanceState { IsArchived = false, IsDeleted = false, IsMarkedForHardDelete = false }, }; // copy applications title to presentation field if not set by instance template if (createdInstance.PresentationField == null && appInfo.Title != null) { LanguageString presentation = new LanguageString(); foreach (KeyValuePair <string, string> title in appInfo.Title) { presentation.Add(title.Key, title.Value); } createdInstance.PresentationField = presentation; } if (createdInstance.Data == null) { createdInstance.Data = new List <DataElement>(); } if (instanceTemplate.Process != null) { createdInstance.Process = instanceTemplate.Process; } else { createdInstance.Process = new ProcessState(); } return(createdInstance); }
private Instance CreateInstanceFromTemplate(Application appInfo, Instance instanceTemplate, DateTime creationTime, string userId) { Instance createdInstance = new Instance() { InstanceOwner = instanceTemplate.InstanceOwner, CreatedBy = userId, Created = creationTime, LastChangedBy = userId, LastChanged = creationTime, AppId = appInfo.Id, Org = appInfo.Org, VisibleAfter = DateTimeHelper.ConvertToUniversalTime(instanceTemplate.VisibleAfter), Title = instanceTemplate.Title, Status = instanceTemplate.Status, DueBefore = DateTimeHelper.ConvertToUniversalTime(instanceTemplate.DueBefore), AppOwner = new ApplicationOwnerState { Labels = instanceTemplate.AppOwner?.Labels, }, }; // copy applications title to presentation field if not set by instance template if (createdInstance.Title == null && appInfo.Title != null) { LanguageString presentation = new LanguageString(); foreach (KeyValuePair <string, string> title in appInfo.Title) { presentation.Add(title.Key, title.Value); } createdInstance.Title = presentation; } createdInstance.Data = new List <DataElement>(); createdInstance.Process = instanceTemplate.Process; return(createdInstance); }