public void showchart() { main.Visible = false; bm = AForm.bm; //메인-주문 컨트롤러에서 저장한 구매 데이터를 메인-통계 컨트롤러로 이동 chart = new Chart(); chart.Show(); }
public IHttpActionResult DoWork() { int tempId = 0; try { using (var scope = new TransactionScope()) { var a = new AModel { BValue1 = Guid.NewGuid().ToString() }; var b = new BModel { BValue1 = Guid.NewGuid().ToString() }; _contextA.ATable.Add(a); _contextA.SaveChanges(); tempId = a.Id; throw new Exception(); _contextB.BTable.Add(b); _contextB.SaveChanges(); scope.Complete(); } } catch { return(Ok($"Id A supposed to get - {tempId}")); } }
static void Main(string[] args) { ILogger logger = LogManager.GetCurrentClassLogger(); IUnityContainer unitycontainer = new UnityContainer(); // 建立物件 unitycontainer.RegisterTypes( AllClasses.FromLoadedAssemblies(), WithMappings.FromMatchingInterface, WithName.Default, WithLifetime.Hierarchical); unitycontainer.RegisterInstance <ILogger>(logger); // 注入 IClass1 class1 = unitycontainer.Resolve <IClass1>(); //IClass class2 = new Class1(logger); class1.Log(); var config = new MapperConfiguration(cfg => { cfg.AddProfile <BModelProfile>(); }); var mapper = config.CreateMapper(); var amodel = new AModel { Name = "Jeff", No = 123 }; BModel bmodel = mapper.Map <BModel>(amodel); }
public IActionResult Delete(int id) { BModel bModel = _context.BModels.Find(id); if (bModel == null) { return(NotFound()); } _context.BModels.Remove(bModel); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public IHttpActionResult CreateItemsEach() { using (var scope = new TransactionScope()) { var a = new AModel { BValue1 = Guid.NewGuid().ToString() }; var b = new BModel { BValue1 = Guid.NewGuid().ToString() }; _contextA.ATable.Add(a); _contextA.SaveChanges(); _contextB.BTable.Add(b); _contextB.SaveChanges(); scope.Complete(); return(Ok($"A Id - {a.Id}, B Id - {b.Id}")); } }
static void Main(string[] args) { ILogger logger = LogManager.GetCurrentClassLogger(); IUnityContainer unitycontainer = new UnityContainer(); //unitycontainer.RegisterType<IClass, Class1>(); //注入 unitycontainer.RegisterInstance <ILogger>(logger);//跟上面一樣用意 IClass IClassToDo = unitycontainer.Resolve <Class1>(); //IClass class1 = new Class1(logger) ; //同上 unitycontainer.RegisterTypes( AllClasses.FromLoadedAssemblies(), WithMappings.FromMatchingInterface, WithName.Default, WithLifetime.Hierarchical); //自動注入 IClassToDo.Log(); var config = new MapperConfiguration(cfg => { cfg.AddProfile <BModelProfile>(); }); var mapper = config.CreateMapper(); var amodel = new AModel { Name = "Jeff", No = 123 }; BModel bmodel = mapper.Map <BModel>(amodel); //Interface裡面宣告AA函式 //Class1去接IClass //在program裡面呼叫Interface實作 }
//練習一的程式碼註解 //private static Logger logger = LogManager.GetCurrentClassLogger(); static void Main(string[] args) { //--------練習三的程式碼註解---------------------------------------------------------------- ILogger logger = LogManager.GetCurrentClassLogger(); IUnityContainer unitycontainer = new UnityContainer(); // 建立物件 unitycontainer.RegisterTypes( //Unity的設定 AllClasses.FromLoadedAssemblies(), WithMappings.FromMatchingInterface, WithName.Default, WithLifetime.Hierarchical ); unitycontainer.RegisterInstance <ILogger>(logger); // 注入 客制的注入要再自動地注入後面。 IClass2 result = unitycontainer.Resolve <IClass2>(); //取得實作 result.DemoMethod(); //--------練習二的程式碼註解---------------------------------------------------------------- //ILogger logger = LogManager.GetCurrentClassLogger(); //IClass2 class1 = new Class2(logger); //class1.DemoMethod(); //--------練習一的程式碼註解---------------------------------------------------------------- //logger.Trace("我是追蹤:Trace"); //logger.Debug("我是偵錯:Debug"); //logger.Info("我是資訊:Info"); //logger.Warn("我是警告:Warn"); //logger.Error("我是錯誤:error"); //logger.Fatal("我是致命錯誤:Fatal"); //automapper未使用時的程式碼----------------------------------------- var amodel = new AModel { Name = "Jeff", No = 123 }; var bmodel = new BModel { Name = amodel.Name, No = amodel.No }; //automapper未使用時的程式碼----------------------------------------- //加了auto----------------------------------- var config = new MapperConfiguration(cfg => cfg.CreateMap <AModel, BModel>()); var mapper = config.CreateMapper(); var amodel2 = new AModel { Name = "Jeff", No = 123 }; var bmodel3 = mapper.Map <BModel>(amodel2); //加了auto----------------------------------- //透過AddProfile增加多組mapping---------------------------------------- var config2 = new MapperConfiguration(cfg => { cfg.CreateMap <AModel, BModel>(); cfg.AddProfile <BModelProfile>(); }); var mapper2 = config2.CreateMapper(); var amodel4 = new AModel { Name = "Jeff", No = 123 }; var bmodel4 = mapper.Map <BModel>(amodel4); //透過AddProfile增加多組mapping---------------------------------------- }
public AModel() { BModel = new BModel(); CModel = new CModel(); }