public OperationResultVo <Guid> Save(Guid currentUserId, UserPreferencesViewModel viewModel) { try { UserPreferences model; if (viewModel.Id == viewModel.UserId) { viewModel.Id = Guid.Empty; } UserPreferences existing = userPreferencesDomainService.GetById(viewModel.Id); if (existing != null) { model = mapper.Map(viewModel, existing); } else { model = mapper.Map <UserPreferences>(viewModel); } if (viewModel.Id == Guid.Empty) { userPreferencesDomainService.Add(model); viewModel.Id = model.Id; } else { userPreferencesDomainService.Update(model); } unitOfWork.Commit(); return(new OperationResultVo <Guid>(model.Id)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }