Esempio n. 1
0
        protected override void PrepareEntity(Category entity)
        {
            var l = DependencyResolver.Current.GetService <ILocalizationContext>();

            WebContext.ViewBag.Products = DataModelContext.Set <Product>().Where(x => !x.Categories.Any() || x.Categories.Any(p => p.Lang == l.Current.Lang));
            base.PrepareEntity(entity);
        }
Esempio n. 2
0
 private IEnumerable <LocalizationText> GetLocalizations()
 {
     if (_list == null)
     {
         _list = DataModelContext.Set <LocalizationText>().Where(x => x.Lang == _lang && x.Key.StartsWith(Key)).ToList();
     }
     return(_list);
 }
Esempio n. 3
0
        protected override void PrepareEntity(Product entity)
        {
            var l = DependencyResolver.Current.GetService <ILocalizationContext>();

            WebContext.ViewBag.Categories = DataModelContext.Set <Category>().Where(x => x.Lang == l.Current.Lang);
            WebContext.ViewBag.Related    = DataModelContext.Set <Product>().Where(x => x.Categories.Any(c => c.Lang == l.Current.Lang) && x.Id != entity.Id);
            base.PrepareEntity(entity);
        }
Esempio n. 4
0
        protected override void PrepareEntity(Partner entity)
        {
            LocalizeItem(entity);
            var countries = DataModelContext.Set <Country>().ToList();

            countries.ForEach(x =>
            {
                var text = GetByKey("country.name." + x.Name);
                if (text != null)
                {
                    x.Name = text.Value;
                }
            });
            WebContext.ViewBag.Countries = countries;
        }
Esempio n. 5
0
        private LocalizationText GetByKey(string fullKey, bool create = false)
        {
            var localizations = GetLocalizations();
            var text          = localizations.FirstOrDefault(t => t.Key == fullKey);

            if (text == null && create)
            {
                text = new LocalizationText
                {
                    Lang = _lang,
                    Key  = fullKey
                };
                DataModelContext.Set <LocalizationText>().Add(text);
            }
            return(text);
        }
        public JsonResult Salvar(List <ListaCompra> dadosWeb)
        {
            var itensListaBanco = db.Set <ListaCompra>().ToList();

            foreach (var item in dadosWeb)
            {
                var itemLista = itensListaBanco.FirstOrDefault(f => f.Id == item.Id);
                if (itemLista == null)
                {
                    var novoItemLista = new ListaCompra();
                    novoItemLista.IdAlimento = item.IdAlimento;
                    novoItemLista.Quantidade = item.Quantidade;
                    db.ListaCompra.Add(novoItemLista);
                }
            }

            foreach (var listItem in itensListaBanco)
            {
                var itemLista = dadosWeb.FirstOrDefault(f => f.Id == listItem.Id);

                if (itemLista != null)
                {
                    db.Entry <ListaCompra>(listItem).CurrentValues.SetValues(itemLista);
                }
            }

            foreach (var item in itensListaBanco)
            {
                var itemLista = dadosWeb.FirstOrDefault(f => f.Id == item.Id);
                if (itemLista == null)
                {
                    db.Entry <ListaCompra>(item).State = System.Data.Entity.EntityState.Deleted;
                }
            }

            db.SaveChanges();

            return(Json(new { }));
        }
Esempio n. 7
0
        public virtual ActionResult CreateBlock(int entityId)
        {
            var entity          = DataModelContext.Set <T>().First(x => x.Id == entityId);
            var interfaces      = typeof(T).GetInterfaces();
            var blockHolderType = interfaces.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHaveBlocksEntity <>));

            if (blockHolderType != null)
            {
                var vm        = (dynamic)entity;
                var blocks    = Enumerable.Cast <IBlockEntity>((IEnumerable)vm.Blocks);
                var blockType = blockHolderType.GetGenericArguments()[0];
                var block     = (IBlockEntity)Activator.CreateInstance(blockType);
                block.Sort = blocks.Select(x => x.Sort).DefaultIfEmpty().Max() + 1;

                DataModelContext.Set(block.GetType()).Add(block);

                AppendBlock(entity, block);

                DataModelContext.SaveChanges();
                return(PartialView(block));
            }
            return(new EmptyResult());
        }
Esempio n. 8
0
 private IEnumerable <LocalizationText> GetLocalizations()
 {
     return(_list ?? (_list = DataModelContext.Set <LocalizationText>().Where(x => x.Lang == _lang).ToList()));
 }
Esempio n. 9
0
 protected override void RemoveBlock(Category entity, IBlockEntity block)
 {
     entity.Blocks.Remove((CategoryBlock)block);
     DataModelContext.Set <CategoryBlock>().Remove((CategoryBlock)block);
     base.RemoveBlock(entity, block);
 }
Esempio n. 10
0
 protected override void RemoveBlock(Location entity, IBlockEntity block)
 {
     entity.Blocks.Remove((LocationBlock)block);
     DataModelContext.Set <LocationBlock>().Remove((LocationBlock)block);
     base.RemoveBlock(entity, block);
 }
Esempio n. 11
0
 public GenericRepository(DataModelContext context)
 {
     this.Context = context;
     this.DbSet   = context.Set <TEntity>();
 }