public Canvas CreateCanvas(String name) { if (databaseContext.Canvases.Find(name) != null) { BadRequest("A canvas with this name already exists"); } Canvas newCanvas = new Canvas(); newCanvas.Name = name; newCanvas.Version = 1; databaseContext.Canvases.Add(newCanvas); databaseContext.SaveChanges(); CanvasImage canvasImage = new CanvasImage(); canvasImage.InitializeBitmap(); canvasImage.canvas = databaseContext.Canvases.Find(name); canvasImage.Name = name; databaseContext.CanvasImages.Add(canvasImage); databaseContext.SaveChanges(); return(newCanvas); }
public ActionResult Create([Bind(Include = "PlaceID,Name,Lat,Lng,Rate,Type")] Place place) { if (ModelState.IsValid) { db.Places.Add(place); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(place)); }
public ActionResult Create(Place place) { if (ModelState.IsValid) { db.Places.Add(place); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(place)); }
/// <summary> /// Helper method that applies any pixel changes between the image version and the latest version /// </summary> /// <param name="canvas">Which canvas to apply changes to</param> private void ApplyChangedPixelsToImage(CanvasImage canvasImage) { Canvas canvas = canvasImage.canvas; // Get changed pixels IEnumerable <PixelChange> pixelChanges = databaseContext.PixelChanges .Where(p => p.CanvasVersion > canvas.ImageVersion && p.Canvas.Name == canvas.Name) .OrderBy(p => p.CanvasVersion); if (!pixelChanges.Any()) { return; } // Update bitmap with changes Bitmap bitmap = canvasImage.GetBitmap(); foreach (PixelChange pixelChange in pixelChanges) { bitmap.SetPixel(pixelChange.X, pixelChange.Y, ColorTranslator.FromHtml(pixelChange.Color)); //placeContext.PixelChanges.Remove(pixelChange); } canvasImage.SetBitmap(bitmap); canvas.ImageVersion = pixelChanges.Last().CanvasVersion; databaseContext.SaveChanges(); }
public ActionResult Place(PlaceModel model) { if (ModelState.IsValid) { Place place = null; using (PlaceContext db = new PlaceContext()) { place = db.Places.FirstOrDefault(u => u.Email == model.Email); } if (place == null) { using (PlaceContext db = new PlaceContext()) { db.Places.Add(new Place { PlaceName = model.PlaceName, Website = model.Website, Email = model.Email, TypeOfPlace = model.TypeOfPlace, PhoneNumber = model.PhoneNumber }); db.SaveChanges(); place = db.Places.Where(u => u.Email == model.Email).FirstOrDefault(); } if (place != null) { return(RedirectToAction("Place", "Content")); } } } return(View(model)); }
public PixelChange SetPixelChange([FromUri] String canvasName, [FromBody] PixelChange pixelChange) { pixelChange.Canvas = databaseContext.Canvases.Find(canvasName); pixelChange.Canvas.Version++; pixelChange.CanvasVersion = pixelChange.Canvas.Version; databaseContext.PixelChanges.Add(pixelChange); databaseContext.SaveChanges(); return(pixelChange); }
public void AddPlace(Place place) { if (place == null) { throw new ArgumentNullException(nameof(place)); } placeContext.Places.Add(place); placeContext.SaveChanges(); }
public void DatabaseTest() { placeContext.Places.Add(new Place { Name = "Bar" }); placeContext.Places.Add(new Place { Name = "Restaurant" }); placeContext.SaveChanges(); var blogs = placeContext.Places.ToList(); Assert.AreEqual(2, blogs.Count); }
private void SetupDefaultValuesInDb() { placeContext.Places.Add(new Place { Name = "Bar", Address = new Address { Country = "Germany", City = "Berlin" } }); placeContext.Places.Add(new Place { Name = "Restaurant", Address = new Address { Country = "Germany", City = "Berlin" } }); placeContext.SaveChanges(); }
public void SaveChanges() { _context.SaveChanges(); }