示例#1
0
        public ActionResult Save(CodelistEditModel model)
        {
            var typeName = model.Name;

            var type = _types.Where(t => t.Name == typeName).SingleOrDefault();

            if (type != null)
            {
                using (CatalogContext db = new CatalogContext())
                {
                    var keys = new object[] { model.ID };

                    var res = (ICodelist)db.Set(type).Find(keys);
                    if (res != null)
                    {
                        res.ShortDescription = model.ShortDescription;
                        res.LongDescription  = model.LongDescription;
                        res.CodelistNumber   = model.CodelistNumber;
                        res.SortOrder        = model.SortOrder;
                        db.Entry(res).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            return(Redirect("~/Codelists?n=" + model.Name));
        }
示例#2
0
 private static void SaveEnts(ref ICodelist tt, Type type)
 {
     using (CatalogContext db = new CatalogContext())
     {
         if (tt.Parent == null || tt.Parent.ID == 0)
         {
         }
         else
         {
             var res = db.Set(tt.Parent.GetType()).Find(new object[] { tt.Parent.ID });
             //((ICodelistCategory)res).AddChild(tt);
             tt.Parent = (ICodelist)res;
         }
         db.Set(type).Add(tt);
         db.SaveChanges();
     }
 }
示例#3
0
        public ActionResult Add()
        {
            var n                = Request.Form["n"];
            var typeName         = Request.Form["typeName"];
            var parentID         = (Request.Form["parentID"] == "")? "0" : Request.Form["parentID"];
            var parentName       = Request.Form["parentName"];
            var shortDescription = Request.Form["shortDescription"];
            var longDescription  = Request.Form["longDescription"];

            if (Request.Form["codelistNumber"] == "" || shortDescription == "")
            {
                return(Redirect("~/Codelists?n=" + n));
            }

            var codelistNumber = Request.Form["codelistNumber"];
            var sortOrder      = (Request.Form["sortOrder"] == "")? "0" : Request.Form["sortOrder"];

            var type = _types.Where(t => t.Name == typeName).SingleOrDefault();

            if (type != null)
            {
                using (CatalogContext db = new CatalogContext())
                {
                    var t = new object[] { codelistNumber, shortDescription, longDescription, sortOrder };

                    var tt = Activator.CreateInstance(type, t);

                    if (parentName != "")
                    {
                        var parentType = _types.Where(i => i.Name == parentName).SingleOrDefault();

                        var keys = new object[] { int.Parse(parentID) };

                        var parent = db.Set(parentType).Find(keys);

                        ((ICodelist)tt).Parent = (ICodelist)parent;
                    }

                    db.Set(type).Add(tt);

                    db.SaveChanges();
                }
            }
            return(Redirect("~/Codelists?n=" + n));
        }
示例#4
0
 public Repository(CatalogContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     Context = context;
     DbSet   = context.Set <T>();
 }
示例#5
0
        public ActionResult Delete(string n, int id)
        {
            var type = _types.Where(t => t.Name == n).SingleOrDefault();

            if (type != null)
            {
                using (CatalogContext db = new CatalogContext())
                {
                    var keys = new object[] { id };
                    var ent  = db.Set(type).Find(keys);

                    db.Set(type).Remove(ent);

                    db.SaveChanges();
                }
            }

            return(Redirect("~/Codelists?n=" + n));
        }
 /// <summary>
 /// Add an aggregate to the repository
 /// </summary>
 /// <typeparam name="TModel">The aggregate's type</typeparam>
 /// <param name="model">The aggregate to add</param>
 public void Add <TModel>(TModel model) where TModel : class, Core.Infrastructure.IAggregateRoot
 {
     try
     {
         _context.Set <TModel>().Add(model);
     }
     catch
     {
         throw;
     }
 }
示例#7
0
        public async Task <ActionResult <Category> > UpdateCategory(int id, [FromBody] Category newCategory)
        {
            newCategory.Id = id;
            _catalogContext.Set <Category>().Update(newCategory);
            try
            {
                await _catalogContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(newCategory != null?Ok(newCategory) : NotFound());
        }
示例#8
0
        public async Task <ActionResult <Product> > UpdateProduct(Guid id, [FromBody] Product newProduct)
        {
            newProduct.Id = id;

            _catalogContext.Set <Product>().Update(newProduct);

            try
            {
                await _catalogContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }
            return(newProduct != null?Ok(newProduct) : NotFound());
        }
示例#9
0
        public async Task <ActionResult <Supplier> > UpdateSupplier(int id, [FromBody] Supplier newSupplier)
        {
            newSupplier.Id = id;

            _catalogContext.Set <Supplier>().Update(newSupplier);
            try
            {
                await _catalogContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(newSupplier != null?Ok(newSupplier) : NotFound());
        }
示例#10
0
        public ActionResult Edit(string id)
        {
            ICodelist result = null;
            var       n      = id.Split('_');
            var       type   = _types.Where(t => t.Name == n[0]).SingleOrDefault();

            if (type != null)
            {
                using (CatalogContext db = new CatalogContext())
                {
                    var keys = new object[] { int.Parse(n[1]) };
                    result = (ICodelist)db.Set(type).Find(keys);
                    var par = result.Parent;
                }
            }

            return(PartialView(result));
        }
示例#11
0
        public void GetsExistingOrder()
        {
            var existingOrder = OrderBuilder.WithDefaultValues();

            _catalogContext.Set <Order>().Add(existingOrder);
            _catalogContext.SaveChanges();
            int orderId = existingOrder.Id;

            _output.WriteLine($"OrderId: {orderId}");

            var orderFromRepo = _orderRepository.GetById(orderId);

            Assert.Equal(OrderBuilder.TestBuyerId, orderFromRepo.BuyerId);

            // Note: Using InMemoryDatabase OrderItems is available. Will be null if using SQL DB.
            var firstItem = orderFromRepo.OrderItems.FirstOrDefault();

            Assert.Equal(OrderBuilder.TestUnits, firstItem.Units);
        }
示例#12
0
        // GET: Codelists
        public ActionResult Index(string n)
        {
            List <ICodelist> list = new List <ICodelist>();

            var type = typeof(CatalogContext).Assembly.ExportedTypes.Where(t => t.Name == n).SingleOrDefault();

            using (CatalogContext db = new CatalogContext())
            {
                var set = db.Set(type);

                foreach (var item in set)
                {
                    list.Add((ICodelist)item);
                }
            }

            ViewBag.Title = n;

            return(View(list));
        }
示例#13
0
 public ProductQueriesRepository(CatalogContext context)
 {
     _context = context;
     _dbSet   = _context.Set <Product>();
 }
示例#14
0
 public CategoryRepository(CatalogContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
 {
     _context = context;
     dbSet    = _context.Set <Category>();
 }
示例#15
0
 public virtual async Task <TEntity> GetByIdAsync(int id)
 {
     return(await _dbContext.Set <TEntity>().FindAsync(id));
 }
示例#16
0
 public virtual T GetById(int id)
 {
     return(_dbContext.Set <T>().Find(id));
 }
示例#17
0
 public CategoryQueriesRepository(CatalogContext context)
 {
     _context = context;
     _dbSet   = _context.Set <Category>();
 }
示例#18
0
        public T Create(T item)
        {
            var a = _db.Set <T>().Add(item);

            return(a);
        }
示例#19
0
 public virtual T Get(int id) => _db.Set <T>().Find(id);
示例#20
0
 public ProductRepository(CatalogContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
 {
     _context = context;
     dbSet    = _context.Set <Product>();
 }
示例#21
0
        // GET: Codelists
        public ActionResult Index(string n)
        {
            List <ICodelist> list  = new List <ICodelist>();
            List <string>    names = new List <string>()
            {
                n
            };

            var type = _types.Where(t => t.Name == n).SingleOrDefault();

            if (type != null)
            {
                ICodelist parent = null;

                using (CatalogContext db = new CatalogContext())
                {
                    var set = db.Set(type);

                    foreach (ICodelist item in set)
                    {
                        if (item.Parent != null)
                        {
                            parent = item.Parent;
                            names.Add(parent.Name);
                            var childs = parent.Childs;
                            while (parent.Parent != null)
                            {
                                parent = parent.Parent;
                                names.Add(parent.Name);
                                childs = parent.Childs;
                            }
                            break;
                        }
                        else
                        {
                            list.Add(item);
                        }
                    }

                    if (parent != null)
                    {
                        set = db.Set(parent.GetType());
                        foreach (ICodelist item in set)
                        {
                            var childs = item.Childs;
                            foreach (var c in childs)
                            {
                                var cc = c.Childs;
                            }
                            list.Add(item);
                        }
                    }
                }
            }
            ViewBag.NamesCount = names.Count - 1;
            ViewBag.Names      = names;

            ViewBag.Title = n;

            return(View(list));
        }
 public Repository(CatalogContext context)
 {
     Db    = context;
     DbSet = Db.Set <TEntity>();
 }
示例#23
0
        // GET: PipingMaterialsClassDatas
        public async Task <ActionResult> Index(string n)
        {
            var type = _types.Where(t => t.Name == n).SingleOrDefault();

            var list = await db.Set(type).ToListAsync();

            ViewBag.Type = type;

            return(View(list));
        }
示例#24
0
 protected BaseRepository(CatalogContext context, IUnitOfWork unitOfWork)
 {
     this.context    = context;
     this.unitOfWork = unitOfWork;
     DbSet           = context.Set <TEntity>();
 }
 public async Task <IReadOnlyList <T> > GetAllAsync()
 {
     return(await _dbContext.Set <T>().ToListAsync());
 }
 /// <inheritdoc />
 public IEnumerable <TDomain> LoadWhere(ISpecification <TDomain, TId> specification)
 {
     return(Context.Set <TDomain>().Where(specification.Operation()));
 }