Exemplo n.º 1
0
        public async Task <BaseResponse> MenuBannerMappingAdd(MenuBannerMappingAddRequest request)
        {
            BaseResponse response = new BaseResponse();

            try
            {
                MenuBannerMappingAddCommand command = request.ToAddBannerCommand();
                var result = await _menuService.SendCommand(command);

                if (result.IsSucess)
                {
                    response.SetSucess();
                }
                else
                {
                    response.SetFail(result.Message);
                }
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }
        public async Task <ICommandResult> Handle(MenuBannerMappingAddCommand message)
        {
            try
            {
                ICommandResult result;
                RMenu          rMenu = await _menuService.Get(message.MenuId);

                if (rMenu == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "Menu not found",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Template_NotFound
                    };
                    return(result);
                }
                RBanner[] rbanners = await _bannerService.GetBannerByMenuId(rMenu.Id);

                Menu    menu   = new Menu(rMenu, rbanners);
                RBanner banner = await _bannerService.GetBannerById(message.BannerId);

                var bannerAdd = menu.AddBanner(banner);
                await _menuService.AddMenuBannerMapping(menu.Id, bannerAdd.Id);

                result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = menu.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = message;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
Exemplo n.º 3
0
        public async Task <CommandResult> SendCommand(MenuBannerMappingAddCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }