Exemple #1
0
        public void SaveInstrumentCategory(InstrumentCategory instrumentCategory)
        {
            DanielsEntities context = new DanielsEntities();

            COSC4210.MusicalIntruments.Web.Models.Category instrumentItemCategory = new COSC4210.MusicalIntruments.Web.Models.Category();

            if (instrumentCategory.ID != 0)
            {
                var etItemCategory = from t in context.Categories
                                     where t.ID == instrumentCategory.ID
                                     select t;

                instrumentItemCategory = etItemCategory.FirstOrDefault();

                instrumentItemCategory.CategoryName = instrumentCategory.InstrumentCategoryName;
            }
            else
            {
                instrumentItemCategory.CategoryName = instrumentCategory.InstrumentCategoryName;
                context.Categories.Add(instrumentItemCategory);
            }

            instrumentItemCategory.LastModified   = DateTime.Now;
            instrumentItemCategory.LastModifiedBy = "Phil";
            context.SaveChanges();
        }
Exemple #2
0
        public void SaveMusicalInstrument(MusicalInstrument MusicalInstrument)
        {
            DanielsEntities context = new DanielsEntities();

            COSC4210.MusicalIntruments.Web.Models.Item instrumentItem = new COSC4210.MusicalIntruments.Web.Models.Item();

            if (MusicalInstrument.ID != 0)
            {
                var etItem = from t in context.Items
                             where t.ID == MusicalInstrument.ID
                             select t;

                instrumentItem          = etItem.FirstOrDefault();
                instrumentItem.ItemName = MusicalInstrument.Name;
                instrumentItem.Brand    = MusicalInstrument.Brand;
                instrumentItem.TypeID   = MusicalInstrument.TypeID;
                instrumentItem.Price    = MusicalInstrument.Price;
            }
            else
            {
                instrumentItem.ItemName = MusicalInstrument.Name;
                instrumentItem.Brand    = MusicalInstrument.Brand;
                instrumentItem.Price    = MusicalInstrument.Price;
                instrumentItem.TypeID   = MusicalInstrument.TypeID;
                context.Items.Add(instrumentItem);
            }


            instrumentItem.LastModified   = DateTime.Now;
            instrumentItem.LastModifiedBy = "Phil";
            context.SaveChanges();
        }
Exemple #3
0
        public void SaveInstrumentType(InstrumentType instrumentType)
        {
            DanielsEntities context = new DanielsEntities();

            COSC4210.MusicalIntruments.Web.Models.Type instrumentItemType = new COSC4210.MusicalIntruments.Web.Models.Type();

            if (instrumentType.ID != 0)
            {
                var etItemType = from t in context.Types
                                 where t.ID == instrumentType.ID
                                 select t;

                instrumentItemType = etItemType.FirstOrDefault();

                instrumentItemType.TypeName = instrumentType.TypeName;
            }
            else
            {
                instrumentItemType.TypeName = instrumentType.TypeName;
                context.Types.Add(instrumentItemType);
            }

            instrumentItemType.LastModified   = DateTime.Now;
            instrumentItemType.LastModifiedBy = "Phil";
            context.SaveChanges();
        }
Exemple #4
0
        public IList <InstrumentCategory> DeleteCategoryAssociation(int InstrumentID, int CategoryID)
        {
            DanielsEntities context = new DanielsEntities();

            var assoc = from t in context.ItemCategories
                        where t.ItemID == InstrumentID && t.CategoryID == CategoryID
                        select t;

            ItemCategory category = assoc.FirstOrDefault();

            context.ItemCategories.Remove(category);
            context.SaveChanges();
            return(GetCategoryAssociations(InstrumentID));
        }
Exemple #5
0
        public IList <InstrumentCategory> AddCategoryAssociation(int InstrumentID, int CategoryID)
        {
            DanielsEntities context = new DanielsEntities();

            Models.ItemCategory association = new ItemCategory();

            association.CategoryID     = CategoryID;
            association.ItemID         = InstrumentID;
            association.LastModified   = DateTime.Now;
            association.LastModifiedBy = "Phil";

            context.ItemCategories.Add(association);

            context.SaveChanges();

            return(GetCategoryAssociations(InstrumentID));
        }