移动系统liao
2024-09-23 78028cee453a5878835a27f884ae36c0900fe8f7
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
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
 
namespace CoreCms.Net.Repository
{
    /// <summary>
    /// 用户地址表 接口实现
    /// </summary>
    public class CoreCmsUserShipRepository : BaseRepository<CoreCmsUserShip>, ICoreCmsUserShipRepository
    {
        public CoreCmsUserShipRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }
 
 
        #region 重写异步插入方法
 
        /// <summary>
        /// 重写异步插入方法
        /// </summary>
        /// <param name="entity">实体数据</param>
        /// <returns></returns>
        public async Task<WebApiCallBack> InsertAsync(CoreCmsUserShip entity)
        {
            var jm = new WebApiCallBack();
            if (entity.isDefault == true)
            {
                await DbClient.Updateable<CoreCmsUserShip>().SetColumns(p => p.isDefault == false).Where(p => p.userId == entity.userId).ExecuteCommandAsync();
            }
            var bl = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync() > 0;
            jm.code = bl ? 0 : 1;
            jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
 
            return jm;
        }
 
        #endregion
 
        #region 重写异步更新方法方法
 
        /// <summary>
        /// 重写异步更新方法方法
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<AdminUiCallBack> UpdateAsync(CoreCmsUserShip entity)
        {
            var jm = new AdminUiCallBack();
 
            var oldModel = await DbClient.Queryable<CoreCmsUserShip>().Where(p => p.id == entity.id && p.userId == entity.userId).SingleAsync();
            if (oldModel == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }
            //事物处理过程开始
            oldModel.areaId = entity.areaId;
            oldModel.address = entity.address;
            oldModel.name = entity.name;
            oldModel.mobile = entity.mobile;
            oldModel.isDefault = entity.isDefault;
            //oldModel.createTime = entity.createTime;
            oldModel.updateTime = entity.updateTime;
 
            oldModel.longitude = entity.longitude;
            oldModel.latitude = entity.latitude;
            oldModel.street = entity.street;
 
 
            if (oldModel.isDefault)
            {
                await DbClient.Updateable<CoreCmsUserShip>().SetColumns(p => p.isDefault == false).Where(p => p.userId == entity.userId).ExecuteCommandAsync();
            }
 
            //事物处理过程结束
            var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
            jm.code = bl ? 0 : 1;
            jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
 
            return jm;
        }
 
        #endregion
 
 
 
    }
}