public async Task <ServiceResult> Edit(Guid id, [FromBody] ShopItemDetailEditModel apiEntity) { var entity = ShopItemDetailEditModel.Map(apiEntity, id); var result = await _shopItemDetailService.UpdateAsync(entity); if (result.TryCastModel(out ShopItemDetail detail)) { result.ViewModel = ShopItemDetailViewModel.Map(detail); } return(result); }
public async Task <ServiceResult> Add([FromBody] ShopItemDetailAddModel apiEntity) { var entity = ShopItemDetailAddModel.Map(apiEntity); var result = await _shopItemDetailService.AddAsync(entity); if (result.TryCastModel(out ShopItemDetail detail)) { result.ViewModel = ShopItemDetailViewModel.Map(detail); } return(result); }
public static ShopItemViewModel Map(ShopItem model) { if (model == null) { return(null); } if (model.Details == null) { model.Details = new List <ShopItemDetail>(); } return(new ShopItemViewModel { Id = model.Id, Title = model.Title, Description = model.Description, ImagePath = Constants.GetFullPathToImage(model.ImagePath), Details = model.Details.Select(x => ShopItemDetailViewModel.Map(x)).ToList() }); }