当前位置: 首页>>代码示例>>C#>>正文


C# IDataContext.Add方法代码示例

本文整理汇总了C#中IDataContext.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IDataContext.Add方法的具体用法?C# IDataContext.Add怎么用?C# IDataContext.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDataContext的用法示例。


在下文中一共展示了IDataContext.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        /// <summary>
        /// Create a new web by specified web template.
        /// </summary>
        /// <param name="template">The web template object.</param>
        /// <param name="dbContext">The data context object.</param>
        /// <param name="name">The new web name.</param>
        /// <param name="owner">The new web owner name.</param>
        /// <returns>A new web instance created from template.</returns>
        public static Web Install(this WebElement template, IDataContext dbContext, string name, string owner)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            var thisWeb = dbContext.Find<Web>(w => w.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (thisWeb == null)
            {
                thisWeb = new Web()
                {
                    Name = name,
                    Owner = string.IsNullOrEmpty(owner) ? name : owner,
                    Created = DateTime.UtcNow,
                    MostOnlined = DateTime.UtcNow,
                    MostOnlineUserCount = 1,
                    IsEnabled = true
                };

                //thisWeb.Popuplate(template);
                thisWeb = dbContext.Add(thisWeb);
                dbContext.SaveChanges();
            }

            foreach (var wpTmpl in template.Pages)
                wpTmpl.Install(dbContext, thisWeb);

            return thisWeb;
        }
开发者ID:howej,项目名称:dotnetage,代码行数:37,代码来源:InstallationHelpers.cs

示例2: Start

        public virtual void Start(IDataContext context = null)
        {
            Initialize();
            context = context.ToNonReadOnly();
            if (!context.Contains(NavigationConstants.IsDialog))
                context.Add(NavigationConstants.IsDialog, false);
            var app = MvvmApplication.Current;
            var viewModelType = app.GetStartViewModelType();

            var mappingProvider = app.IocContainer.Get<IViewMappingProvider>();
            IViewMappingItem mapping = mappingProvider.FindMappingForViewModel(viewModelType, context.GetData(NavigationConstants.ViewName), true);
            if (typeof(Page).IsAssignableFrom(mapping.ViewType))
            {
                _rootWindow = CreateNavigationWindow();
                var service = CreateNavigationService(_rootWindow);
                app.IocContainer.BindToConstant(service);
            }
            app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this);
            app.Start(context);
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:20,代码来源:WpfBootstrapperBase.cs

