Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            var user = await GetCurrentUser();

            var l = await portfolios.GetMedicines(user.Id);

            var catObjs = await categories.GetCategories(user.Id);

            List <CategoryViewModel> categoryViews = new List <CategoryViewModel>();
            List <MedicineObject>    usedMeds      = new List <MedicineObject>();

            foreach (var c in catObjs)
            {
                await categoryMedicines.LoadMedicines(c);

                foreach (var med in c.MedicinesWithCategory)
                {
                    usedMeds.Add(med);
                    await medicineEffects.LoadEffects(med);
                }
                categoryViews.Add(CategoryViewModelFactory.Create(c));
            }

            var allMeds = await medicines.GetObjectsList();

            List <string> duplicateIds = new List <string>();

            for (int i = 0; i < allMeds.Count; i++)
            {
                bool contains = usedMeds.Any(x => x.DbRecord.ID == allMeds[i].DbRecord.ID);
                if (contains)
                {
                    duplicateIds.Add(allMeds[i].DbRecord.ID);
                }
            }

            foreach (var id in duplicateIds)
            {
                var medicine = allMeds.Where(x => x.DbRecord.ID == id).ToList();
                allMeds.Remove(medicine[0]);
            }
            //foreach (var med in allMeds)
            //{
            //    int index = usedMeds.FindIndex(x => x.DbRecord.ID == med.DbRecord.ID);
            //    if (index>=0)
            //    {
            //        allMeds.Remove(med);
            //    }
            //}

            ViewBag.Medicines = allMeds.Select(x => new SelectListItem
            {
                Value = x.DbRecord.ID,
                Text  = x.DbRecord.Name + ", " + x.DbRecord.FormOfInjection + ", " + x.DbRecord.Strength
            }).ToList();

            ViewBag.Categories = categoryViews;
            return(View(PortfolioViewModelFactory.Create(user.Id, l)));
        }
        private CategoryViewModel GetCategoryViewModel(Category category, SearchOptions productSearchOptions = null)
        {
            Assert.IsNotNull(category, nameof(category));

            var cacheKey = CreateCacheKey("Category", category, productSearchOptions);

            var categoryViewModel = this.GetFromCache <CategoryViewModel>(cacheKey);

            if (categoryViewModel != null)
            {
                return(categoryViewModel);
            }
            categoryViewModel = CategoryViewModelFactory.Create(category, productSearchOptions);

            return(this.AddToCache(cacheKey, categoryViewModel));
        }
        public ActionResult CategoryPageHeader()
        {
            if (CatalogManager.CatalogContext == null)
            {
                return(this.InfoMessage(InfoMessage.Error("This rendering cannot be shown without a valid catalog context.")));
            }

            var currentCategory = GetCurrentCategory();

            if (currentCategory == null)
            {
                return(this.InfoMessage(InfoMessage.Error(AlertTexts.InvalidDataSourceTemplateFriendlyMessage)));
            }

            var model = CategoryViewModelFactory.Create(currentCategory);

            return(View(model));
        }
 public void Process(GetPageMetadataArgs args)
 {
     if (CatalogItemContext.IsCategory)
     {
         var category = CategoryViewModelFactory.Create(CatalogItemContext.Current.Item);
         args.Metadata.PageTitle   = category.Title;
         args.Metadata.Description = StringUtil.RemoveTags(category.Description);
     }
     if (CatalogItemContext.IsProduct)
     {
         var product = ProductViewModelFactory.Create(CatalogItemContext.Current.Item);
         args.Metadata.PageTitle   = product.Title;
         args.Metadata.Description = StringUtil.RemoveTags(product.Description);
         foreach (var tag in product.Tags)
         {
             args.Metadata.KeywordsList.Add(tag);
         }
     }
 }
Esempio n. 5
0
 public IActionResult New()
 {
     return(View(_factory.Create()));
 }