private ActivityTemplateDO Clone(ActivityTemplateDO source) { var newTemplate = new ActivityTemplateDO(); CopyPropertiesHelper.CopyProperties(source, newTemplate, false); newTemplate.Terminal = _terminal.GetByKey(source.TerminalId); if (source.Categories != null) { newTemplate.Categories = new List <ActivityCategorySetDO>(); foreach (var acs in source.Categories) { var newActivityCategory = new ActivityCategoryDO(); var activityCategory = _activityCategory.GetById(acs.ActivityCategoryId); CopyPropertiesHelper.CopyProperties(activityCategory, newActivityCategory, false); newTemplate.Categories.Add(new ActivityCategorySetDO() { ActivityTemplateId = newTemplate.Id, ActivityTemplate = newTemplate, ActivityCategoryId = newActivityCategory.Id, ActivityCategory = newActivityCategory }); } } return(newTemplate); }
private TerminalDO Clone(TerminalDO source) { var newTerminal = new TerminalDO(); CopyPropertiesHelper.CopyProperties(source, newTerminal, false); return(newTerminal); }
private ActivityCategoryDO Clone(ActivityCategoryDO activityCategory) { var newActivityCategory = new ActivityCategoryDO(); CopyPropertiesHelper.CopyProperties(activityCategory, newActivityCategory, false); return(newActivityCategory); }
public TerminalDO RegisterOrUpdate(TerminalDO terminalDo, bool isUserInitiated) { if (terminalDo == null) { return(null); } if (!IsATandTCacheDisabled) { Initialize(); } // we are going to change activityTemplateDo. It is not good to corrupt method's input parameters. // make a copy var clone = new TerminalDO(); CopyPropertiesHelper.CopyProperties(terminalDo, clone, true); terminalDo = clone; lock (_terminals) { var doRegisterTerminal = false; TerminalDO terminal, existingTerminal; using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { if (terminalDo.Id == Guid.Empty) { terminalDo.Id = Guid.NewGuid(); uow.TerminalRepository.Add(terminalDo); doRegisterTerminal = true; existingTerminal = terminalDo; } else { existingTerminal = uow.TerminalRepository.FindOne(x => x.Id == terminalDo.Id); // this is for updating terminal CopyPropertiesHelper.CopyProperties(terminalDo, existingTerminal, false, x => x.Name != "Id"); } uow.SaveChanges(); terminal = Clone(existingTerminal); _terminals[existingTerminal.Id] = terminal; } if (doRegisterTerminal) { if (isUserInitiated) { //add ownership for this new terminal to current user _securityServices.SetDefaultRecordBasedSecurityForObject(Roles.OwnerOfCurrentObject, terminal.Id, nameof(TerminalDO), new List <PermissionType>() { PermissionType.UseTerminal }); } //make it visible for Fr8 Admins _securityServices.SetDefaultRecordBasedSecurityForObject(Roles.Admin, terminal.Id, nameof(TerminalDO), new List <PermissionType>() { PermissionType.UseTerminal }); } return(terminal); } }
public void RegisterOrUpdate(ActivityTemplateDO activityTemplateDo) { if (activityTemplateDo == null) { return; } // validate values if (string.IsNullOrWhiteSpace(activityTemplateDo.Name)) { throw new ArgumentOutOfRangeException("ActivityTemplate.Name can't be empty"); } if (string.IsNullOrWhiteSpace(activityTemplateDo.Label)) { throw new ArgumentOutOfRangeException("ActivityTemplate.Label can't be empty"); } if (string.IsNullOrWhiteSpace(activityTemplateDo.Version)) { throw new ArgumentOutOfRangeException("ActivityTemplate.Version can't be empty"); } int tempVersion; if (!int.TryParse(activityTemplateDo.Version, out tempVersion)) { throw new ArgumentOutOfRangeException($"ActivityTemplate.Version is not a valid integer value: {activityTemplateDo.Version}"); } // we are going to change activityTemplateDo. It is not good to corrupt method's input parameters. // make a copy var clone = new ActivityTemplateDO(); CopyPropertiesHelper.CopyProperties(activityTemplateDo, clone, true); clone.Terminal = activityTemplateDo.Terminal; // Create list of activity categories for current ActivityTemplate. var activityCategories = new List <ActivityCategoryDO>(); if (activityTemplateDo.Categories != null) { foreach (var acs in activityTemplateDo.Categories) { activityCategories.Add(acs.ActivityCategory); } } activityTemplateDo = clone; activityTemplateDo.Terminal = null; // otherwise we can add dupliacte terminals into the DB if (!IsATandTCacheDisabled) { Initialize(); } lock (_activityTemplates) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { // Try to extract existing ActivityTemplate. var activity = uow.ActivityTemplateRepository.GetQuery() // .Include(x => x.WebService) .FirstOrDefault(t => t.Name == activityTemplateDo.Name && t.TerminalId == activityTemplateDo.TerminalId && t.Version == activityTemplateDo.Version); // We're creating new ActivityTemplate. if (activity == null) { if (activityTemplateDo.Id == Guid.Empty) { throw new ApplicationException("ActivityTemplate Id not specified"); } activity = activityTemplateDo; activityTemplateDo.Categories = null; uow.ActivityTemplateRepository.Add(activityTemplateDo); uow.SaveChanges(); activityTemplateDo.Categories = ApplyActivityCategories(uow, activityTemplateDo, activityCategories); } // We're updating existing ActivityTemplate. else { // TODO: FR-4943, this breaks DEV's activity registration, commented out for now. // if (activity.Id != activityTemplateDo.Id) // { // throw new InvalidOperationException($"Existent activity with same Name ({activity.Name}) and Version ({activity.Version}) that we passed " // + $"has different Id. (ExistentId = {activity.Id}. Passed Id = {activityTemplateDo.Id}. Changing of activity template Id is not possible. If you need to have another Id please update the version number or create new activity template"); // } // This is for updating activity template CopyPropertiesHelper.CopyProperties(activityTemplateDo, activity, false, x => x.Name != "Id"); activity.ActivityTemplateState = ActivityTemplateState.Active; uow.SaveChanges(); activity.Categories = ApplyActivityCategories(uow, activity, activityCategories); } _activityTemplates[activity.Id] = Clone(activity); } } }