Ejemplo n.º 1
0
        public JournalEntryDataModel Copy(JournalEntryDataModel selectedEntry)
        {
            var retVal = new JournalEntryDataModel();

            retVal.Load(selectedEntry.Copy());
            retVal.Dose.Load(selectedEntry.Dose.Copy());
            retVal.NutritionalInfo.Load(selectedEntry.NutritionalInfo.Copy());
            retVal.Tags.AddRange(selectedEntry.Tags.ToList());
            return(retVal);
        }
        public JournalEntryDataModel CreateEntry(string entryTitle)
        {
            var entry = new JournalEntry
            {
                Title  = entryTitle,
                Logged = DateTime.Now
            };

            var entryModel = new JournalEntryDataModel();

            entryModel.Load(entry);

            return(entryModel);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <JournalEntryDataModel> > SearchJournal(int userId, string searchString)
        {
            var retVal   = new List <JournalEntryDataModel>();//journalEntry/SearchJournal?searchValue=test
            var endPoint = $"journalEntries/V2/?userId={userId}&searchValue={searchString}";

            if (string.IsNullOrEmpty(searchString))
            {
                endPoint = $"journalEntries/V2/?userId={userId}";
            }

            using (var response = await client.GetAsync(endPoint))
            {
                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var entries = await Task.Run(() => JsonConvert.DeserializeObject <IEnumerable <JournalEntryWebApiModel> >(content));

                    foreach (var entry in entries)
                    {
                        var entryDataModel = new JournalEntryDataModel();
                        entryDataModel.Load(this.journalEntryFactory.Build(entry));
                        entryDataModel.Dose.Load(this.doseFactory.Build(entry.Dose));
                        entryDataModel.NutritionalInfo.Load(this.nutritionalInfoFactory.Build(entry.NutritionalInfo));

                        foreach (var tag in entry.Tags)
                        {
                            var tagDataModel = new TagDataModel();
                            tagDataModel.Load(this.tagFactory.Build(tag));
                            entryDataModel.Tags.Add(tagDataModel);
                        }

                        retVal.Add(entryDataModel);
                    }
                }
                else
                {
                    var content = await response.Content.ReadAsStringAsync();

                    //var message = await Task.Run(() => JsonConvert.DeserializeObject<string>(content));
                    //var test = message;
                }
            }

            return(retVal);
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <JournalEntryDataModel> > SearchJournal(string searchString)
        {
            var retVal = new List <JournalEntryDataModel>();

            var results = from entry in await journalEntries.GetItemsAsync()
                          join entryTag in await journalEntryTags.GetItemsAsync() on entry.Id equals entryTag.JournalEntryId into et
                          from entryTag in et.DefaultIfEmpty(new JournalEntryTag()
            {
                Id = entry.Id, JournalEntryId = 0, TagId = 0
            })
                          join tag in await tags.GetItemsAsync() on entryTag.TagId equals tag.Id into te
                          from tag in te.DefaultIfEmpty(new Tag()
            {
                Id = entryTag.TagId, Description = ""
            })
                          join entryNutrition in await journalEntryNutritionalInfos.GetItemsAsync() on entry.Id equals entryNutrition.JournalEntryId into en
                          from entryNutrition in en.DefaultIfEmpty(new JournalEntryNutritionalInfo()
            {
                Id = entry.Id, JournalEntryId = 0, JournalEntryNutritionalInfoId = 0
            })
                          join nutrition in await nutritionalInfos.GetItemsAsync() on entryNutrition.JournalEntryNutritionalInfoId equals nutrition.Id into n
                          from nutrition in n.DefaultIfEmpty(new NutritionalInfo()
            {
                Id = entryNutrition.JournalEntryNutritionalInfoId, Carbohydrates = 0
            })
                          join entryDose in await journalEntryDoses.GetItemsAsync() on entry.Id equals entryDose.JournalEntryId into ed
                          from entryDose in ed.DefaultIfEmpty(new JournalEntryDose()
            {
                Id = entry.Id, JournalEntryId = 0, DoseId = 0
            })
                          join dose in await doses.GetItemsAsync() on entryDose.DoseId equals dose.Id into d
                          from dose in d.DefaultIfEmpty(new Dose()
            {
                Id = entryDose.DoseId, InsulinAmount = 0, Extended = 0, UpFront = 100, TimeExtended = 0, TimeOffset = 0
            })
                          where entry.Title.ToUpper().Contains(searchString.ToUpper()) || tag.Description.ToUpper().Contains(searchString.ToUpper())
                          select new
            {
                entry,
                tag,
                nutrition,
                dose
            };

            var currentEntry = new JournalEntryDataModel();

            if (results.Any())
            {
                foreach (var result in results)
                {
                    if (result.entry.Id != currentEntry.Id)
                    {
                        if (currentEntry.Id > 0)
                        {
                            retVal.Add(currentEntry);
                        }

                        currentEntry = new JournalEntryDataModel();
                        currentEntry.Load(result.entry);

                        if (result.nutrition.Id > 0)
                        {
                            currentEntry.NutritionalInfo.Load(result.nutrition);
                        }

                        if (result.dose.Id > 0)
                        {
                            currentEntry.Dose.Load(result.dose);
                        }
                    }

                    if (result.tag.Id > 0)
                    {
                        var tagViewModel = new TagDataModel();
                        tagViewModel.Load(result.tag);
                        currentEntry.Tags.Add(tagViewModel);
                    }
                }
            }

            if (currentEntry.Id > 0)
            {
                retVal.Add(currentEntry);
            }

            return(retVal);
        }