Esempio n. 1
0
        public async Task <IActionResult> Transfer(int id, decimal sum, string from, string to)
        {
            Wallet walletFrom = _context.Wallets.FirstOrDefault(p => p.UserId == id && p.Currency == from.ToUpper());
            Wallet walletTo   = _context.Wallets.FirstOrDefault(p => p.UserId == id && p.Currency == to.ToUpper());

            if (walletFrom == null || walletTo == null)
            {
                return(BadRequest("User wasn't found!"));
            }

            if (walletFrom.Sum < sum)
            {
                return(BadRequest("Not enough money!"));
            }

            var          res          = CurrentRate.GetRateAsync(from.ToUpper(), to.ToUpper()).Result.Content;
            Deserializer deserializer = new Deserializer(res, from.ToUpper(), to.ToUpper());

            walletFrom.Sum -= sum;
            walletTo.Sum   += sum * deserializer.Rate;
            _context.Entry(walletFrom).State = EntityState.Modified;
            _context.Entry(walletTo).State   = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToAction("Get", "Wallets", new { id = id }));
        }
Esempio n. 2
0
 public void MergeFrom(ApplicantProfileReply other)
 {
     if (other == null)
     {
         return;
     }
     if (other.Id.Length != 0)
     {
         Id = other.Id;
     }
     if (other.Login.Length != 0)
     {
         Login = other.Login;
     }
     if (other.currentSalary_ != null)
     {
         if (currentSalary_ == null)
         {
             CurrentSalary = new global::CareerCloud.Grpc.Protos.DecimalValue();
         }
         CurrentSalary.MergeFrom(other.CurrentSalary);
     }
     if (other.currentRate_ != null)
     {
         if (currentRate_ == null)
         {
             CurrentRate = new global::CareerCloud.Grpc.Protos.DecimalValue();
         }
         CurrentRate.MergeFrom(other.CurrentRate);
     }
     if (other.Currency.Length != 0)
     {
         Currency = other.Currency;
     }
     if (other.Country.Length != 0)
     {
         Country = other.Country;
     }
     if (other.Province.Length != 0)
     {
         Province = other.Province;
     }
     if (other.Street.Length != 0)
     {
         Street = other.Street;
     }
     if (other.City.Length != 0)
     {
         City = other.City;
     }
     if (other.PostalCode.Length != 0)
     {
         PostalCode = other.PostalCode;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Esempio n. 3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Login.Length != 0)
            {
                hash ^= Login.GetHashCode();
            }
            if (currentSalary_ != null)
            {
                hash ^= CurrentSalary.GetHashCode();
            }
            if (currentRate_ != null)
            {
                hash ^= CurrentRate.GetHashCode();
            }
            if (Currency.Length != 0)
            {
                hash ^= Currency.GetHashCode();
            }
            if (Country.Length != 0)
            {
                hash ^= Country.GetHashCode();
            }
            if (Province.Length != 0)
            {
                hash ^= Province.GetHashCode();
            }
            if (Street.Length != 0)
            {
                hash ^= Street.GetHashCode();
            }
            if (City.Length != 0)
            {
                hash ^= City.GetHashCode();
            }
            if (PostalCode.Length != 0)
            {
                hash ^= PostalCode.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 4
0
 internal string GetJsonCurrentRate()
 {
     #region
     JsonHelper jsonhlp = new JsonHelper();
     if (AliCache._CurrentRate != null)
     {
         jsonhlp.AddObjectToJson("success", "true");
         CurrentRate rate = AliCache._CurrentRate;
         jsonhlp.AddObjectToJson(CurrentRate.KeyNameFetchTime, rate._FetchTime.ToString("yyyy-MM-dd HH:mm:ss"));
         jsonhlp.AddObjectToJson(CurrentRate.KeyNameMonth1To6, getMonthRate(rate._Month1To6));
         jsonhlp.AddObjectToJson(CurrentRate.KeyNameMonth6To12, getMonthRate(rate._Month6To12));
         jsonhlp.AddObjectToJson(CurrentRate.KeyNameMonth12To24, getMonthRate(rate._Month12To24));
         return(jsonhlp.ToString());
     }
     else
     {
         return(JsonHelper.GetErrorJson("服务器暂未获取成功阿里招财宝利率!"));
     }
     #endregion
 }
Esempio n. 5
0
        private async Task PublishCurrentRate()
        {
            TrimRates();

            var now         = DateTime.UtcNow;
            var currentRate = _rates.LastOrDefault(x => x.Key <= now);

            if (!currentRate.Equals(default(KeyValuePair <DateTime, decimal>)))
            {
                Console.WriteLine($"Publishing current rate of {currentRate.Value}");

                var message = new CurrentRate
                {
                    Now  = now,
                    Rate = currentRate.Value
                };

                var applicationMessage = new MqttApplicationMessageBuilder()
                                         .WithTopic(_currentRateTopic)
                                         .WithPayload(message.Payload)
                                         .WithAtLeastOnceQoS()
                                         .Build();

                Console.WriteLine("### SENDING APPLICATION MESSAGE ###");
                Console.WriteLine($"+ Topic = {_currentRateTopic}");
                Console.WriteLine($"+ Payload = {message.Payload}");
                Console.WriteLine();

                await _mqttClient.PublishAsync(applicationMessage);

                _lastPublished = now;
            }
            else
            {
                Console.WriteLine("No current rate available!");
            }
            await Task.Delay(0);
        }