示例#1
0
        public ReviewLocation Update(ContentReference contentLink, ReviewLocation reviewLocation)
        {
            var data = reviewLocation.Data;

            lock (_lock)
            {
                var reviewLocations = Load(contentLink).ToList();

                if (string.IsNullOrWhiteSpace(reviewLocation.Id))
                {
                    reviewLocation = new ReviewLocation
                    {
                        Id = Guid.NewGuid().ToString(),
                    };
                    reviewLocations.Add(reviewLocation);
                }
                else
                {
                    reviewLocation = reviewLocations.FirstOrDefault(x => x.Id == reviewLocation.Id);
                    if (reviewLocation == null)
                    {
                        throw new ReviewLocationNotFoundException();
                    }
                }

                reviewLocation.Data = data;
                Save(contentLink, reviewLocations);
            }

            return(reviewLocation);
        }
        public ReviewLocation Update(ContentReference contentLink, ReviewLocation reviewLocation)
        {
            var data = reviewLocation.Data;

            lock (_lock)
            {
                var reviewLocations = Load(contentLink).ToList();

                var isNew = string.IsNullOrWhiteSpace(reviewLocation.Id);

                var beforeUpdateEventArgs = new BeforeUpdateEventArgs
                {
                    ReviewLocations = reviewLocations,
                    IsNew           = isNew,
                    Cancel          = false
                };
                OnBeforeUpdate?.Invoke(this, beforeUpdateEventArgs);
                if (beforeUpdateEventArgs.Cancel)
                {
                    return(null);
                }

                if (isNew)
                {
                    reviewLocation = new ReviewLocation
                    {
                        Id = Guid.NewGuid().ToString(),
                    };
                    reviewLocations.Add(reviewLocation);
                }
                else
                {
                    reviewLocation = reviewLocations.FirstOrDefault(x => x.Id == reviewLocation.Id);
                    if (reviewLocation == null)
                    {
                        throw new ReviewLocationNotFoundException();
                    }
                }

                reviewLocation.Data = data;
                Save(contentLink, reviewLocations);
            }

            return(reviewLocation);
        }