public async Task <BannerAddOrChangeResponse> BannerAddOrChange(BannerAddOrChangeRequest request) { var response = new BannerAddOrChangeResponse(); try { var userLogin = await _context.GetCurrentCustomer(); if (string.IsNullOrEmpty(request.Id)) { //add request.Status = EnumDefine.CommonStatusEnum.New; var command = request.ToCommandAdd(userLogin.Id); var result = await _bannerService.SendCommand(command); if (result.IsSucess) { response.SetSucess(); } else { response.SetFail(result.Message); } } else { var data = await _bannerService.GetBannerById(request.Id); if (data == null || string.IsNullOrEmpty(data.Id)) { response.SetFail("Banner not found!"); return(response); } //update var command = request.ToCommandChange(userLogin.Id); var result = await _bannerService.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 <IActionResult> Change([FromBody] BannerAddOrChangeRequest request) { try { var response = new BannerAddOrChangeResponse(); ValidationResult validate = BannerChangeRequestValidate.ValidateModel(request); if (validate.IsValid) { response = await _bannerAppService.BannerAddOrChange(request); } else { response.SetFail(validate.Errors.Select(p => p.ToString())); } return(Json(response)); } catch (Exception e) { _logger.LogError(e, Common.Common.GetMethodName(), request); throw; } }