username@email.com
2024-07-08 c6c6761506785691ef44e7e232c45e1b4b16f7fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using AutoMapper;
using DTO;
using IServices;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zhengcaioa.Models;
 
namespace Services
{
   public class AreaService: IAreaService
    {
 
        private readonly zhengcaioaContext _context;
        private readonly IMapper _mapper;
        public AreaService(zhengcaioaContext context, IMapper mapper)
        {
            _context = context;
            _mapper = mapper;
        }
        public ResultEntity save(AreaDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                var Area = _mapper.Map<Area>(dto);
                if (String.IsNullOrEmpty(Area.CodeId))
                {
                   // Area.CodeId = Guid.NewGuid().ToString();
 
 
                    _context.Areas.Add(Area);
                }
                else
                {
                    var updatepltRole = _context.Areas.Find(Area.CodeId);
                    if (updatepltRole != null)
                    {
                        updatepltRole.Name = Area.Name;
                        updatepltRole.ParentId = Area.ParentId;
                    }
                    else
                    {
                       // Area.CodeId = Guid.NewGuid().ToString();
 
 
                        _context.Areas.Add(Area);
                    }
                    
                   
 
 
 
 
 
                    
 
                }
 
                _context.SaveChanges();
                resultEntity.ReturnID = Area.CodeId;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
 
            }
            return resultEntity;
        }
 
        public AreaDTO Get(string id)
        {
            var entity = _context.Areas.Find(id);
 
            if (entity == null)
            {
                entity = new Area();
            }
            var AreaDTO = _mapper.Map<AreaDTO>(entity);
            return AreaDTO;
        }
 
        public ResultDataEntity<AreaDTO> SearchByPaging(AreaDTOSearch searchEntity)
        {
            ResultDataEntity<AreaDTO> data = new ResultDataEntity<AreaDTO>();
 
            
 
            var query = (from a in _context.Areas//.Where(x => x.RecStatus == "A")
                         join b in _context.Areas
                        on a.ParentId equals b.CodeId
                         into bsss
                         from bbb in bsss.DefaultIfEmpty()
 
 
                         where 1==1
                         && (string.IsNullOrWhiteSpace(searchEntity.Name) || a.Name.Contains(searchEntity.Name.Trim()))
                            && (string.IsNullOrWhiteSpace(searchEntity.ParentName) || bbb.Name.Contains(searchEntity.ParentName.Trim()))
                         select new AreaDTO
                         {
                             CodeId = a.CodeId,
                             Name = a.Name,
                             ParentName = bbb.Name,
                             ParentId = a.ParentId,
                         }).OrderBy(x => x.CodeId).ToList();
 
 
 
 
 
 
 
 
            //if (searchEntity.totalrows == 0)
                searchEntity.totalrows = query.Count();
            var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
 
            data.LoadData(searchEntity, rolelist);
            return data;
        }
 
        public ResultEntity ModifyStatus(string id, string userid)
        {
 
            ResultEntity result = new ResultEntity();
            result.Result = true;
 
            var model = _context.Areas.Find(id);
            if (model != null)
            {
                _context.Areas.Remove(model);
                _context.SaveChanges();
            }
 
            return result;
        }
 
 
 
        /// <summary>
        /// 获取所有有效科目
        /// </summary>
        /// <returns></returns>
        public List<AreaDTO> GetList()
        {
 
 
            var listPosition = _context.Areas.ToList();
 
            var list = _mapper.Map<List<AreaDTO>>(listPosition);
            return list;
        }
    }
}