public IActionResult Drawing([FromBody] DrawingModel drawing) { var numbers = drawing.DrawnNumbers.Split(',').Select(Int32.Parse).ToList(); if (numbers.Count != numbers.Distinct().Count()) { return(BadRequest("You got duplicates. Fix it")); } _adminService.PublishNumbers(drawing); _userService.FindWinners(); _adminService.StartSession(); return(Ok("Numbers are published.")); }
public ActionResult SubDrawingDetail(DrawingModel drawing) { using (DrawingContext context = new DrawingContext()) { Drawing editDrawing = context.Drawing.FirstOrDefault(u => u.Drawing_id == drawing.Drawing_id); if (editDrawing == null) { Drawing addrawing = new Drawing() { Drawing_id = Guid.NewGuid().ToString(), Drawing_author = drawing.Drawing_author, Drawing_title = drawing.Drawing_title, Drawing_time = DateTime.Now, Drawing_type = drawing.Drawing_type, Drawing_mine = drawing.Drawing_mine, }; context.Drawing.Add(addrawing); } else { editDrawing.Drawing_id = drawing.Drawing_id; editDrawing.Drawing_title = drawing.Drawing_title; editDrawing.Drawing_author = drawing.Drawing_author; editDrawing.Drawing_time = DateTime.Now; editDrawing.Drawing_type = drawing.Drawing_type; editDrawing.Drawing_mine = drawing.Drawing_mine; } int flg = context.SaveChanges(); if (flg > 0) { return(Json(new { Success = true, Message = "操作成功" })); } return(Json(new { Success = false, Message = "操作失败" })); } }
public PencilCommand(DrawingModel model, DrawingAction action) { _model = model; _action = action; }
// This is a constructor method for the DrawIt class. Notice that it has the same name ("DrawIt") as the class, // and does not have a return type. That's how we know it's a constructor method. public DrawIt() { // This may look familiar from last week's "create a Windows Forms application" assignment. // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form. InitializeComponent(); // This line creates a SimpleDrawActionSource(), which is a class that very minimally // implements IUndoRedoActionSource with an action type of IDrawAction. // This won't support Undo or Redo, so the buttons will always be disabled, but it // will allow us to use the interface (since it has been implemented), and later we can // replace it with a more advanced implementation. _actions = new SimpleActionSource<IDrawAction>(); // This line creates a BrokenDrawActionSource(), with the behavior // we saw at the beginning of class (in DrawIt 1.0). It appears to // allow Undo and Redo, but if you Undo some actions and then // start drawing more circles, it redraws the undone actions // before it starts drawing the new circles. //_actions = new BrokenActionSource<IDrawAction>(); // Homework: Create an actual UndoRedoDrawActionSource() and make sure // that it has the proper Undo() and Redo() semantics. //_actions = new UndoRedoDrawActionSource(); _actions= new UndoRedoActionSource<IDrawAction>(); // This line says, "I want to listen to ActionsChanged events from this IActionSource. // Every time the ActionsChanged event happens, I want my UpdateUi() method to be called. // // Note the use of "+=" instead of "=". That's how delegates are assigned to events. Instead // of using "=", which would imply that only one delegate could listen to an event, we use "+=", // which basically says "Add my UpdateUi method as a listener to this event, along with any other // listeners who are listening to this event." This is a good thing, because while we're listening // to the ActionsChanged event to update our UI, the DrawingModel will be listening to the same // ActionsChanged event to know when to redraw. // // Note also that I did *NOT* put parentheses after the "UpdateUi" in the line below. Parentheses // indicate a method call -- that I'm actually invoking the method. In this line, I'm NOT invoking // UpdateUi. Instead, I'm talking about it. I'm actually giving the event a reference to the method, // rather than calling the method. I'm treating "UpdateUi" as if it were just another value, to be // assigned. This is one of the great things about C#: a method can be treated as just another value, // assigned to a variable, passed around to another method as a parameter, etc. It's a very powerful // and advanced language feature, which we're using here to set up our "UpdateUi" method as a listener // ("delegate") on the ActionsChanged event of our actions model. _actions.ActionsChanged += UpdateUi; // This adds ANOTHER event handler ("event listener") on the ActionsChanged // event of the _actions object. When the _actions object fires its // ActionsChanged event, it will also call UpdateClearButton() _actions.ActionsChanged += UpdateClearButton; // This line creates a new DrawingModel which wraps around and encapsulates // the CanvasPanel, and then stores that DrawingModel into the instance variable // _canvasModel. // // Since _canvasModel is an "instance variable" (declared as part of the DrawIt // class, above), all of the "instance methods" here in DrawIt (also declared as // part of the DrawIt class) will be able to see it. Anything that wants to draw // something on the canvas can say _canvasModel.DrawLine() or _canvasModel.DrawCircle() or... // // I have implemented versions of HandleMouseDown() and HandleMouseMoved() below // that draw simple circles on the canvas, and a circular cursor to show where // the next circle will be drawn, to illustrate how to use the DrawingModel. _canvasModel = new DrawingModel(CanvasPanel, _actions) { Background = new DrawBackgroundAction(_BACKGROUND_COLOR) }; // This creates the Pen intance that draws lines on the canvas. _pen = new Pen(_COLOR, _LINE_WIDTH); // This creates the Pen instance that draws the cursor. _cursorPen = new Pen(_CURSOR_COLOR, _LINE_WIDTH); // This starts us out with a dark gray background on the canvas (so the user can see // where to draw). Clear(); // These three lines add "event handlers" to the canvas so that we get told when the user // does something with the mouse. An "event handler" is just a method that knows how to // respond to an event (something that happened). You can watch the extra session from // this Thursday if you want to see how to create a method like this. CanvasPanel.MouseDown += HandleMouseDown; CanvasPanel.MouseUp += HandleMouseUp; CanvasPanel.MouseMove += HandleMouseMoved; CanvasPanel.MouseLeave += HandleMouseLeave; }
public DrawingPresenter(IView _drawingView) { drawingView = _drawingView; _model = new DrawingModel(); printDialog = new PrintDialog(); pd = new PrintDocument(); ppd = new PrintPreviewDialog(); ppd.Document = pd; printDialog.Document = pd; pd.DefaultPageSettings.Landscape = true; pd.PrintPage += Pd_PrintPage; drawingView.Print += (object o, EventArgs e) => { if (printDialog.ShowDialog() == DialogResult.OK) { pd.Print(); } }; drawingView.Preview += (object o, EventArgs e) => { ppd.ShowDialog(); }; drawingView.LoadFile += DrawingView_LoadFile; drawingView.CreateNewFile += DrawingView_CreateNewFile; drawingView.SaveCreatedFile += DrawingView_SaveCreatedFile; drawingView.CloseFile += (bool b) => { _model.crrStream?.Close(); drawingView.CurrentFileName = ""; drawingView.TableTxt = ""; if (b == true) { _model.gr.GraphCurves.Clear(); } }; drawingView.InitGraphic += (object s, EventArgs e) => { _model.Init(drawingView.graph); InitCurvesNames(); }; drawingView.PlotAction += DrawingView_PlotAction; drawingView.PlotMouseDown += (object o, MouseEventArgs e) => { _model.PrimaryParamsInit(e.Location); drawingView.graph.Cursor = Cursors.SizeAll; }; drawingView.PlotMouseUp += (object o, MouseEventArgs e) => drawingView.graph.Cursor = Cursors.Default; drawingView.ApdateCurvesList += DrawingView_PlotAction; drawingView.FillCurveFields += (string s) => { foreach (Curves c in _model.gr.GraphCurves) { if (c.Legend == s) { drawingView.CurveColor = c.CurveColor; drawingView.DotsSettings = c.DotsType; drawingView.Thikness = c.CurveThickness; if (c.DashStyle == System.Drawing.Drawing2D.DashStyle.Dash) { drawingView.dashStyle = DashStyle.Dash; } else if (c.DashStyle == System.Drawing.Drawing2D.DashStyle.DashDot) { drawingView.dashStyle = DashStyle.DashDot; } else if (c.DashStyle == System.Drawing.Drawing2D.DashStyle.DashDotDot) { drawingView.dashStyle = DashStyle.DashDotDot; } else if (c.DashStyle == System.Drawing.Drawing2D.DashStyle.Dot) { drawingView.dashStyle = DashStyle.Dot; } else { drawingView.dashStyle = DashStyle.Solid; } } } }; drawingView.SetCurveColor += (object o, EventArgs e) => { using (ColorDialog cd = new ColorDialog()) { cd.Color = drawingView.CurveColor; DialogResult res = cd.ShowDialog(); if (res == DialogResult.OK) { drawingView.CurveColor = cd.Color; } } }; drawingView.ShowCurvePoints += (string s) => { drawingView.TableTxt = _model.ShowCurvePoints(s); }; drawingView.AddNewCurve += DrawingView_PlotAction; drawingView.Zoom += DrawingView_PlotAction; drawingView.InitDiagramParams += (object s, EventArgs e) => { drawingView.Title = _model.gr.Title; drawingView.TitlePos = _model.gr.TitlePosition; drawingView.TitleSize = _model.gr.TitleSize; drawingView.OXName = _model.gr.Config.OXName; drawingView.OXSize = _model.gr.Config.OXNameSize; drawingView.OXPos = _model.gr.Config.OXNamePosition; drawingView.OXPrice = _model.gr.Config.PriceForPointOX; drawingView.OYName = _model.gr.Config.OYName; drawingView.OYSize = _model.gr.Config.OYNameSize; drawingView.OYPos = _model.gr.Config.OYNamePosition; drawingView.OYPrice = _model.gr.Config.PriceForPointOY; drawingView.Grid = _model.gr.Config.Grid; drawingView.Smooth = _model.gr.Config.SmoothAngles; }; drawingView.ApdateDiagramParams += (object s, EventArgs e) => { _model.gr.Title = drawingView.Title; _model.gr.TitlePosition = drawingView.TitlePos; _model.gr.TitleSize = (int)drawingView.TitleSize; _model.gr.Config.OXName = drawingView.OXName; _model.gr.Config.OXNamePosition = drawingView.OXPos; _model.gr.Config.OXNameSize = drawingView.OXSize; _model.gr.Config.PriceForPointOX = drawingView.OXPrice; _model.gr.Config.OYName = drawingView.OYName; _model.gr.Config.OYNamePosition = drawingView.OYPos; _model.gr.Config.OYNameSize = drawingView.OYSize; _model.gr.Config.PriceForPointOY = drawingView.OYPrice; _model.gr.Config.Grid = drawingView.Grid; _model.gr.Config.SmoothAngles = drawingView.Smooth; }; drawingView.DrawSpiral += (bool b) => { PointF[] pt = _model.GenerateSpiral(drawingView.OmegaSpiral, drawingView.CoefSpiral, drawingView.StartSpiral, drawingView.LenghtSpiral, b); _model.ShowCreatedSpiral(pt); }; drawingView.SpiralAction += (bool b) => { _model.SpiralAction(b); if (b) { InitCurvesNames(); } }; }
public DrawingViewModel(DrawingModel drawingModel) { _drawingModel = drawingModel; }
public Button(DrawingModel drawingModel) { _drawingModel = drawingModel; }
public DrawingCommander(DrawingModel model) { _model = model; _undoCommands = new Stack <IDrawingCommand>(); _redoCommands = new Stack <IDrawingCommand>(); }
// This is a constructor method for the DrawIt class. Notice that it has the same name ("DrawIt") as the class, // and does not have a return type. That's how we know it's a constructor method. public DrawIt() { // This may look familiar from last week's "create a Windows Forms application" assignment. // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form. InitializeComponent(); _actions = new UndoRedoActionSource<IDrawAction>(); _actions.ActionsChanged += UpdateUi; _actions.ActionsChanged += UpdateClearButton; _canvasModel = new DrawingModel(CanvasPanel, _actions) { Background = new DrawBackgroundAction(_BACKGROUND_COLOR) }; // This creates the Pen intance that draws lines on the canvas. _drawingPen = new Pen(_COLOR, _LINE_WIDTH); // This creates the Pen instance that draws the cursor. _cursorPen = new Pen(_CURSOR_COLOR, _LINE_WIDTH); //_brush = new SolidBrush(_COLOR); _brush = new SolidBrush(_COLOR); // This starts us out with a dark gray background on the canvas (so the user can see // where to draw). Clear(); // These three lines add "event handlers" to the canvas so that we get told when the user // does something with the mouse. An "event handler" is just a method that knows how to // respond to an event (something that happened). You can watch the extra session from // this Thursday if you want to see how to create a method like this. CanvasPanel.MouseDown += HandleMouseDown; CanvasPanel.MouseUp += HandleMouseUp; CanvasPanel.MouseMove += HandleMouseMoved; CanvasPanel.MouseLeave += HandleMouseLeave; KeyDown += HandleKeyDown; }