public void ServiceComponentService_Update_EntityExists_EntityIsUpdated()
        {
            var newEntity = UnitTestHelper.GenerateRandomData <ServiceComponent>(x =>
            {
                x.Id = ServiceComponentId;
            });

            _target.Update(newEntity);

            Assert.AreEqual(14, _serviceComponents.Count);
            Assert.IsTrue(_serviceComponents.Any(x => x.ComponentName == newEntity.ComponentName));
        }
        private void TransformComponentLevelTwo(ServiceComponent parentComponent, TemplateRow templateRow)
        {
            var serviceComponent = parentComponent.ChildServiceComponents?.FirstOrDefault(d => d.ComponentName == templateRow.ServiceComponentLevel2 && d.ComponentLevel == 2);

            if (serviceComponent == null)
            {
                if (parentComponent.ChildServiceComponents == null)
                {
                    parentComponent.ChildServiceComponents = new List <ServiceComponent>();
                }

                var dateTimeNow = DateTime.Now;
                serviceComponent = new ServiceComponent
                {
                    ParentServiceComponent = parentComponent,
                    ServiceFunction        = parentComponent.ServiceFunction,
                    ComponentName          = templateRow.ServiceComponentLevel2,
                    ComponentLevel         = 2,
                    ServiceActivities      = !string.IsNullOrEmpty(templateRow.ServiceActivities) ? templateRow.ServiceActivities : string.Empty,
                    DiagramOrder           = 5,
                    InsertedBy             = _userIdentity.Name,
                    InsertedDate           = dateTimeNow,
                    UpdatedBy   = _userIdentity.Name,
                    UpdatedDate = dateTimeNow
                };

                parentComponent.ChildServiceComponents.Add(serviceComponent);
                _serviceComponentService.Update(parentComponent);
            }
            //else if (!string.IsNullOrEmpty(templateRow.ServiceActivities))
            //{
            //    if (!string.IsNullOrEmpty(serviceComponent.ServiceActivities))
            //        serviceComponent.ServiceActivities += $"\r\n{templateRow.ServiceActivities}";
            //    else
            //    {
            //        serviceComponent.ServiceActivities = templateRow.ServiceActivities;
            //    }

            //    _serviceComponentService.Update(serviceComponent);
            //}

            if (!string.IsNullOrEmpty(templateRow.ServiceDeliveryOrganisation))
            {
                if (serviceComponent.Resolver != null)
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Multiple Resolvers per Component detected on Component [{templateRow.ServiceComponentLevel2}].");
                }

                TransformResolver(serviceComponent, templateRow);
            }
        }
Example #3
0
        public ActionResult MoveLevel1(MoveServiceComponentLevel1ViewModel model)
        {
            var result = GetJsonSuccessResponse();

            if (ModelState.IsValid)
            {
                if (_appUserContext.Current?.CurrentCustomer != null && _appUserContext.Current.CurrentCustomer.Id > 0)
                {
                    try
                    {
                        var component = _serviceComponentService
                                        .GetByCustomer(_appUserContext.Current.CurrentCustomer.Id)
                                        .SingleOrDefault(x => x.Id == model.ServiceComponentId);
                        if (component == null)
                        {
                            result = GetJsonErrorResponse(WebResources.ServiceComponentCannotBeFound);
                        }
                        else
                        {
                            component.ServiceFunctionId = model.DestinationServiceFunctionId;
                            component.UpdatedBy         = _contextManager.UserManager.Name;
                            component.UpdatedDate       = DateTime.Now;
                            if (component.ChildServiceComponents != null && component.ChildServiceComponents.Any())
                            {
                                // Update all of the underlying child service components
                                foreach (var childComponent in component.ChildServiceComponents)
                                {
                                    childComponent.ParentServiceComponentId = component.ParentServiceComponentId;
                                    childComponent.ServiceFunctionId        = model.DestinationServiceFunctionId;
                                    childComponent.UpdatedBy   = _contextManager.UserManager.Name;
                                    childComponent.UpdatedDate = DateTime.Now;
                                }
                            }
                            _serviceComponentService.Update(component);
                        }
                    }
                    catch (Exception ex)
                    {
                        result = GetJsonErrorResponse(ex.Message);
                    }
                }
            }
            else
            {
                result = GetJsonErrorResponse(ModelState.GetModelStateMesssages().First());
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }