Esempio n. 1
0
        public void AddUpdateConfigEntries(ConfigMultiEntries request)
        {
            using (var context = new TICPuppyLoveDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    context.dbTransaction = dbContextTransaction;

                    ConfigDTO cdto = new ConfigDTO { configs = request.ConfigEntries };

                    //set inserts first
                    cdto.CreateRefConfigNewUserIntances();

                    if (cdto.refConfigEntries.Count() > 0)
                    {
                        context.Add(cdto);
                    }

                    //now do updates
                    cdto.CreateRefConfigUpdateInstances();

                    if (cdto.refConfigEntries.Count() > 0)
                    {
                        context.Update(cdto);
                    }

                    // everything good, commit transaction
                    dbContextTransaction.Commit();
                }
            }
        }
Esempio n. 2
0
        public Int32 DeleteConfigurations(ConfigMultiEntries request)
        {
            Int32 response = -1;
            using (var context = new TICPuppyLoveDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    context.dbTransaction = dbContextTransaction;

                    ConfigDTO cdto = new ConfigDTO { configs = request.ConfigEntries };

                    cdto.refConfigEntries = context.GetRefConfigData();
                    cdto.refConfigEntries = cdto.GetSpecificRefConfigs();

                    context.Ref_Config.RemoveRange(cdto.refConfigEntries);
                    response =  context.SaveChanges();

                    // everything good, commit transaction
                    dbContextTransaction.Commit();
                }
            }

            return response;
        }