public void ServiceFunctionService_Update_CallUpdatesFunctionAndCallsSaveChanges()
        {
            #region Arrange

            var dateTimeNow = DateTime.Now;

            var serviceFunction = new ServiceFunction
            {
                Id            = 3,
                FunctionType  = _serviceFunctionTypes.FirstOrDefault(x => x.Id == 1),
                ServiceDomain = new ServiceDomain {
                    Id = 1, ServiceDeskId = 1
                },
                InsertedBy   = Username,
                InsertedDate = dateTimeNow,
                UpdatedBy    = Username,
                UpdatedDate  = dateTimeNow,
            };

            #endregion

            #region Act

            _serviceFunctionService.Update(serviceFunction);

            #endregion

            #region Assert

            _mockServiceFunctionRepository.Verify(x => x.Update(It.IsAny <ServiceFunction>()), Times.Once());
            _mockUnitOfWork.Verify(x => x.Save(), Times.Exactly(1));

            #endregion
        }
        private void TransformComponentLevelOne(ServiceFunction serviceFunction, TemplateRow templateRow)
        {
            var serviceComponent = serviceFunction.ServiceComponents.FirstOrDefault(d => d.ComponentName == templateRow.ServiceComponentLevel1 && d.ComponentLevel == 1);

            if (serviceComponent == null)
            {
                var dateTimeNow = DateTime.Now;
                serviceComponent = new ServiceComponent
                {
                    ServiceFunction   = serviceFunction,
                    ComponentName     = templateRow.ServiceComponentLevel1,
                    ComponentLevel    = 1,
                    ServiceActivities = string.IsNullOrEmpty(templateRow.ServiceComponentLevel2) &&
                                        !string.IsNullOrEmpty(templateRow.ServiceActivities)
                        ? templateRow.ServiceActivities
                        : string.Empty,
                    DiagramOrder = 5,
                    InsertedBy   = _userIdentity.Name,
                    InsertedDate = dateTimeNow,
                    UpdatedBy    = _userIdentity.Name,
                    UpdatedDate  = dateTimeNow
                };

                serviceFunction.ServiceComponents.Add(serviceComponent);
                _serviceFunctionService.Update(serviceFunction);
            }
            //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.ServiceComponentLevel2))
            {
                if (serviceComponent.Resolver != null)
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Resolvers and Childs Components detected on Component [{templateRow.ServiceComponentLevel1}].");
                }

                TransformComponentLevelTwo(serviceComponent, templateRow);
            }
            else 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.ServiceComponentLevel1}].");
                }

                TransformResolver(serviceComponent, templateRow);
            }
        }
Beispiel #3
0
        public ActionResult UpdateAjaxServiceFunctionGrid([DataSourceRequest] DataSourceRequest request, ServiceFunctionViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var userName    = _contextManager.UserManager.Name;
                    var dateTimeNow = DateTime.Now;

                    // Update
                    var serviceFunction = _serviceFunctionService.GetById(model.Id);

                    // Check that the domain is from the current customer.
                    if (serviceFunction == null)
                    {
                        _contextManager.ResponseManager.StatusCode = 500;
                        _contextManager.ResponseManager.AppendHeader("HandledError",
                                                                     WebResources.ServiceFunctionCannotBeFound);
                    }
                    else
                    {
                        serviceFunction.AlternativeName = model.AlternativeName;
                        serviceFunction.DiagramOrder    = model.DiagramOrder ?? 5;
                        serviceFunction.FunctionTypeId  = model.FunctionTypeId;
                        serviceFunction.UpdatedDate     = dateTimeNow;
                        serviceFunction.UpdatedBy       = userName;
                        _serviceFunctionService.Update(serviceFunction);
                    }
                }
                catch (Exception ex)
                {
                    _contextManager.ResponseManager.StatusCode = 500;
                    _contextManager.ResponseManager.AppendHeader(ModelStateErrorNames.ErrorMessage, ex.Message);
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }