Beispiel #1
0
        public async Task Recharge(MachineRechargeDto machineRechargeDto)
        {
            var machine      = _repositoryMachines.Where(q => q.Id == machineRechargeDto.MachineId).FirstOrDefault();
            var serialNumber = _repositorySerialNumbers.Where(q => q.Id == machineRechargeDto.SerialNumberId).FirstOrDefault();

            if (machine == null)
            {
                throw new UserFriendlyException("未找到机器信息");
            }
            if (serialNumber == null)
            {
                throw new UserFriendlyException("未找到序列号信息");
            }
            if (serialNumber.UseTime != null)
            {
                throw new UserFriendlyException("该序列号已被使用,如有疑问请联系管理员");
            }
            if (machine.ProductId != serialNumber.ProductId)
            {
                throw new UserFriendlyException("机器信息与序列号信息不匹配,无法充值");
            }

            serialNumber.UseTime     = DateTime.Now;
            serialNumber.BuyUserId   = CurrentUser.Id ?? new Guid();
            serialNumber.MachineId   = machine.Id;
            serialNumber.CreateDesc += $"\r\n{CurrentUser.UserName}通过平台充值,充值机器号:{machine.Id},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}";
            if (machine.ExpireTime < DateTime.Now)
            {
                machine.ExpireTime = DateTime.Now;
            }
            if (serialNumber.Expire > 0)
            {
                machine.ExpireTime = machine.ExpireTime.AddDays(serialNumber.Expire);
            }
            else
            {
                machine.ExpireTime = serialNumber.ExpireTime.Value;
            }

            machine.MachineRecords.Add(new MachineRecord()
            {
                MachineId = machine.Id,
                Desc      = $"{CurrentUser.UserName}使用【{machineRechargeDto.SerialNumberId}】序列号进行充值,增加时间【{serialNumber.Expire}】天,有效期到:{ machine.ExpireTime.ToString("yyyy-MM-dd ")}",
            });

            await _repositoryMachines.UpdateAsync(machine);

            await _repositorySerialNumbers.UpdateAsync(serialNumber);
        }
 public void OnGet()
 {
     MachineRechargeDto           = new MachineRechargeDto();
     MachineRechargeDto.MachineId = MachineId;
 }