public async Task <BannerItemGetResponse> GetBannerItemById(BannerItemGetRequest request) { var response = new BannerItemGetResponse(); try { var banner = await _bannerService.GetBannerById(request.BannerId); if (banner == null) { response.SetFail("Banner not found."); return(response); } response.Banner = banner.ToModel(); if (string.IsNullOrEmpty(request.Id)) { response.BannerItem = new BannerItemViewModel() { Status = EnumDefine.CommonStatusEnum.New, BannerId = request.BannerId }; } else { var data = await _bannerService.GetBannerItemById(request.Id); response.BannerItem = data.ToModel(); } response.SetSucess(); } catch (Exception e) { response.SetFail(e); _logger.LogError(e, e.Message, request); } return(response); }
public async Task <IActionResult> Get([FromBody] BannerItemGetRequest request) { BannerItemGetResponse response = new BannerItemGetResponse(); try { ValidationResult validate = BannerItemGetRequestValidate.ValidateModel(request); if (validate.IsValid) { response = await _bannerAppService.GetBannerItemById(request); } else { response.SetFail(validate.Errors.Select(p => p.ToString())); } return(Json(response)); } catch (Exception e) { _logger.LogError(e, Common.Common.GetMethodName(), request); throw; } }