Ejemplo n.º 1
0
 public void UpdateSlot(Item _item, int _amount)
 {
     if (OnBeforeUpdate != null)
     {
         OnBeforeUpdate.Invoke(this);
     }
     item   = _item;
     amount = _amount;
     if (OnAfterUpdate != null)
     {
         OnAfterUpdate.Invoke(this);
     }
 }
        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);
        }