public void IntsToEntities() { WindsorRegistrar.RegisterSingleton(typeof(IRepo <>), typeof(Repo <>)); WindsorRegistrar.RegisterSingleton(typeof(IDbContextFactory), typeof(DbContextFactory)); using (var scope = new TransactionScope()) { var repo = new Repo <Meal>(new DbContextFactory()); var meal1 = new Meal { Name = "a" }; var meal2 = new Meal { Name = "b" }; meal1 = repo.Insert(meal1); meal2 = repo.Insert(meal2); repo.Save(); var dinnerInput = new DinnerInput { Meals = new int[] { meal1.Id, meal2.Id } }; var dinner = new Dinner(); dinner.InjectFrom <IntsToEntities>(dinnerInput); Assert.IsNotNull(dinner.Meals); Assert.AreEqual(2, dinner.Meals.Count); Assert.AreEqual(meal1.Id, dinner.Meals.First().Id); } }
public void IntsToEntities() { WindsorRegistrar.RegisterSingleton(typeof(IReadRepo <>), typeof(ReadRepo <>)); WindsorRegistrar.RegisterSingleton(typeof(IDbContextFactory), typeof(DbContextFactory)); using (var scope = new TransactionScope()) { var repo = new Repo <Meal>(new DbContextFactory()); var m1 = new Meal { Name = "a" }; var m2 = new Meal { Name = "b" }; repo.Insert(m1); repo.Insert(m2); repo.Save(); var s = new DinnerInput { Meals = new List <int> { m1.Id, m2.Id } }; var t = new Dinner(); t.InjectFrom <IntsToEntities>(s); Assert.IsNotNull(t.Meals); Assert.AreEqual(2, t.Meals.Count); Assert.AreEqual(m1.Id, t.Meals.First().Id); } }
public void NormalToNullables() { var dinner = new Dinner { ChefId = 3 }; var dinnerInput = new DinnerInput(); dinnerInput.InjectFrom<NormalToNullables>(dinner); Assert.AreEqual(3, dinnerInput.ChefId); Assert.AreEqual(null, dinnerInput.Start); Assert.AreEqual(null, dinnerInput.CountryId); }
public void NullablesToNormal() { var dinnerInput = new DinnerInput { ChefId = 3 }; var dinner = new Dinner(); dinner.InjectFrom<NullablesToNormal>(dinnerInput); Assert.AreEqual(3, dinner.ChefId); Assert.AreEqual(0, dinner.CountryId); Assert.AreEqual(default(DateTime), dinner.Start); }
public void EntitiesToIntsTest() { var dinner = new Dinner { Meals = new List<Meal> { new Meal { Id = 3 }, new Meal { Id = 7 } } }; var dinnerInput = new DinnerInput(); dinnerInput.InjectFrom<EntitiesToInts>(dinner); Assert.IsNotNull(dinnerInput.Meals); Assert.AreEqual(2, dinnerInput.Meals.Count()); Assert.AreEqual(3, dinnerInput.Meals.First()); }
public void NullablesToNormal() { var dinnerInput = new DinnerInput { ChefId = 3 }; var dinner = new Dinner(); dinner.InjectFrom <NullablesToNormal>(dinnerInput); Assert.AreEqual(3, dinner.ChefId); Assert.AreEqual(0, dinner.CountryId); Assert.AreEqual(default(DateTime), dinner.Start); }
public void NormalToNullables() { var dinner = new Dinner { ChefId = 3 }; var dinnerInput = new DinnerInput(); dinnerInput.InjectFrom <NormalToNullables>(dinner); Assert.AreEqual(3, dinnerInput.ChefId); Assert.AreEqual(null, dinnerInput.Start); Assert.AreEqual(null, dinnerInput.CountryId); }
public void NormalToNullables() { var d = new Dinner { ChefId = 3 }; var di = new DinnerInput(); di.InjectFrom <NormalToNullables>(d); Assert.AreEqual(3, di.ChefId); Assert.AreEqual(null, di.Date); Assert.AreEqual(null, di.CountryId); }
public ActionResult Edit(int id) { var m = Db.Dinners.SingleOrDefault(o => o.Id == id); if (m == null) { throw new AwesomeDemoException("this item doesn't exist anymore"); } var vm = new DinnerInput { Id = m.Id, Name = m.Name, Chef = m.Chef.Id, Date = m.Date, Meals = m.Meals.Select(o => o.Id) }; return(View("create", vm)); }
public ActionResult Edit(int id) { var dinner = Db.Get <Dinner>(id); var input = new DinnerInput { Id = dinner.Id, Name = dinner.Name, Chef = dinner.Chef.Id, Date = dinner.Date, Meals = dinner.Meals.Select(o => o.Id), BonusMealId = dinner.BonusMeal.Id }; return(PartialView("Create", input)); }
public ActionResult Create(DinnerInput input) { //if (!ModelState.IsValid) return PartialView(input); //var dinner = Db.Insert(new Dinner //{ // Name = input.Name, // Date = input.Date.Value, // Chef = Db.Get<Chef>(input.Chef), // Meals = Db.Meals.Where(o => input.Meals.Contains(o.Id)), // BonusMeal = Db.Get<Meal>(input.BonusMealId) //}); //return Json(MapToGridModel(dinner)); // returning grid model, used in grid.api.renderRow return(View()); }
public ActionResult Edit(DinnerInput input) { if (!ModelState.IsValid) { return(View("create", input)); } var dinner = Db.Get <Dinner>(input.Id); dinner.Name = input.Name; dinner.Date = input.Date.Value; dinner.Chef = Db.Get <Chef>(input.Chef); dinner.Meals = Db.Meals.Where(m => input.Meals.Contains(m.Id)); Db.Update(dinner); return(Json(new { dinner.Id, Content = this.RenderPartialView("ListItems/Dinner", new[] { dinner }) })); }
public ActionResult Create(DinnerInput input) { if (!ModelState.IsValid) { return(View(input)); } var dinner = Db.Insert(new Dinner { Name = input.Name, Date = input.Date.Value, Chef = Db.Get <Chef>(input.Chef), Meals = Db.Meals.Where(o => input.Meals.Contains(o.Id)) }); return(Json(new { Content = this.RenderView("ListItems/Dinner", new[] { dinner }) })); }
public ActionResult Edit(DinnerInput input) { if (!ModelState.IsValid) { return(PartialView("Create", input)); } var dinner = Db.Get <Dinner>(input.Id); dinner.Name = input.Name; dinner.Date = input.Date.Value; dinner.Chef = Db.Get <Chef>(input.Chef); dinner.Meals = Db.Meals.Where(m => input.Meals.Contains(m.Id)); dinner.BonusMeal = Db.Get <Meal>(input.BonusMealId); Db.Update(dinner); // returning the key to call grid.api.update return(Json(new { Id = dinner.Id })); }
public ActionResult Create(DinnerInput input) { if (!ModelState.IsValid) { return(PartialView(input)); } var dinner = Db.Insert(new Dinner { Name = input.Name, Date = input.Date.Value, Chef = Db.Get <Chef>(input.Chef), Meals = input.Meals.Select(mid => Db.Get <Meal>(mid)), BonusMeal = Db.Get <Meal>(input.BonusMealId) }); return(Json(MapToGridModel(dinner))); // returning grid model, used in grid.api.renderRow }
public void EntitiesToIntsTest() { var dinner = new Dinner { Meals = new List <Meal> { new Meal { Id = 3 }, new Meal { Id = 7 } } }; var dinnerInput = new DinnerInput(); dinnerInput.InjectFrom <EntitiesToInts>(dinner); Assert.IsNotNull(dinnerInput.Meals); Assert.AreEqual(2, dinnerInput.Meals.Count()); Assert.AreEqual(3, dinnerInput.Meals.First()); }
public ActionResult Edit(DinnerInput input) { if (ModelState.IsValid) { var dinner = Db.Get <Dinner>(input.Id); dinner.Name = input.Name; dinner.Date = input.Date.Value; dinner.Chef = Db.Get <Chef>(input.Chef); dinner.Meals = input.Meals.Select(mid => Db.Get <Meal>(mid)); dinner.BonusMeal = Db.Get <Meal>(input.BonusMealId); dinner.Organic = input.Organic ?? false; Db.Update(dinner); return(Json(new { })); } return(Json(ModelState.GetErrorsInline())); }
public ActionResult Create(DinnerInput input) { if (ModelState.IsValid) { var dinner = new Dinner { Name = input.Name, Date = input.Date.Value, Chef = Db.Get <Chef>(input.Chef), Meals = input.Meals.Select(mid => Db.Get <Meal>(mid)), BonusMeal = Db.Get <Meal>(input.BonusMealId), Organic = input.Organic ?? false }; Db.Insert(dinner); return(Json(new { Item = MapToGridModel(dinner) })); } return(Json(ModelState.GetErrorsInline())); }
public void IntsToEntities() { WindsorRegistrar.RegisterSingleton(typeof(IRepo<>), typeof(Repo<>)); WindsorRegistrar.RegisterSingleton(typeof(IDbContextFactory), typeof(DbContextFactory)); using (var scope = new TransactionScope()) { var repo = new Repo<Meal>(new DbContextFactory()); var meal1 = new Meal { Name = "a" }; var meal2 = new Meal { Name = "b" }; meal1 = repo.Insert(meal1); meal2 = repo.Insert(meal2); repo.Save(); var dinnerInput = new DinnerInput { Meals = new int[] { meal1.Id, meal2.Id } }; var dinner = new Dinner(); dinner.InjectFrom<IntsToEntities>(dinnerInput); Assert.IsNotNull(dinner.Meals); Assert.AreEqual(2, dinner.Meals.Count); Assert.AreEqual(meal1.Id, dinner.Meals.First().Id); } }