コード例 #1
0
        public void ServiceDomainService_Create_CallInsertsDomainAndCallsSaveChanges()
        {
            #region Arrange

            var dateTimeNow = DateTime.Now;

            var serviceDomain = new ServiceDomain()
            {
                Id          = 4,
                DomainType  = _serviceDomainTypes.FirstOrDefault(x => x.Id == 1),
                ServiceDesk = new ServiceDesk()
                {
                    Id = 1, DeskName = "Service Desk"
                },
                InsertedBy   = UserNameOne,
                InsertedDate = dateTimeNow,
                UpdatedBy    = UserNameOne,
                UpdatedDate  = dateTimeNow,
            };

            #endregion

            #region Act

            var response = _serviceDomainService.Create(serviceDomain);

            #endregion

            #region Assert

            _mockServiceDomainRepository.Verify(x => x.Insert(It.IsAny <ServiceDomain>()), Times.Once());
            _mockUnitOfWork.Verify(x => x.Save(), Times.Exactly(1));

            Assert.IsNotNull(response);
            Assert.AreEqual(4, response);

            #endregion
        }
コード例 #2
0
        public ActionResult CreateAjaxServiceAddDomainGrid([DataSourceRequest] DataSourceRequest request,
                                                           [Bind(Prefix = "models")] IEnumerable <BulkServiceDomainViewModel> serviceDomains)
        {
            var inputDomains  = serviceDomains as IList <BulkServiceDomainViewModel> ?? serviceDomains.ToList();
            var outputDomains = new List <BulkServiceDomainViewModel>();

            if (ModelState.IsValid)
            {
                try
                {
                    var customerSpecificTypeThreshold = _parameterService.GetParameterByNameAndCache <int>(ParameterNames.CustomerSpecificTypeThreshold);

                    if (serviceDomains != null && inputDomains.Any())
                    {
                        var userName   = _contextManager.UserManager.Name;
                        var now        = DateTime.Now;
                        var customerId = _appUserContext.Current.CurrentCustomer.Id;

                        // Make sure all the of the specified service desks exist.
                        var checkServiceDeskIds = inputDomains
                                                  .Where(w => w.ServiceDeskId.HasValue)
                                                  .Select(s => s.ServiceDeskId.Value)
                                                  .Distinct()
                                                  .ToList();
                        var serviceDeskIds = _serviceDeskService.GetByCustomer(customerId)
                                             .Where(w => checkServiceDeskIds.Contains(w.Id))
                                             .Select(s => s.Id)
                                             .ToList();

                        foreach (var inputDomain in inputDomains)
                        {
                            if (!inputDomain.ServiceDeskId.HasValue ||
                                inputDomain.ServiceDeskId == 0 ||
                                inputDomain.DomainTypeId == 0 ||
                                !serviceDeskIds.Contains(inputDomain.ServiceDeskId.Value))
                            {
                                continue;
                            }

                            var diagramDisplayOrder = inputDomain.DiagramOrder ?? 5;
                            if (diagramDisplayOrder < 1)
                            {
                                diagramDisplayOrder = 5;
                            }
                            var newServiceDomain = new ServiceDomain
                            {
                                AlternativeName = inputDomain.AlternativeName,
                                DiagramOrder    = diagramDisplayOrder,
                                DomainTypeId    = inputDomain.DomainTypeId,
                                ServiceDeskId   = inputDomain.ServiceDeskId.Value,
                                InsertedBy      = userName,
                                InsertedDate    = now,
                                UpdatedBy       = userName,
                                UpdatedDate     = now
                            };
                            newServiceDomain.Id = _serviceDomainService.Create(newServiceDomain);
                            outputDomains.Add(Mapper.Map <BulkServiceDomainViewModel>(newServiceDomain));

                            var domainType = _domainTypeRefDataService.GetById(inputDomain.DomainTypeId);
                            if (!domainType.Visible && _domainTypeRefDataService.GetNumberOfDomainTypeReferences(inputDomain.DomainTypeId) >= customerSpecificTypeThreshold)
                            {
                                domainType.Visible = true;
                                _domainTypeRefDataService.Update(domainType);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _contextManager.ResponseManager.StatusCode = 500;
                    _contextManager.ResponseManager.AppendHeader(ModelStateErrorNames.ErrorMessage, ex.Message);
                }
            }

            return(Json(outputDomains.ToDataSourceResult(request, ModelState)));
        }