public async Task <string> Handle(GetBrandLayoutViewPath request, CancellationToken cancellationToken) { var layout = await _brandLayoutService.GetBrandLayoutById(request.LayoutId); if (layout == null) { layout = (await _brandLayoutService.GetAllBrandLayouts()).FirstOrDefault(); } if (layout == null) { throw new Exception("No default layout could be loaded"); } return(layout.ViewPath); }
public async Task <IActionResult> BrandLayoutUpdate(BrandLayoutModel model) { if (!ModelState.IsValid) { return(Json(new DataSourceResult { Errors = ModelState.SerializeErrors() })); } var layout = await _brandLayoutService.GetBrandLayoutById(model.Id); if (layout == null) { throw new ArgumentException("No layout found with the specified id"); } if (ModelState.IsValid) { layout = model.ToEntity(layout); await _brandLayoutService.UpdateBrandLayout(layout); return(new JsonResult("")); } return(ErrorForKendoGridJson(ModelState)); }
public BrandValidator(IEnumerable <IValidatorConsumer <BrandDto> > validators, ITranslationService translationService, IPictureService pictureService, IBrandService brandService, IBrandLayoutService brandLayoutService) : base(validators) { RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.Name.Required")); RuleFor(x => x).MustAsync(async(x, y, context) => { if (!string.IsNullOrEmpty(x.PictureId)) { var picture = await pictureService.GetPictureById(x.PictureId); if (picture == null) { return(false); } } return(true); }).WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.PictureId.NotExists")); RuleFor(x => x).MustAsync(async(x, y, context) => { if (!string.IsNullOrEmpty(x.BrandLayoutId)) { var layout = await brandLayoutService.GetBrandLayoutById(x.BrandLayoutId); if (layout == null) { return(false); } } return(true); }).WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.BrandLayoutId.NotExists")); RuleFor(x => x).MustAsync(async(x, y, context) => { if (!string.IsNullOrEmpty(x.Id)) { var brand = await brandService.GetBrandById(x.Id); if (brand == null) { return(false); } } return(true); }).WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.Id.NotExists")); }