示例3: SetAttributeValue

 private static void SetAttributeValue(View view, Context context, IAttributeSet attrs, int[] groupId,
     int requiredAttributeId, string attachedMemberName, IDataContext dataContext, DataConstant<int> constant)
 {
     int? value = ReadAttributeValueId(context, attrs, groupId, requiredAttributeId);
     if (!value.HasValue)
         return;
     dataContext.Add(constant, value.Value);
     IBindingMemberInfo member = BindingServiceProvider
         .MemberProvider
         .GetBindingMember(view.GetType(), attachedMemberName, false, false);
     if (member != null)
         member.SetSingleValue(view, value);
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:13,代码来源:ViewFactory.cs

示例4: btnNew_Click

        private void btnNew_Click(object sender, EventArgs e)
        {
            IList<TakmicarskaKategorija> dodeljeneKategorije = getDodeljeneKategorije();
            if (dodeljeneKategorije.Count == kategorijeCount)
            {
                MessageDialogs.showMessage(
                    "Vec su odredjeni rasporedi sudija za sve kategorije.", this.Text);
                return;
            }

            string msg = "Izaberite kategorije za koje vazi raspored sudija";
            DialogResult dlgResult = DialogResult.None;
            SelectKategorijaForm form = null;
            try
            {
                form = new SelectKategorijaForm(takmicenje.Id, dodeljeneKategorije,
                    false, msg);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelektovaneKategorije.Count == 0)
                return;

            RasporedSudija newRaspored = null;
            bool added = false;
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                newRaspored = new RasporedSudija(form.SelektovaneKategorije, deoTakKod, takmicenje);
                dataContext.Add(newRaspored);

                dataContext.Commit();
                added = true;
            }
            catch (Exception ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showMessage(
                    Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
            }
            finally
            {
                if (dataContext != null)
                    dataContext.Dispose();
                dataContext = null;
            }

            if (!added)
            {
                Close();
                return;
            }

            rasporedi.Add(newRaspored);
            tabOpened.Add(false);

            createTab(newRaspored);
            if (tabControl1.SelectedIndex != tabControl1.TabPages.Count - 1)
                tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1;
            else
                onSelectedIndexChanged();
        }
开发者ID:stankela,项目名称:bilten,代码行数:71,代码来源:RasporedSudijaForm.cs

示例5: CreateBuilder

 public IBindingBuilder CreateBuilder(IDataContext context = null)
 {
     context = context.ToNonReadOnly();
     if (!context.Contains(BindingBuilderConstants.BuildDelegate))
         context.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate);
     return new BindingBuilder(context);
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:7,代码来源:BindingProvider.cs

示例6: Start

 public virtual void Start(IDataContext context = null)
 {
     Initialize();
     context = context.ToNonReadOnly();
     if (!context.Contains(NavigationConstants.IsDialog))
         context.Add(NavigationConstants.IsDialog, false);
     var app = MvvmApplication.Current;
     app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this);
     app.Start(context);
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:10,代码来源:WinFormsBootstrapperBase.cs

示例7: addCmd

        private void addCmd()
        {
            NacinIzboraGimnasticaraForm form2 = new NacinIzboraGimnasticaraForm();
            if (form2.ShowDialog() != DialogResult.OK)
                return;

            List<GimnasticarUcesnik> selGimnasticari = new List<GimnasticarUcesnik>();

            DialogResult dlgResult = DialogResult.None;
            SelectGimnasticariPrethTakmForm form3 = null;
            SelectGimnasticarForm form = null;
            if (form2.IzPrethodnogTakmicenja)
            {
                try
                {
                    form3 = new SelectGimnasticariPrethTakmForm(ActiveKategorija.Gimnastika, false);
                    dlgResult = form3.ShowDialog();
                }
                catch (InfrastructureException ex)
                {
                    MessageDialogs.showError(ex.Message, this.Text);
                }
                if (dlgResult != DialogResult.OK || form3.SelectedGimnasticari.Count == 0)
                    return;
            }
            else
            {
                try
                {
                    form = new SelectGimnasticarForm(ActiveKategorija.Gimnastika);
                    dlgResult = form.ShowDialog();
                }
                catch (InfrastructureException ex)
                {
                    MessageDialogs.showError(ex.Message, this.Text);
                }

                if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
                    return;
            }

            bool added = false;
            List<GimnasticarUcesnik> okGimnasticari = new List<GimnasticarUcesnik>();
            List<GimnasticarUcesnik> illegalGimnasticari = new List<GimnasticarUcesnik>();
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                if (form2.IzPrethodnogTakmicenja)
                {
                    foreach (GimnasticarUcesnik g in form3.SelectedGimnasticari)
                    {
                        selGimnasticari.Add(createGimnasticarUcesnik(
                            g, ActiveKategorija));
                    }
                }
                else
                {
                    foreach (Gimnasticar g in form.SelectedEntities)
                    {
                        selGimnasticari.Add(createGimnasticarUcesnik(
                            g, ActiveKategorija));
                    }
                }

                foreach (GimnasticarUcesnik g in selGimnasticari)
                {
                    //GimnasticarUcesnik gimnasticar = createGimnasticarUcesnik(
                    //    g, ActiveKategorija);
                    if (canAddGimnasticar(g/*imnasticar*/, ActiveKategorija))
                        okGimnasticari.Add(g/*imnasticar*/);
                    else
                        illegalGimnasticari.Add(g);
                }

                foreach (GimnasticarUcesnik g in okGimnasticari)
                    dataContext.Add(g);
                dataContext.Commit();
                added = true;
            }
            catch (Exception ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showMessage(
                    Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
            }
            finally
            {
                if (dataContext != null)
                    dataContext.Dispose();
                dataContext = null;
            }

            if (!added)
            {
                Close();
                return;
//.........这里部分代码省略.........
开发者ID:stankela,项目名称:bilten,代码行数:101,代码来源:TakmicariKategorijeForm.cs


注:本文中的IDataContext.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。