public ActionResult Create([Bind(Include = "ID,Name,ServerName,UserId,Password,AppUserId,DBType")] Server server) { ConnectionState validateConnection = SharedLib.CheckConnection(server); if (validateConnection == ConnectionState.Open) { server.AppUserId = User.Identity.GetUserName(); db.Servers.Add(server); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Connection can not be established."); ViewBag.DBType = new SelectList(db.DataBaseTypes, "DataBaseTypes", "DataBaseTypes", server.DBType); return(View(server)); } if (ModelState.IsValid) { db.Servers.Add(server); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DBType = new SelectList(db.DataBaseTypes, "DataBaseTypes", "DataBaseTypes", server.DBType); return(View(server)); }
private static bool CreateImage(string subPath, string cachePath, object options) { var img = new Image <Rgb24>(512, 512); img.Mutate(ctx => ctx.Clear(Color.White)); var blackBrush = Brushes.Solid(Color.Black); var whiteBrush = Brushes.Solid(Color.White); var charsX = "12345678"; var charsY = "ABCDEFGH"; var font = new Font(SharedLib.DefaultFontFamily(), 56f, FontStyle.Regular); for (var y = 0; y < 8; y++) { for (var x = 0; x < 8; x++) { var box = new Rectangle(x * 64, y * 64, 64, 64); var label = (string)charsY[y].ToString() + charsX[x].ToString(); var evenX = x % 2 == 0; var evenY = y % 2 == 0; var black = evenX; if (evenY) { black = !black; } if (black) { img.Mutate(ctx => ctx.Fill(blackBrush, box)); } var fontColor = black ? Color.White : Color.Black; var gfxOptions = new TextGraphicsOptions { TextOptions = new TextOptions { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, }, }; img.Mutate(ctx => ctx.DrawText(gfxOptions, label, font, fontColor, new PointF(box.X + 32, box.Y + 32))); } } img.Save(cachePath); return(true); }