Beispiel #1
0
        public string RevokeOrder(string username, string orderID)
        {
            var db   = Firebase.Database;
            var doc  = db.Collection("Orders").Document(orderID);
            var snap = doc.GetSnapshotAsync().Result;

            if (snap.Exists)
            {
                snap.TryGetValue <string>("Username", out var owner);
                if (!owner.Equals(username))
                {
                    return(JsonResponser.Response(false,
                                                  "cancel fail orderID not match with username's owner"));
                }
                else
                {
                    var result = doc.DeleteAsync().Result;
                    return(JsonResponser.Response(true,
                                                  $"cancel order [{orderID}] completed"));
                }
            }
            else
            {
                return(JsonResponser.Response(false, $"order [{orderID}] doesn't exist"));
            }
        }
Beispiel #2
0
        public string Create([FromBody] Order order)
        {
            var db    = Firebase.Database;
            var snaps = db.Collection("Orders");

            SetPrice(order);
            var result = snaps.AddAsync(order).Result;

            return(JsonResponser.Response(true, $"your transaction ID is [{result.Id}]"));
        }
Beispiel #3
0
        public string Get(string username, string id)
        {
            var db = Firebase.Database;

            var doc  = db.Collection("Orders").Document(id);
            var snap = doc.GetSnapshotAsync().Result;

            var json  = JsonConvert.SerializeObject(snap.ToDictionary());
            var order = JsonConvert.DeserializeObject <Order>(json);

            if (order.Username.Equals(username))
            {
                return(JsonResponser.Response(true, json));
            }
            else
            {
                return(JsonResponser.Response(false, "Username mismatch of transaction owner"));
            }
        }