public PointContainer GetOrCreateById(string userId)
        {
            using (var db = new LiteDatabase(databaseName))
            {
                var pointsCollections        = db.GetCollection <PointCartContainerDTO>(PointCartContainerDTO.TableName);
                PointCartContainerDTO result = null;

                var search = pointsCollections.Find(x => x.UserId.Equals(userId));

                if (search.Any())
                {
                    result = search.Single();
                }
                else
                {
                    result = new PointCartContainerDTO {
                        DateCreated = DateTime.UtcNow, Points = new PointDTO[] { }, UserId = userId
                    };
                    pointsCollections.Insert(result);
                }

                var container = new PointContainer();

                foreach (var pointDto in result.Points)
                {
                    container.Add(Point.TryCreate(pointDto.X, pointDto.Y));
                }

                return(container);
            }
        }
        public PointContainer GetByName(string name)
        {
            using (var db = new LiteDatabase(databaseName))
            {
                var pointsCollections = db.GetCollection <PointContainerDTO>(PointContainerDTO.TableName);
                var result            = pointsCollections.FindOne(x => x.Name.StartsWith(name));

                var container = new PointContainer();

                foreach (var pointDto in result.Points)
                {
                    container.Add(Point.TryCreate(pointDto.X, pointDto.Y));
                }

                return(container);
            }
        }
        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);
            }
        }
Esempio n. 5
0
 private void SyncCart(PointContainer cntnrt)
 {
     pointCartContainerRepository.Save(getCurrentUserId(), cntnrt);
 }