public void Save(string userID, PointContainer container) { using (var db = new LiteDatabase(databaseName)) { var pointsCollections = db.GetCollection <PointCartContainerDTO>(PointCartContainerDTO.TableName); var pointContainerEntity = pointsCollections.FindOne(x => x.UserId == userID); if (pointContainerEntity == null) { pointContainerEntity = new PointCartContainerDTO { DateCreated = DateTime.UtcNow, UserId = userID }; pointsCollections.Insert(pointContainerEntity); } pointContainerEntity.Points = container.Select(x => new PointDTO(x.X, x.Y)).ToArray(); pointsCollections.Update(pointContainerEntity); } }
public void Save(string name, PointContainer container) { using (var db = new LiteDatabase(databaseName)) { var pointsCollections = db.GetCollection <PointContainerDTO>(PointContainerDTO.TableName); var result = pointsCollections.FindOne(x => x.Name == name); if (result != null) { pointsCollections.Delete(x => x.Name == name); } var containerDto = new PointContainerDTO { Points = container.Select(x => new PointDTO(x.X, x.Y)).ToArray(), Name = name }; pointsCollections.Insert(containerDto); } }