Пример #1
0
        public BannerItem RemoveItem(BannerItemRemoveCommand command)
        {
            if (BannerItems == null)
            {
                BannerItems = new List <BannerItem>();
            }
            BannerItem bannerItem = BannerItems.FirstOrDefault(p => p.Id == command.Id);

            if (bannerItem == null)
            {
                throw new Exception("BannerItem not found.");
            }
            bannerItem.Remove(command);

            AddEvent(this.ToAddOrChangCacheEvent());
            return(bannerItem);
        }
        public async Task <ICommandResult> Handle(BannerItemRemoveCommand mesage)
        {
            try
            {
                ICommandResult result;
                var            rBanner = await _bannerService.GetBannerById(mesage.BannerId);

                if (rBanner == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "Banner not found",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Banner_NotFound
                    };
                    return(result);
                }
                RBannerItem[] rBannerItems = await _bannerService.GetBannerItemByBannerId(rBanner.Id);

                SystemDomains.Banner.Banner banner = new SystemDomains.Banner.Banner(rBanner, rBannerItems);
                var bannerItem = banner.RemoveItem(mesage);
                await _bannerService.ChangeBannerItemStatus(bannerItem.Id, bannerItem.Status, bannerItem.UpdatedUid, bannerItem.UpdatedDateUtc);

                await _eventSender.Notify(banner.Events);

                result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = banner.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
Пример #3
0
        public async Task <CommandResult> SendCommand(BannerItemRemoveCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }
Пример #4
0
 public void Remove(BannerItemRemoveCommand command)
 {
     Status         = EnumDefine.CommonStatusEnum.Deleted;
     UpdatedDateUtc = command.CreatedDateUtc;
     UpdatedUid     = command.UpdatedUserId;
 }