Example #1
0
        public async Task <IEnumerable <Article> > GetAllArticles()
        {
            Query         query             = _firestoreDb.Collection(collectionName);
            QuerySnapshot articlesSnapshots = await query.GetSnapshotAsync();

            IEnumerable <Article> articles = articlesSnapshots.Where(snap => snap.Exists).Select(snap => { return(snap.ConvertTo <Article>()); });

            return(articles);
        }
Example #2
0
        public virtual async Task <IEnumerable <PersistedGrant> > GetAllAsync(string subjectId)
        {
            QuerySnapshot persistedGrants = await GetPersistedGrants((nameof(PersistedGrant.SubjectId), subjectId))
                                            .ConfigureAwait(false);

            List <PersistedGrant> model = persistedGrants
                                          .Where(persistedGrant => persistedGrant.Exists)
                                          .Select(persistedGrant => persistedGrant.ConvertTo <PersistedGrant>())
                                          .ToList();

            _logger.LogDebug("{persistedGrantCount} persisted grants found for {subjectId}", model.Count, subjectId);

            return(model);
        }
Example #3
0
        public Task <StatusResult> GetRepairStatus(string name, string reclaim)
        {
            FirestoreDb  db     = connection.GetFirestoreDb();
            StatusResult result = new StatusResult();

            string repairNum = reclaim
                               .Substring(reclaim.LastIndexOf("0") + 1);

            int id = int.Parse(repairNum);

            QuerySnapshot snapshot = db
                                     .Collection("service-repairs")
                                     .WhereEqualTo("CustomerName", name)
                                     .GetSnapshotAsync()
                                     .Result;

            result.Status = snapshot.FirstOrDefault()
                            .ConvertTo <Repair>()
                            .RepairStatus;

            QuerySnapshot qs = db.Collection("activity-log")
                               .WhereEqualTo("RepairId", id)
                               .GetSnapshotAsync()
                               .Result;

            string        docId  = qs.FirstOrDefault().Id;
            QuerySnapshot getLog = db
                                   .Collection("activity-log")
                                   .Document(docId)
                                   .Collection("logs")
                                   .GetSnapshotAsync()
                                   .Result;

            result.Time = getLog
                          .Where(x => x.ConvertTo <RepairLog>()
                                 .Description.Contains(result.Status))
                          .OrderByDescending(x => x.CreateTime)
                          .FirstOrDefault()
                          .ConvertTo <RepairLog>()
                          .TimeOfEvent;

            return(Task.FromResult(result));
        }
Example #4
0
        public override void NextQuestion()
        {
            DatabaseService service = new DatabaseService(_Bot, _db);

            string text = "";

            try {
                // Call successor
                switch (_Bot.LineEvent.type)
                {
                case "message":
                    if (_Bot.LineEvent.message.type.Equals("text"))
                    {
                        text = _Bot.LineEvent.message.text;
                    }
                    else
                    {
                        throw new Exception(new Error(ErrCode.S010).Message);
                    }
                    break;

                case "postback":
                    text = _Bot.LineEvent.postback.Params != null ? ((_Bot.LineEvent.postback.Params.datetime != null) ? _Bot.LineEvent.postback.Params.datetime : ((_Bot.LineEvent.postback.Params.date != null) ? _Bot.LineEvent.postback.Params.date : (_Bot.LineEvent.postback.Params.time != null) ? _Bot.LineEvent.postback.Params.time : _Bot.LineEvent.postback.data)) : _Bot.LineEvent.postback.data;
                    break;

                default:
                    throw new Exception(new Error(ErrCode.S002).Message);
                }

                if (service.LastQuestionNumber(_Bot.UserInfo.userId, this.GetType().FullName) == 0)
                {
                    service.AddRecord(_Bot.UserInfo.userId, 1, this.GetType().FullName);
                    this.PushQuestion(1);
                }
                else
                {
                    int  lastQuestionNumber = service.LastQuestionNumber(_Bot.UserInfo.userId, this.GetType().FullName);
                    bool flag = this.IsAnswerPassed(lastQuestionNumber, text);
                    if (flag)
                    {
                        foreach (PropertyInfo pi in this.GetType().GetProperties())
                        {
                            Order order = pi.GetCustomAttribute <Order> ();
                            if (order != null && order.Id == lastQuestionNumber)
                            {
                                pi.SetValue(this, text);
                            }
                        }

                        service.Update(_Bot.UserInfo.userId, lastQuestionNumber, text, this.GetType().FullName);

                        if (this.MaxOrder == lastQuestionNumber)
                        {
                            QuerySnapshot query     = _db.Collection(_Bot.UserInfo.userId).GetSnapshotAsync().Result;
                            DateTime      startDate = DateTime.Parse(this.startDate);
                            DateTime      endDate   = DateTime.Parse(this.endDate);
                            if (query.Count > 0)
                            {
                                List <MessageBase> messages = query.Where(a => DateTime.Parse(a.Id) >= new DateTime(startDate.Year, startDate.Month, 1) && DateTime.Parse(a.Id) <= endDate.AddMonths(1).AddDays(-1)).Select(a => new { key = a.Id, value = a.GetValue <List <Dictionary <string, object> > > ("list").Sum(a => Decimal.Parse(a["Money"].ToString())) })
                                                              .GroupBy(a => DateTime.Parse(a.key).ToString("yyyy/MM")).Select(a => {
                                    Decimal total = a.Sum(a => a.value);
                                    string text   = a.Key + " 總金額:" + total;
                                    return(new TextMessage(text));
                                }).ToList <MessageBase> ();

                                _Bot.ReplyMessage(_Bot.LineEvent.replyToken, messages);
                            }
                            else
                            {
                                _Bot.ReplyMessage(_Bot.LineEvent.replyToken, @"範圍區間無消費");
                            }
                            service.Remove(_Bot.UserInfo.userId, this.GetType().FullName);
                        }
                        else
                        {
                            service.AddRecord(_Bot.UserInfo.userId, lastQuestionNumber + 1, this.GetType().FullName);
                            this.PushQuestion(lastQuestionNumber + 1);
                        }
                    }
                    else
                    {
                        this.PushComplaint(lastQuestionNumber);
                    }
                }
            } catch (Exception ex) {
                _Bot.Notify(ex);
            }
        }