schangxiang@126.com
2025-09-17 e8e8a06fc68a6a645ce32be2cc9c3aaa67a97d68
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
using iWareCommon.Common.Service;
using iWareCommon.Utils;
using iWareDataCore.BASE.Dao;
using iWareDataCore.BASE.Entity;
using iWareDataCore.ORM;
using iWareDataCore.Properties;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareDataCore.BASE.Service
{
   public class PlaceTypeService : CommonService<PlaceTypeEntity, BASEPlaceType, DbModelCore>
    {
 
 
        private static object Lock = new object();
 
        private PlaceTypeService() : base(PlaceTypeDao.GetInstance()) { }
 
        private static PlaceTypeService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>角色服务的单例实体</returns>
        public static PlaceTypeService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new PlaceTypeService();
                    }
                }
            }
            return Instance;
        }
 
 
        public override int Delete(int id, out string msg)
        {
            Delete(new List<int> { id }, out msg);
            return string.IsNullOrEmpty(msg) ? id : -1;
        }
 
        public override int Delete(List<int> ids, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var roleUsers = dbModel.BASEPlaceTypes.Where(x => ids.Contains(x.id)).ToList();
 
                    foreach (var roleUser in roleUsers)
                    {
                        dbModel.BASEPlaceTypes.Remove(roleUser);
                    }
 
                    dbModel.SaveChanges();
                    return ids.Count;
                }
                catch (DbEntityValidationException ex)
                {
                    var errs = ex.EntityValidationErrors.SelectMany(validationResult => validationResult.ValidationErrors).Select(m => m.ErrorMessage);
                    msg = string.Join(", ", errs);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", msg);
                    return 0;
                }
 
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", ex.Message);
                    return 0;
                }
            }
        }
    }
}