/// <inheritdoc /> public async Task <AuctionItemCategoryInputModel> AddAsync(AuctionItemCategoryInputModel model) { if (!Validator.TryValidateObject(model, new ValidationContext(model), null, true)) { return(null); } try { AuctionItemCategory auctionItemCategory = mapper.Map <AuctionItemCategory>(model); await workUnit.AuctionItemCategoryRepository.AddAsync(auctionItemCategory); await workUnit.SaveAsync(); model.Id = auctionItemCategory.Id; return(model); } catch (DbUpdateException) { return(null); } catch (Exception ex) { logger.LogError(ex, ExceptionThrownInService); throw; } }
/// <inheritdoc /> public async Task <AuctionItemCategoryDetailedModel> UpdateAsync(int id, AuctionItemCategoryInputModel model) { if (!Validator.TryValidateObject(model, new ValidationContext(model), null, true)) { return(null); } try { model.Id = id; AuctionItemCategory auctionItemCategory = mapper.Map <AuctionItemCategory>(model); workUnit.AuctionItemCategoryRepository.Update(auctionItemCategory); await workUnit.SaveAsync(); AuctionItemCategory result = await workUnit.AuctionItemCategoryRepository.GetByIdWithDetailsAsync(id); return(mapper.Map <AuctionItemCategoryDetailedModel>(result)); } catch (DbUpdateException) { return(null); } catch (Exception ex) { logger.LogError(ex, ExceptionThrownInService); throw; } }