Exemplo n.º 1
0
 public IActionResult CreateAssociation(int id, AssociationWrapper Form)
 {
     Form.AssociationForm.ProductId = id;
     _context.Add(Form.AssociationForm);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        public IActionResult AddProduct(Product Form)
        {
            AssociationWrapper CMod = new AssociationWrapper();

            CMod.CategoryDropdown = _context.Categories.ToList();
            return(View("AddProduct", Form));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fills the references of a <see cref="PersistentObject"/>
        /// </summary>
        /// <param name="pObject"><see cref="PersistentObject"/> to fill references</param>
        private void FillReferences(ClassWrapper classWrapper, DataRow row, PersistentObject pObject)
        {
            foreach (PropertyWrapper fw in classWrapper.GetRelationWrapper())
            {
                if (fw.IsList)
                {
                    continue;
                }

                string oid = row[fw.Name] as string;

                if (oid != null && !oid.Equals(""))
                {
                    Guid uuidToCompare = new Guid(oid);

                    AssociationWrapper asW = fw.GetForeignKey();
                    ClassWrapper       cw  = asW.AssociationPartnerClass;
                    Type cl = cw.ClassToWrap;

                    // check if refObj is already loaded
                    PersistentObject refObj = ObjectCache.GetTemp(cl).FirstOrDefault(x => x.ID.Equals(uuidToCompare));

                    if (refObj == null)
                    {
                        refObj = GetObject(cl, uuidToCompare, true);
                    }

                    pObject.SetRelation(fw.OriginalField.Name, refObj);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the member name to the new value and also updates the referenced objects reference
        /// </summary>
        /// <param name="memberName">the name of the changed to change</param>
        /// <param name="value">the new value</param>
        public void SetRelation(string memberName, PersistentObject value)
        {
            SetMemberValue(memberName, value);

            AssociationWrapper aw = objectSpace.WrappingHandler.GetClassWrapper(GetType())
                                    .GetFieldWrapper(memberName, true).GetForeignKey();

            if (aw != null && aw.AssociationPartner != null && !aw.AssociationPartner.IsList)
            {
                value.SetMemberValue(aw.AssociationPartner.OriginalField.Name, this);
            }
        }
Exemplo n.º 5
0
 public IActionResult CreateProduct(AssociationWrapper Form)
 {
     if (ModelState.IsValid)
     {
         _context.Add(Form.ToDisplay);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(Index());
     }
 }
Exemplo n.º 6
0
        public IActionResult AddAssociation(int id)
        {
            AssociationWrapper WMod = new AssociationWrapper();

            WMod.ToDisplay = _context.Products
                             .Include(a => a.ProdAndCatAssoc)
                             .FirstOrDefault(a => a.ProductId == id);

            WMod.CategoryDropdown = _context.Categories
                                    .Include(p => p.Associations)
                                    .Where(p => p.CategoryId != WMod.ToDisplay.ProdCategoryId && !p.Associations.Any(v => v.ProductId == WMod.ToDisplay.ProductId))
                                    .ToList();
            return(View("AddAssociation", WMod));
        }