protected override void CleanOutItemFromStore(FooModel item) { using (var session = DocumentStore.OpenSession()) { var refitem = session.Load <FooModel>(item.ID.ToString()); session.Delete(refitem); session.SaveChanges(); } }
protected override void CleanOutItemFromStore(FooModel item) { using (var conn = NewConnection()) { var cmdtext = "DELETE FROM FooModel WHERE ID = @ID"; var cmd = new SqlCommand(cmdtext, conn); cmd.ExecuteNonQuery(); } }
public FooModel(Foo myFoo) { this.Children = new HashSet <FooModel>(); FooId = myFoo.FooId; ParentId = myFoo.ParentId; Name = myFoo.Name; Foo2 = new FooModel(myFoo.Foo2); Childern = myFoo.Children.Select(c => new FooModel(c)); }
public ActionResult Index(FooModel model) { if (ModelState.IsValid) { // Do something with our model here return(View("Success", model)); } ViewBag.Wonders = GetWonderSelectList(model.Wonder); return(View("Index", model)); }
protected override void CleanOutItemFromStore(FooModel item) { try { _dbset.Remove(item); this.SaveChanges(); } catch (Exception) { } }
public HttpResponseMessage Get(CancellationToken cancellationToken) { FooModel data = new FooModel { MyProperty = "bar" }; HttpResponseMessage message = this.Request.CreateResponse(HttpStatusCode.OK, data); return(message); }
public void GetModelFromViewPageStronglyTyped() { // Arrange ViewMasterPage <FooModel> vmp = new ViewMasterPage <FooModel>(); ViewPage vp = new ViewPage(); vmp.Page = vp; FooModel model = new FooModel(); vp.ViewData = new ViewDataDictionary(model); // Assert Assert.AreEqual(model, vmp.Model); }
//----------------------------------------------------------------------------------------- /// <summary> /// 新增 /// </summary> /// <param name="model">The model.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public async Task <IResult> InsertAsync(FooModel model) { var stepName = $"{nameof(RedisFooRepository)}.{nameof(this.InsertAsync)}"; using (ProfilingSession.Current.Step(stepName)) { var result = await this.FooRepository.InsertAsync(model); this.RemoveCacheItem($"{CachekeyPrefix}{Cachekeys.Foo.Exists.ToFormat(model.FooId)}"); this.RemoveCacheItem($"{CachekeyPrefix}{Cachekeys.Foo.Get.ToFormat(model.FooId)}"); return(result); } }
public ActionResult Foo(FooModel model) { DateTime updatedDateTime; var dateTime = string.Format("{0} {1}", model.Date, model.Time); var isValid = DateTime.TryParse(dateTime, out updatedDateTime); if (!isValid) { ModelState.AddModelError("Time", "Please enter a valid Time."); return(View(model)); } // process updates return(View("Success")); }
/// <summary> /// 更新 /// </summary> /// <param name="model">The model.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public async Task <IResult> UpdateAsync(FooModel model) { var stepName = $"{nameof(CachedFooRepository)}.{nameof(this.UpdateAsync)}"; using (ProfilingSession.Current.Step(stepName)) { var result = await this.FooRepository.UpdateAsync(model); this.RemoveCacheItem(Cachekeys.Foo.Exists.ToFormat(model.FooId)); this.RemoveCacheItem(Cachekeys.Foo.Get.ToFormat(model.FooId)); return(result); } }
public async Task <FooModel> Post() { var key = Guid.NewGuid().ToString("N").Substring(0, 4); var value = Guid.NewGuid().ToString("N"); var model = new FooModel { Key = key, Value = value }; await _service.SetAsync(model); return(model); }
protected override FooModel GetItemById(long id) { using (var conn = NewConnection()) { var cmdtext = "SELECT * FROM FooModel WHERE ID = @ID"; var cmd = new SqlCommand(cmdtext, conn); var dr = cmd.ExecuteReader(); var hydrator = new EntityMemberResolver <FooModel>(); dr.Read(); var item = new FooModel(); hydrator.HydrateFromDictionary(item, hydrator.ConvertToDictionary(dr)); return(item); } }
public void ModelPropertyStronglyTypedViewPage() { // Arrange FooModel model = new FooModel(); ViewDataDictionary<FooModel> viewData = new ViewDataDictionary<FooModel>(model); ViewPage<FooModel> viewPage = new ViewPage<FooModel>(); viewPage.ViewData = viewData; // Act object viewPageModelObject = ((ViewPage)viewPage).Model; FooModel viewPageModelPerson = viewPage.Model; // Assert Assert.AreEqual(model, viewPageModelObject); Assert.AreEqual(model, viewPageModelPerson); }
public void InterceptorTest() { IServiceCollection services = new ServiceCollection(); services.AddTransient <IFoo, Foo>() .AddSingleton(new FooConfig { Name = "redis" }); IServiceProvider serviceProvider = services.BuildCastleDynamicProxyProvider(); IFoo foo = serviceProvider.GetService <IFoo>(); bool addFlag = foo.Add(new FooModel { Id = 1, Name = "test", Date = DateTime.Now }); foo.Delete(1); FooModel fooModel = foo.Get(1); }
public void ModelPropertyStronglyTypedViewPage() { // Arrange FooModel model = new FooModel(); ViewDataDictionary <FooModel> viewData = new ViewDataDictionary <FooModel>(model); ViewPage <FooModel> viewPage = new ViewPage <FooModel>(); viewPage.ViewData = viewData; // Act object viewPageModelObject = ((ViewPage)viewPage).Model; FooModel viewPageModelPerson = viewPage.Model; // Assert Assert.AreEqual(model, viewPageModelObject); Assert.AreEqual(model, viewPageModelPerson); }
public void Store_Should_Handle_Adding_Keyed_Model() { // GIVEN the foo system currently contains no foos. this.fooSystem.Foos.ShouldBeEmpty(); // GIVEN a patch document to store a foo called "test". var request = "{\"op\":\"add\",\"path\":\"/foos/test\",\"value\":{\"number\":3,\"bazzed\":true}}"; var operation = JsonConvert.DeserializeObject <Operation <FooSystemModel> >(request); var patchDocument = new JsonPatchDocument <FooSystemModel>( new[] { operation }.ToList(), new CamelCasePropertyNamesContractResolver()); // WHEN we apply this patch document to the foo system model. patchDocument.ApplyTo(this.fooSystem); // THEN the system model should now contain a new foo called "test" with the expected properties. this.fooSystem.Foos.ShouldHaveSingleItem(); FooModel foo = this.fooSystem.Foos["test"] as FooModel; foo.Number.ShouldBe(3); foo.IsBazzed.ShouldBeTrue(); }
public void Store_Should_Handle_Removing_Keyed_Model() { // GIVEN the foo system currently contains a foo. var testFoo = new FooModel { Number = 3, IsBazzed = true }; this.fooSystem.Foos["test"] = testFoo; // GIVEN a patch document to remove a foo called "test". var request = "{\"op\":\"remove\",\"path\":\"/foos/test\"}"; var operation = JsonConvert.DeserializeObject <Operation <FooSystemModel> >(request); var patchDocument = new JsonPatchDocument <FooSystemModel>( new[] { operation }.ToList(), new CamelCasePropertyNamesContractResolver()); // WHEN we apply this patch document to the foo system model. patchDocument.ApplyTo(this.fooSystem); // THEN the system model should be empty. this.fooSystem.Foos.ShouldBeEmpty(); }
protected override void AddItemToStore(FooModel item) { var conn = NewConnection(); var sql = @"INSERT INTO FooModel ( ID, CreateDate, Title, Content ) VALUES ( @ID, @CreateDate, @Title, @Content )"; var cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@ID", item.ID); cmd.Parameters.Add("@CreateDate", item.CreateDate); cmd.Parameters.Add("@Title", item.Title); cmd.Parameters.Add("@Content", item.Content); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { IFoo foo = app.ApplicationServices.GetService <IFoo>(); bool addFlag = foo.Add(new FooModel { Id = 1, Name = "test", Date = DateTime.Now }); foo.Delete(1); FooModel fooModel = foo.Get(1); await context.Response.WriteAsync("Hello World!"); }); }); }
public void Store_Should_Handle_Modifying_Keyed_Model() { // GIVEN the foo system currently contains a foo. var originalFoo = new FooModel { Number = 3, IsBazzed = true }; this.fooSystem.Foos["test"] = originalFoo; // GIVEN a patch document to modify a foo called "test". var request = "{\"op\":\"replace\",\"path\":\"/foos/test\", \"value\":{\"number\":6,\"bazzed\":false}}"; var operation = JsonConvert.DeserializeObject <Operation <FooSystemModel> >(request); var patchDocument = new JsonPatchDocument <FooSystemModel>( new[] { operation }.ToList(), new CamelCasePropertyNamesContractResolver()); // WHEN we apply this patch document to the foo system model. patchDocument.ApplyTo(this.fooSystem); // THEN the system model should contain a modified "test" foo. this.fooSystem.Foos.ShouldHaveSingleItem(); FooModel foo = this.fooSystem.Foos["test"] as FooModel; foo.Number.ShouldBe(6); foo.IsBazzed.ShouldBeFalse(); }
public ActionResult Index(FooModel model) { return(View(model)); }
/// <summary> /// 更新 /// </summary> /// <param name="model">The model.</param> /// <returns> /// <c>true</c> if XXXX, <c>false</c> otherwise. /// </returns> /// <exception cref="System.ArgumentNullException">model</exception> public async Task <IResult> UpdateAsync(FooModel model) { var stepName = $"{nameof(FooRepository)}.UpdateAsync"; using (ProfilingSession.Current.Step(stepName)) { if (model.EqualNull()) { throw new ArgumentNullException(nameof(model)); } var exists = await this.IsExistsAsync(model.FooId); if (exists.Equals(false)) { return(new Result(false) { Message = "資料不存在" }); } using (var conn = (_databaseHelper.GetConnection(_databaseHelper.WLDOConnectionString))) { var sqlCommand = new StringBuilder(); sqlCommand.AppendLine(" begin tran "); sqlCommand.AppendLine(" Update [dbo].[Foo] "); sqlCommand.AppendLine(" SET "); sqlCommand.AppendLine(" Name = @Name ,"); sqlCommand.AppendLine(" Description = @Description ,"); sqlCommand.AppendLine(" Enable = @Enable ,"); sqlCommand.AppendLine(" UpdateTime = @UpdateTime "); sqlCommand.AppendLine(" WHERE FooId = @FooId "); sqlCommand.AppendLine(" commit "); var parameters = new DynamicParameters(); parameters.Add("FooId", model.FooId); parameters.Add("Name", model.Name.IsNullOrWhiteSpace() ? string.Empty : model.Name.Trim().Length > 50 ? model.Name.Trim().Substring(0, 50) : model.Name.Trim()); parameters.Add("Description", model.Description.IsNullOrWhiteSpace() ? string.Empty : model.Description.Trim().Length > 100 ? model.Description.Trim().Substring(0, 100) : model.Description.Trim()); parameters.Add("Enable", model.Enable); parameters.Add("UpdateTime", model.UpdateTime); var executeResult = await conn.ExecuteAsync ( sql : sqlCommand.ToString(), param : parameters ); IResult result = new Result(false); if (executeResult.Equals(1)) { result.Success = true; result.AffectRows = executeResult; return(result); } result.Message = "資料更新錯誤"; return(result); } } }
public JsonResult Foo(FooModel model) { string message = _ajaxService.Foo(model); return(Json(message)); }
public Task SetAsync(FooModel model) { Store.Add(model); return(Task.CompletedTask); }
public void DropDownListForUsesLambdaDefaultValueWithNullSelectListUsesViewData() { // Arrange FooModel model = new FooModel { foo = "Bravo" }; ViewDataDictionary<FooModel> vdd = new ViewDataDictionary<FooModel>(model) { { "foo", new SelectList(MultiSelectListTest.GetSampleStrings()) } }; HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(vdd); // Act MvcHtmlString html = helper.DropDownListFor(m => m.foo, selectList: null); // Assert Assert.Equal( "<select id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
protected override void AddItemToStore(FooModel item) { var collection = (MongoCollection <FooModel>)((IDataStore <FooModel>)DataStore).DataSet; collection.Insert(item); }
public PostsModel GetPosts(FooModel model) { return new PostsModel {Posts = repository.GetPosts().ToList() }; }
protected override void CleanOutItemFromStore(FooModel item) { ((IDictionary <string, FooModel>)DataStore.DataSet).Remove(item.ID.ToString()); }
protected override void AddItemToStore(FooModel item) { // cheating; should serialize to this.DataTable base.DataStore.Add(item); }
protected override void CleanOutItemFromStore(FooModel item) { this.DataTable.Rows.Clear(); }
/// <summary> /// 新增 /// </summary> /// <param name="model">The model.</param> /// <returns> /// <c>true</c> if XXXX, <c>false</c> otherwise. /// </returns> public async Task <IResult> InsertAsync(FooModel model) { var stepName = $"{nameof(FooRepository)}.InsertAsync"; using (ProfilingSession.Current.Step(stepName)) { if (model.EqualNull()) { throw new ArgumentNullException(nameof(model)); } using (var conn = (_databaseHelper.GetConnection(_databaseHelper.WLDOConnectionString))) { var sqlCommand = new StringBuilder(); sqlCommand.AppendLine("begin tran"); sqlCommand.AppendLine("INSERT INTO [dbo].[Foo]"); sqlCommand.AppendLine("("); sqlCommand.AppendLine(" [FooId],"); sqlCommand.AppendLine(" [Name],"); sqlCommand.AppendLine(" [Description],"); sqlCommand.AppendLine(" [Enable],"); sqlCommand.AppendLine(" [CreateTime],"); sqlCommand.AppendLine(" [UpdateTime] "); sqlCommand.AppendLine(")"); sqlCommand.AppendLine("VALUES"); sqlCommand.AppendLine("("); sqlCommand.AppendLine(" @FooId,"); sqlCommand.AppendLine(" @Name,"); sqlCommand.AppendLine(" @Description,"); sqlCommand.AppendLine(" @Enable,"); sqlCommand.AppendLine(" @CreateTime,"); sqlCommand.AppendLine(" @UpdateTime "); sqlCommand.AppendLine(");"); sqlCommand.AppendLine("commit"); var parameters = new DynamicParameters(); parameters.Add("FooId", model.FooId); parameters.Add("Name", model.Name.IsNullOrWhiteSpace() ? string.Empty : model.Name.Trim().Length > 50 ? model.Name.Trim().Substring(0, 50) : model.Name.Trim()); parameters.Add("Description", model.Description.IsNullOrWhiteSpace() ? string.Empty : model.Description.Trim().Length > 100 ? model.Description.Trim().Substring(0, 100) : model.Description.Trim()); parameters.Add("Enable", model.Enable); parameters.Add("CreateTime", model.CreateTime); parameters.Add("UpdateTime", model.UpdateTime); var executeResult = await conn.ExecuteAsync ( sql : sqlCommand.ToString(), param : parameters ); IResult result = new Result(false); if (executeResult.Equals(1)) { result.Success = true; result.AffectRows = executeResult; return(result); } result.Message = "資料新增錯誤"; return(result); } } }
protected override void AddItemToStore(FooModel item) { _dbset.Add(item); }
protected override void AddItemToStore(FooModel item) { ((IDictionary <string, FooModel>)DataStore.DataSet).Add(item.ID.ToString(), item); }
public void TestGetProperty() { FooModel model1 = new FooModel("foo1"); FooModel model2 = new FooModel("foo2"); Assert.IsTrue(model1.GetProperty(_ => _.Foo) == model2.GetProperty(_ => _.Foo)); }