MSGCODES

Namespace: SyncSoft.App
We found 10 examples in language CSharp for this search. You will see 49 fragments of code.
		/// <summary>
		/// closes a lobby by hostname
		/// </summary>
		/// <param name="hostname">hostname</param>
		public static void CloseLobby(string hostname)
		{
			if (existingLobbies.ContainsKey(hostname))
			{
				Lobby lby = existingLobbies[hostname];
				if (lby.player2 != string.Empty)
				{
					lby.hostMsg = msgCodes.LobbyClosed;
					lby.msgAvb = true;
				}
				lobbiesMutex.WaitOne();
				existingLobbies.Remove(hostname);
				lobbiesMutex.ReleaseMutex();
			}
		}


        public static int GetMsgCode(Type type)
        {
            if (!MsgCodes.TryGetValue(type, out int result))
            {
                if (type.BaseType == typeof(Enum))
                    return MsgCodes[typeof(int)];
                else
                    throw new Exception($"MessageType:{type} 不存在.");
            }

            return result;
        }


        public UserMessage LoadByUserAndMessageCode(string userCode, string messCode)
        {
            return this.Load(p =>
            {
                p.AppendItem("UserInfoCode", userCode);
                p.AppendItem("MessageCode", messCode);
            }).FirstOrDefault();
        }

        protected override string GetConnectionName()
        {
            return CommonHelper.GetConnectionName();
        }

        public UserMessage LoadByCode(string code)
        {
            return this.Load(p =>
            {
                p.AppendItem("Code", code);
            }).FirstOrDefault();
        }

        public UserMessageCollection LoadByMessCode(string code)
        {
            return this.Load(p =>
            {
                p.AppendItem("MessageCode", code);
            });
        }

        /// <summary>
        /// 更新消息状态
        /// </summary>
        /// <param name="userCode">用户编码</param>
        /// <param name="msgCodes">消息组</param>
        /// <param name="statusWhere">状态(作为查询条件)</param>
        /// <param name="statusSet">状态(作为更新值)</param>
        public void UpdateStatus(string userCode, string[] msgCodes, UserMessageStatus statusWhere, UserMessageStatus statusSet)
        {
            if (msgCodes.Length == 0)
            {
                return;
            }
            else
            {
                InSqlClauseBuilder inSql = new InSqlClauseBuilder();
                inSql.AppendItem(msgCodes);

                this.SetFields(
                        update =>
                        {
                            update.AppendItem("Status", statusSet.ToString("D"));
                        },
                        where =>
                        {
                            where.AppendItem("UserInfoCode", userCode);
                            where.AppendItem("Status", statusWhere.ToString("D"));

                            where.AppendItem("MessageCode", inSql.ToSqlStringWithInOperator(TSqlBuilder.Instance), "", true);

                        },
                        this.GetConnectionName());
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public UserMessageCollection LoadByUserCodeAndStatus(string userCode, UserMessageStatus status)
        {

            return this.Load(where =>
            {
                where.AppendItem("UserInfoCode", userCode);
                where.AppendItem("Status", status.ToString("D"));
            });
        }


        #endregion
        // *******************************************************************************************************************************
        #region -  CRUD  -

        public async Task<string> CreateItemAsync(ProductItemDTO dto)
        {
            var msgCode = CheckItemDTO(dto);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            var existsItem = await ProductItemDAL.GetItemAsync(dto.ASIN, dto.SKU).ConfigureAwait(false);
            if (existsItem.IsNotNull())
            {
                return "Item already exists.";
            }

            msgCode = await ProductItemDAL.InsertItemAsync(dto).ConfigureAwait(false);
            if (msgCode.IsSuccess())
            {
                // 抛出Item更改事件
                _ = MessageDispatcher.PublishAsync(new ProductItemChangedEvent(dto.ASIN));
            }

            return msgCode;
        }

        public async Task<string> UpdateItemAsync(ProductItemDTO dto)
        {
            var msgCode = CheckItemDTO(dto);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            msgCode = await ProductItemDAL.UpdateItemAsync(dto).ConfigureAwait(false);
            if (msgCode.IsSuccess())
            {
                // 抛出库存更改事件
                _ = MessageDispatcher.PublishAsync(new ItemInventoryChangedEvent(dto.SKU, dto.InvQty));
                // 抛出Item更改事件
                _ = MessageDispatcher.PublishAsync(new ProductItemChangedEvent(dto.ASIN));
            }

            return msgCode;
        }

        public async Task<string> DeleteItemAsync(string asin, string sku)
        {
            var msgCode = await ProductItemDAL.DeleteItemAsync(asin, sku).ConfigureAwait(false);
            if (msgCode.IsSuccess())
            {
                // 抛出Item更改事件
                _ = MessageDispatcher.PublishAsync(new ProductItemChangedEvent(asin));
            }

            return msgCode;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  SyncInventoriesAsync  -

        public async Task<string> SyncInventoriesAsync()
        {
            var query = await InventoryService.GetOnHandQtysAsync(new InventoriesMSG { Warehouse = Constants.WarehouseID });
            if (query.Inventories.IsPresent())
            {
                var dic = query.Inventories.ToDictionary(x => x.ItemNo, x => x.Qty);
                return await ProductItemDAL.SetItemInvQtysdAsync(dic).ConfigureAwait(false);
            }
            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  SyncHoldInventoriesAsync  -

        public async Task<string> SyncHoldInventoriesAsync()
        {
            var query = await InventoryService.GetOnHoldQtysAsync(new InventoriesMSG { Warehouse = Constants.WarehouseID });
            if (query.Inventories.IsPresent())
            {
                var dic = query.Inventories.ToDictionary(x => x.ItemNo, x => x.Qty);
                return await ProductItemDAL.SetItemHoldInvQtysdAsync(dic).ConfigureAwait(false);
            }
            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  Utilities  -

        private string CheckItemDTO(ProductItemDTO dto)
        {
            if (dto.ASIN.IsNull()) return MsgCodes.ASINCannotBeEmpty;
            if (dto.SKU.IsNull()) return MsgCodes.SKUCannotBeEmpty;

            if (dto.ASIN.IsNotNull() && dto.ASIN.Length > 20) return MsgCodes.InvalidASINLength;
            if (dto.SKU.IsNotNull() && dto.SKU.Length > 20) return MsgCodes.InvalidSKULength;
            if (dto.Alias.IsNotNull() && dto.Alias.Length > 200) return MsgCodes.InvalidAliasLength;
            if (dto.Color.IsNotNull() && dto.Color.Length > 30) return MsgCodes.InvalidColorLength;
            if (dto.Size.IsNotNull() && dto.Size.Length > 30) return MsgCodes.InvalidSizeLength;
            if (dto.Url.IsNotNull() && dto.Url.Length > 200) return MsgCodes.InvalidImageUrlLength;

            if (dto.InvQty < 0) return MsgCodes.InvalidInventoryQuantity;

            return MsgCodes.SUCCESS;
        }

        #endregion


        #region Public Methods

        /// <summary>
        /// Connette a plcserver
        /// </summary>
        /// <returns>true if connected </returns>
        /// <returns>false if not connected</returns>
        private bool PLCServerConnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.ConnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat("Messaggio non inviato");
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Connesso");
            }

            return RetValue;
        }

        /// <summary>
        /// Disconnette da plcserver
        /// </summary>
        /// <returns>true if all ok</returns>
        /// <returns>false if not</returns>
        private bool PLCServerDisconnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.DisconnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat("Messaggio non inviato");
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Disconnesso");
            }

            return RetValue;
        }




        public void PLCAdd(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            if (plc.Connection(ApplicationName, PLCServerApplicationName))
            {
                model.ListPLCItems.Add(plc);
            }
        }

        public void PLCRemove(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            plc.Disconnection(ApplicationName, PLCServerApplicationName);

            model.ListPLCItems.Remove(plc);
        }

        public void PLCConnect(PLCItem plc)
        {
            plc.Connection(ApplicationName, PLCServerApplicationName);
        }

        public void PLCDisconnect(PLCItem plc)
        {
            plc.Disconnection(ApplicationName, PLCServerApplicationName);
        }


        #endregion
        // *******************************************************************************************************************************
        #region -  AllocateInventories  -

        /// <summary>
        /// 分配库存
        /// </summary>
        /// <remarks>
        /// 插入库存Qty和SafeQty,如果已经存在则直接更新
        /// </remarks>
        public async Task<string> AllocateInventoriesAsync(AllocateInventoriesCommand cmd)
        {
            var msgCode = ValidateCommand(cmd);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            // 检查参数正确性
            foreach (var item in cmd.Inventories)
            {
                if (item.SafeQty > item.Qty) return MsgCodes.WH_0000000010;
                // ^^^^^^^^^^

                if (item.SafeQty == 0) item.SafeQty = item.Qty; // 使用实际库存作为安全库存
            }

            // 开始执行事务
            var tran = new AllocateInventoriesTransaction(cmd);
            await tran.RunAsync().ConfigureAwait(false);


            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  HoldInventories  -

        /// <summary>
        /// 锁定订单库存
        /// </summary>
        public async Task<string> HoldOrderInventoriesAsync(HoldOrderInventoriesCommand cmd)
        {
            var msgCode = ValidateCommand(cmd);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            msgCode = await EnsureInventoriesSufficientAsync(cmd.Merchant_ID, cmd.Inventories).ConfigureAwait(false);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            // 开始执行事务
            var tran = new HoldOrderInventoriesTransaction(cmd);
            await tran.RunAsync().ConfigureAwait(false);
            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  UnholdInventories  -

        /// <summary>
        /// 解锁订单库存
        /// </summary>
        public async Task<string> UnholdOrderInventoriesAsync(UnholdOrderInventoriesCommand cmd)
        {
            var msgCode = ValidateCommand(cmd);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            // 开始执行事务
            var tran = new UnholdOrderInventoriesTransaction(cmd);
            await tran.RunAsync().ConfigureAwait(false);
            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  InventoryShipConfirm  -

        /// <summary>
        /// 库存出运确认
        /// </summary>
        public async Task<string> InventoryShipConfirmAsync(InventoryShipConfirmCommand cmd)
        {
            var msgCode = ValidateCommand(cmd);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            // 开始执行事务
            var tran = new InventoryShipCancelTransaction(cmd);
            await tran.RunAsync().ConfigureAwait(false);
            return MsgCodes.SUCCESS;
        }

        #endregion
        // *******************************************************************************************************************************
        #region //-  ClearOrderHeldInventories  -

        ///// <summary>
        ///// 清理数量为0的订单锁定库存数据
        ///// </summary>
        //public Task<string> ClearOrderHeldInventoriesAsync()
        //    => _InventoryMasterDAL.ClearOrderHeldInventoriesAsync();

        #endregion
        // *******************************************************************************************************************************
        #region -  Validation  -

        /// <summary>
        /// 检查命令
        /// </summary>
        private string ValidateCommand(InventoriesOperationCommand cmd)
        {
            if (cmd.Inventories.IsMissing()) return MsgCodes.WH_0000000004;
            // ^^^^^^^^^^
            foreach (var item in cmd.Inventories)
            {
                if (item.Qty < 0 || item.SafeQty < 0) return MsgCodes.WH_0000000009;
                // ^^^^^^^^^^
            }

            return MsgCodes.SUCCESS;
        }

        /// <summary>
        /// 确保不超卖
        /// </summary>
        private async Task<string> EnsureInventoriesSufficientAsync(string merchantId, IEnumerable<InventoryDTO> operationInventories)
        {
            var inventoryDAL = await LogisticsMasterDALFactory.CreateInventoryDALAsync(merchantId).ConfigureAwait(false);

            var availableInventories = await inventoryDAL.GetAvailableInventoriesAsync(merchantId, operationInventories.Select(x => x.ItemNo)).ConfigureAwait(false);
            var hasInsufficientInventory = operationInventories.Any(x => x.Qty > availableInventories[x.ItemNo]);
            if (hasInsufficientInventory) return MsgCodes.WH_0000000007;
            // ^^^^^^^^^^ 库存不足

            return MsgCodes.SUCCESS;
        }

        [TestInitialize]
        public void Initialize()
        {
            var dict = new Dictionary<string, string>
            {
                ["0"] = "�Twas brillig; and the slithy toves",
                ["1"] = "Did gyre and gimble in the wabe:",
                ["2"] = "All mimsy were the borogoves;",
                ["3"] = "And the mome raths outgrabe.",
                ["4"] = "�Beware the Jabberwock; my son!",
                ["5"] = "The jaws that bite; the claws that catch!",
                ["6"] = "Beware the Jubjub bird; and shun",
                ["7"] = "The frumious Bandersnatch!�"
            };
            var json = JsonSerializer.Serialize(dict);
            File.WriteAllText("data_en-US.json", json);
            dict = new Dictionary<string, string>
            {
                ["0"] = "���������. ������� ������",
                ["1"] = "�������� �� ����,",
                ["2"] = "� ��������� ������,",
                ["3"] = "��� ������� � ����.",
                ["4"] = "� ����� ����������, ���!",
                ["5"] = "�� ��� ������� � ���,",
                ["6"] = "� � ��y�� ����� ������� --",
                ["7"] = "���������� ����������."
            };
            json = JsonSerializer.Serialize(dict);
            File.WriteAllText("data_ru-RU.json", json);
        }

        [TestCleanup()]
        public void Cleanup()
        {
            File.Delete("data_en-US.json");
            File.Delete("data_ru-RU.json");
        }

        [TestMethod]
        public void MessageContainerAShouldWorkAsIntended()
        {
            TestMessageContainer(new MessageContainerA());
        }

        [TestMethod]
        public void MessageContainerBShouldWorkAsIntended()
        {
            TestMessageContainer(new MessageContainerB());
        }

        private void TestMessageContainer(MessageContainer container)
        {
            CultureInfo.CurrentUICulture = new CultureInfo("en-US");
            Assert.AreEqual("�Twas brillig; and the slithy toves", container[MsgCodes.Msg1]);
            Assert.AreEqual("Did gyre and gimble in the wabe:", container[MsgCodes.Msg2]);
            CultureInfo.CurrentUICulture = new CultureInfo("ru-RU");
            Assert.AreEqual("���������. ������� ������", container[MsgCodes.Msg1]);
            Assert.AreEqual("�������� �� ����,", container[MsgCodes.Msg2]);
            CultureInfo.CurrentUICulture = new CultureInfo("en-GB");
            Assert.ThrowsException<Exception>(() => container[MsgCodes.Msg1], "Data file for en-GB is not found.");
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Connette a plcserver
        /// </summary>
        /// <returns>true if connected </returns>
        /// <returns>false if not connected</returns>
        private bool PLCServerConnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.ConnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat("Messaggio non inviato");
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Connesso");
            }

            return RetValue;
        }

        /// <summary>
        /// Disconnette da plcserver
        /// </summary>
        /// <returns>true if all ok</returns>
        /// <returns>false if not</returns>
        private bool PLCServerDisconnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.DisconnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat("Messaggio non inviato");
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Disconnesso");
            }

            return RetValue;
        }




        public void PLCAdd(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            if (plc.Connection(ApplicationName, PLCServerApplicationName))
            {
                model.ListPLCItems.Add(plc);
            }
        }

        public void PLCRemove(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            plc.Disconnection(ApplicationName, PLCServerApplicationName);

            model.ListPLCItems.Remove(plc);
        }

        public void PLCConnect(PLCItem plc)
        {
            plc.Connection(ApplicationName, PLCServerApplicationName);
        }

        public void PLCDisconnect(PLCItem plc)
        {
            plc.Disconnection(ApplicationName, PLCServerApplicationName);
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Connette a plcserver
        /// </summary>
        /// <returns>true if connected </returns>
        /// <returns>false if not connected</returns>
        private bool PLCServerConnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.ConnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat(Texts._MSG_NOT_SENT_);
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Connesso");
            }

            return RetValue;
        }

        /// <summary>
        /// Disconnette da plcserver
        /// </summary>
        /// <returns>true if all ok</returns>
        /// <returns>false if not</returns>
        private bool PLCServerDisconnect()
        {
            bool RetValue = true;

            //Create a DotNetMQ Message to send 
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new MsgData
            {
                MsgCode = MsgCodes.DisconnectSubscriber,
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat(Texts._MSG_NOT_SENT_);
                RetValue = false;
            }

            if (RetValue)
            {
                Logger.InfoFormat("Disconnesso");
            }

            return RetValue;
        }




        public void PLCAdd(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            if (plc.Connection(ApplicationName, PLCServerApplicationName))
            {
                model.ListPLCItems.Add(plc);
            }
        }

        public void PLCRemove(string plcName, string ipAddress)
        {
            var plc = new PLCItem(plcName, ipAddress, mdsClient);

            plc.Disconnection(ApplicationName, PLCServerApplicationName);

            model.ListPLCItems.Remove(plc);
        }

        public void PLCConnect(PLCItem plc)
        {
            plc.Connection(ApplicationName, PLCServerApplicationName);
        }

        public void PLCDisconnect(PLCItem plc)
        {
            plc.Disconnection(ApplicationName, PLCServerApplicationName);
        }


        #endregion
        // *******************************************************************************************************************************
        #region -  User Address  -

        public async Task<string> RemoveAddressAsync(RemoveAddressCommand cmd)
        {
            return await UserDAL.DeleteUserAddressAsync(cmd.Address).ConfigureAwait(false);
        }

        public async Task<string> SaveAddressAsync(SaveAddressCommand cmd)
        {
            // 格式化地址
            cmd.Address.Address1 = Utils.FormatAddress(cmd.Address.Address1);
            cmd.Address.Address2 = Utils.FormatAddress(cmd.Address.Address2);
            cmd.Address.City = Utils.FormatAddress(cmd.Address.City);
            cmd.Address.State = Utils.FormatAddress(cmd.Address.State);
            cmd.Address.ZipCode = Utils.FormatAddress(cmd.Address.ZipCode);
            cmd.Address.Country = "US";
            cmd.Address.Hash = cmd.Address.ToSha1();

            var existAddress = await UserDAL.GetUserAddressAsync(cmd.Address.User_ID, cmd.Address.Hash).ConfigureAwait(false);
            if (existAddress.IsNull())
            {// 没有才添加
                return await UserDAL.InsertUserAddressAsync(cmd.Address).ConfigureAwait(false);
            }
            else
            {// 已经存在
                return MsgCodes.AddressExists;
            }
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  User  -

        public async Task<string> SaveProfileAsync(SaveUserProfileCommand cmd)
        {
            var msgCode = CheckUserDTO(cmd.User);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            if (cmd.Identity.UserID() != cmd.User.ID) return MsgCodes.SecurityCheckFailed;
            // ^^^^^^^^^^   必须本人

            var userHr = await UserApi.GetUserAsync(cmd.User.ID).ConfigureAwait(false);
            var user = await userHr.GetResultAsync().ConfigureAwait(false);
            if (user.IsNull()) return MsgCodes.UserNotExists;
            // ^^^^^^^^^^

            user.Email = cmd.User.Email;
            user.Phone = cmd.User.Phone;

            var hr = await UserApi.UpdateUserAsync(user).ConfigureAwait(false);
            var rs = await hr.GetResultAsync().ConfigureAwait(false);
            return rs;
        }

        #endregion
        // *******************************************************************************************************************************
        #region -  AdminUser  -

        public async Task<string> CreateAdminUserAsync(CreateAdminUserCommand cmd)
        {
            var msgCode = CheckUserDTO(cmd.User);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            // TODO: call passport account api

            var user = await UserDAL.GetUserAsync(cmd.User.ID).ConfigureAwait(false);
            if (user.IsNotNull())
            {
                return "User already exists.";
            }

            return await UserDAL.InsertUserAsync(cmd.User).ConfigureAwait(false);
        }

        public async Task<string> UpdateAdminUserAsync(SaveAdminUserCommand cmd)
        {
            var msgCode = CheckUserDTO(cmd.User);
            if (!msgCode.IsSuccess()) return msgCode;
            // ^^^^^^^^^^

            var user = await UserDAL.GetUserAsync(cmd.User.ID).ConfigureAwait(false);
            if (user.IsNull()) return MsgCodes.UserNotExists;
            // ^^^^^^^^^^

            return await UserDAL.UpdateUserAsync(cmd.User).ConfigureAwait(false);
        }

        public async Task<string> DeleteAdminUserAsync(DeleteAdminUserCommand cmd)
        {
            return await UserDAL.DeleteUserAsync(cmd.ID).ConfigureAwait(false);
        }

SyncSoft.App.MSGCODES : Object

Fields :

public static String SUCCESS
public static String DUPLICATE_KEY
public static String APP_0000000001
public static String APP_0000000002
public static String APP_0000000003
public static String APP_0000000006
public static String APP_0000000007
public static String APP_0000000010
public static String APP_0000000012
public static String APP_0000000014
public static String APP_0000000015
public static String APP_0000000017
public static String APP_0000000018

Methods :

public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()