public async Task <BannerItemAddOrChangeResponse> BannerItemAddOrChange(BannerItemAddOrChangeRequest request) { var response = new BannerItemAddOrChangeResponse(); try { var userLogin = await _context.GetCurrentCustomer(); if (string.IsNullOrEmpty(request.Id)) { //add 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.GetBannerItemById(request.Id); if (data == null) { response.SetFail("Template 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> Add([FromBody] BannerItemAddOrChangeRequest request) { BannerItemAddOrChangeResponse response = new BannerItemAddOrChangeResponse(); try { ValidationResult validate = BannerItemAddRequestValidate.ValidateModel(request); if (validate.IsValid) { response = await _bannerAppService.BannerItemAddOrChange(request); } else { response.SetFail(validate.Errors.Select(p => p.ToString())); } return(Json(response)); } catch (Exception e) { _logger.LogError(e, Common.Common.GetMethodName(), request); throw; } }