public void ServiceComponentService_Create_NewEntity_AddedToRepository()
        {
            var newEntity = UnitTestHelper.GenerateRandomData <ServiceComponent>();

            _target.Create(newEntity);

            Assert.AreEqual(15, _serviceComponents.Count);
            Assert.IsTrue(_serviceComponents.Any(x => x.Id == newEntity.Id));
        }
Ejemplo n.º 2
0
        public ActionResult CreateAjaxServiceAddComponentLevel1Grid([DataSourceRequest] DataSourceRequest request,
                                                                    [Bind(Prefix = "models")] IEnumerable <BulkServiceComponentViewModel> serviceComponents)
        {
            try
            {
                if (_appUserContext.Current.CurrentCustomer != null &&
                    _appUserContext.Current.CurrentCustomer.Id > 0 &&
                    serviceComponents != null)
                {
                    var now      = DateTime.Now;
                    var userName = _contextManager.UserManager.Name;

                    var newComponents = new List <ServiceComponent>(serviceComponents
                                                                    .Where(x => x.ServiceFunctionId.HasValue &&
                                                                           x.ServiceFunctionId.Value != 0 &&
                                                                           !string.IsNullOrEmpty(x.ComponentName))
                                                                    .Select(x => new ServiceComponent
                    {
                        ComponentLevel    = (int)ServiceComponentLevel.Level1,
                        ComponentName     = x.ComponentName,
                        DiagramOrder      = x.DiagramOrder == null || x.DiagramOrder < 1 ? 5 : x.DiagramOrder.Value,
                        ServiceFunctionId = x.ServiceFunctionId.Value,
                        InsertedBy        = userName,
                        InsertedDate      = now,
                        UpdatedBy         = userName,
                        UpdatedDate       = now
                    }));

                    if (newComponents.Any())
                    {
                        _serviceComponentService.Create(newComponents);
                    }
                }
            }
            catch (Exception ex)
            {
                _contextManager.ResponseManager.StatusCode = 500;
                _contextManager.ResponseManager.AppendHeader(ModelStateErrorNames.ErrorMessage, ex.Message);
            }

            if (serviceComponents == null)
            {
                serviceComponents = new List <BulkServiceComponentViewModel>();
            }

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