12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Threading.Tasks;
- using GxPress.Repository.Interface.Navigation;
- using GxPress.Service.Interface.Navigation;
- using System.Transactions;
- using GxPress.Common.Tools;
- using System.Linq;
- using System.Collections.Generic;
- using GxPress.Request.Navigation;
- using AutoMapper;
- namespace GxPress.Service.Implement.Navigation
- {
- public class MiddleLableService : IMiddleLableService
- {
- private readonly IMiddleLableRepository middleLableRepository;
- private readonly IMiddleLableNexusRepository middleLableNexusRepository;
- private readonly IMapper _mapper;
- public MiddleLableService(IMiddleLableRepository middleLableRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMapper mapper)
- {
- this.middleLableRepository = middleLableRepository;
- this.middleLableNexusRepository = middleLableNexusRepository;
- _mapper = mapper;
- }
- /// <summary>
- /// 添加中间件页面
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public async Task<bool> InsertAsync(MiddleLableInRequest request)
- {
- try
- {
- using (var transactionScope = new System.Transactions.TransactionScope())
- {
- var model = _mapper.Map<Entity.Navigations.MiddleLable>(request);
- var middleLableId = await middleLableRepository.InsertAsync(model);
- var ids = StringUtils.StringCollectionToStringList(request.LabelId);
- var idInts = new List<int>();
- foreach (var item in ids)
- idInts.Add(int.Parse(item));
- await middleLableNexusRepository.InsertAsync(middleLableId, idInts);
- transactionScope.Complete();
- }
- }
- catch
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<bool> DeleteAsync(int id)
- {
- try
- {
- using (var transactionScope = new System.Transactions.TransactionScope())
- {
- await middleLableRepository.DeleteAsync(id);
- await middleLableNexusRepository.DeleteByMiddleLableIdAsync(id);
- transactionScope.Complete();
- }
- }
- catch
- {
- return false;
- }
- return true;
- }
- public async Task<bool> UpdateAsync(MiddleLableUpRequest request)
- {
- try
- {
- using (var transactionScope = new System.Transactions.TransactionScope())
- {
- await middleLableRepository.UpdateAsync(request);
- if (!string.IsNullOrEmpty(request.LabelId))
- await middleLableNexusRepository.UpdateAsync(request.Id, request.LabelId);
- transactionScope.Complete();
- }
- }
- catch
- {
- return false;
- }
- return true;
- }
- }
- }
|