Exemplo n.º 1
0
        public async Task <ResultDto> Add(QuestInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var itemDrop = _mapper.Map <QuestEntity>(item);


                await _questDomainService.Add(itemDrop);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加任务,
                    Content = JsonConvert.SerializeObject(item)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加任务,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <ResultDto> Add(int id, ItemDropRateInput input)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var itemDropRate = _mapper.Map <ItemDropRateEntity>(input);

                itemDropRate.ItemDropId = id;
                await _itemDropRateDomainService.Add(itemDropRate);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加掉落项,
                    Content = JsonConvert.SerializeObject(input)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加掉落项,
                    Content = $"Data={JsonConvert.SerializeObject(input)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <ResultDto> UpdateConfigs(Dictionary <string, string> configDic)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var oldConfigDic = await _configDomainService.GetConfigsFromDb();

                var content = oldConfigDic.ComparisonTo(configDic);
                await _configDomainService.UpdateConfigs(configDic, oldConfigDic);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改配置,
                    Content = content
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改配置,
                    Content = $"Data={JsonConvert.SerializeObject(configDic)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 4
0
        public async Task <ResultDto> SetEnabled(int id, bool enabled)
        {
            var result = new ResultDto {
                Message = ""
            };

            var operatorLogType = enabled ? OperatorLogType.启用用户 : OperatorLogType.禁用用户;

            try
            {
                var user = await _userDomainService.Get(id);

                if (user == null)
                {
                    result.Message = $"用户 {id} 不存在!";
                    return(result);
                }

                user.Status = enabled ? UserStatusEnum.正常 : UserStatusEnum.封禁;

                await _userDomainService.Update(user);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = operatorLogType,
                    Content = $"Id = {id}"
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = operatorLogType,
                    Content = $"Id = {id}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 5
0
        public async Task <ResultDto> Update(int id, PlayerInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var player = await _playerDomainService.Get(id);

                if (player == null)
                {
                    result.Message = $"玩家 {id} 不存在!";
                    return(result);
                }
                var content = player.ComparisonTo(item);
                _mapper.Map(item, player);

                await _playerDomainService.Update(player);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改玩家,
                    Content = $"Id = {id},Data = {content}"
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.修改玩家,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 6
0
        public async Task <ResultDto> Add(WareInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var ware = _mapper.Map <WareEntity>(item);
                if (ware.Effect == null)
                {
                    ware.Effect = "";
                }

                await _wareDomainService.Add(ware);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加物品,
                    Content = JsonConvert.SerializeObject(item)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加物品,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 7
0
        public async Task <ResultDto> Add(RoomInput item, int mapId, int roomId, string position)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var map = await _mapDomainService.Get(mapId);

                if (map == null)
                {
                    result.Message = $"参数错误(mapId={mapId})";

                    return(result);
                }

                var room = _mapper.Map <RoomEntity>(item);
                room.MapId = mapId;
                await _roomDomainService.Add(room);

                if (roomId > 0)
                {
                    var oldRoom = await _roomDomainService.Get(roomId);

                    if (oldRoom != null && oldRoom.MapId == mapId)
                    {
                        switch (position)
                        {
                        case "west":
                            if (oldRoom.East == 0)
                            {
                                oldRoom.East     = room.Id;
                                oldRoom.EastName = room.Name;

                                room.West     = oldRoom.Id;
                                room.WestName = oldRoom.Name;
                            }
                            break;

                        case "east":
                            if (oldRoom.West == 0)
                            {
                                oldRoom.West     = room.Id;
                                oldRoom.WestName = room.Name;


                                room.East     = oldRoom.Id;
                                room.EastName = oldRoom.Name;
                            }
                            break;

                        case "south":
                            if (oldRoom.South == 0)
                            {
                                oldRoom.South     = room.Id;
                                oldRoom.SouthName = room.Name;

                                room.North     = oldRoom.Id;
                                room.NorthName = oldRoom.Name;
                            }
                            break;

                        case "north":
                            if (oldRoom.North == 0)
                            {
                                oldRoom.North     = room.Id;
                                oldRoom.NorthName = room.Name;

                                room.South     = oldRoom.Id;
                                room.SouthName = oldRoom.Name;
                            }
                            break;
                        }
                    }
                }

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加地图,
                    Content = JsonConvert.SerializeObject(item)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.添加地图,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Exemplo n.º 8
0
        public async Task <ResultDto> Login(LoginInput input)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var query = await _adminDomainService.GetAll();

                var adminCount = await query.CountAsync();

                if (adminCount == 0)
                {
                    var admin = new AdminEntity
                    {
                        Name     = input.Name,
                        Password = input.Password.ToMd5()
                    };

                    await _adminDomainService.Add(admin);

                    await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                    {
                        Type    = OperatorLogType.登录,
                        Content = JsonConvert.SerializeObject(input)
                    });
                    await Commit();

                    result.IsSuccess = true;
                }
                else
                {
                    var admin = await _adminDomainService.Get(x => x.Name == input.Name);

                    if (admin == null)
                    {
                        result.Message = "账号不存在";
                        await _operatorLogDomainService.AddError(new OperatorLogEntity
                        {
                            Type    = OperatorLogType.登录,
                            Content = $"Data={JsonConvert.SerializeObject(input)},ErrorMessage={result.Message}"
                        });
                        await Commit();
                    }
                    else if (admin.Password != input.Password.ToMd5())
                    {
                        result.Message = "密码错误";
                        await _operatorLogDomainService.AddError(new OperatorLogEntity
                        {
                            Type    = OperatorLogType.登录,
                            Content = $"Data={JsonConvert.SerializeObject(input)},ErrorMessage={result.Message}"
                        });
                        await Commit();
                    }
                    else
                    {
                        var claims = new[] {
                            new Claim(ClaimTypes.NameIdentifier, admin.Id.ToString()),
                            new Claim(ClaimTypes.Name, admin.Name)
                        };

                        var             claimsIdentity = new ClaimsIdentity(claims, "Default");
                        ClaimsPrincipal user           = new ClaimsPrincipal(claimsIdentity);

                        await _httpAccessor.HttpContext.SignInAsync("admin", user, new AuthenticationProperties { IsPersistent = true, AllowRefresh = true, ExpiresUtc = DateTimeOffset.Now.AddDays(30) });

                        await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                        {
                            Type    = OperatorLogType.登录,
                            Content = ""
                        });
                        await Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.登录,
                    Content = $"Data={JsonConvert.SerializeObject(input)},ErrorMessage={result.Message}"
                });
                await Commit();
            }

            return(result);
        }