public void FunctionTypeRefDataService_Update_CallSaveChanges()
        {
            #region Arrange

            var function = new FunctionTypeRefData()
            {
                Id           = 4,
                FunctionName = "MJJ Management",
            };

            #endregion

            #region Act

            _functionTypeRefDataService.Update(function);

            #endregion

            #region Assert

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

            #endregion
        }
예제 #2
0
        public ActionResult Edit(EditServiceFunctionViewModel model)
        {
            if (_appUserContext.Current.CurrentCustomer == null ||
                _appUserContext.Current.CurrentCustomer.Id == 0)
            {
                return(GetRedirect(model.EditLevel));
            }

            if (_contextManager.RequestManager.Form[FormValuesNames.Return] != null)
            {
                return(GetRedirect(model.EditLevel, model.ServiceFunction.ServiceDomainId));
            }

            if (ModelState.IsValid)
            {
                var serviceFunction = _serviceFunctionService.GetById(model.ServiceFunction.Id);
                if (serviceFunction == null)
                {
                    return(GetRedirect(model.EditLevel, model.ServiceFunction.ServiceDomainId));
                }

                var now = DateTime.Now;

                serviceFunction.FunctionTypeId  = model.ServiceFunction.FunctionTypeId;
                serviceFunction.AlternativeName = model.ServiceFunction.AlternativeName;
                serviceFunction.DiagramOrder    = model.ServiceFunction.DiagramOrder ?? 5;
                serviceFunction.UpdatedBy       = _contextManager.UserManager.Name;
                serviceFunction.UpdatedDate     = now;

                _serviceFunctionService.Update(Mapper.Map <ServiceFunction>(serviceFunction));

                var customerSpecificTypeThreshold = _parameterService.GetParameterByNameAndCache <int>(ParameterNames.CustomerSpecificTypeThreshold);
                var functionType = _functionTypeRefDataService.GetById(serviceFunction.FunctionTypeId);
                if (!functionType.Visible && _functionTypeRefDataService.GetNumberOfFunctionTypeReferences(serviceFunction.FunctionTypeId) >= customerSpecificTypeThreshold)
                {
                    functionType.Visible = true;
                    _functionTypeRefDataService.Update(functionType);
                }


                return(GetRedirect(model.EditLevel, serviceFunction.ServiceDomainId));
            }

            return(View("Edit" + model.EditLevel, model));
        }