public void ParameterService_Create_NewParameterEntityPassed_IsAddedToCollection() { var p = UnitTestHelper.GenerateRandomData <Parameter>(x => x.Name = "XXX"); _parameterService.Create(p); Assert.IsTrue(_parameters.Any(x => x.Name == "XXX")); }
/// <summary> /// 添加参数 /// </summary> /// <param name="model"></param> /// <returns></returns> public HttpResponseMessage Post(ParameterModel model) { if (String.IsNullOrEmpty(model.Name) || model.Id == 0) { return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据异常!"))); } var entity = new ParameterEntity { Category = _categoryService.GetCategoryById(model.Id),//添加时候 这里的Id传的是分类ID Name = model.Name, Sort = model.Sort, AddTime = DateTime.Now, UpdTime = DateTime.Now, }; if (_parameterService.Create(entity).Id > 0) { return(PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功!"))); } return(PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败!"))); }