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


C# ApplicationDbContext.Add方法代码示例

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


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

示例1: CrearClase

        public bool CrearClase(Clase clase)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                try
                {
                    db.Add(clase);
                    db.SaveChanges();
                    return true;
                }
                catch (Exception)
                {

                    return false;
                }

            }
        }
开发者ID:CarlosOlivares,项目名称:web,代码行数:18,代码来源:GestionDeCursos.cs

示例2: CrearCurso

        /// <summary>
        /// Método para crear un nuevo curso si se ha declarado antes el atributo curso.
        /// </summary>
        /// <returns></returns>
        public bool CrearCurso()
        {
            if (this._Curso == null) return false;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                db.Add(this._Curso);
                db.SaveChanges();
                return true;
            }
        }
开发者ID:CarlosOlivares,项目名称:web,代码行数:15,代码来源:GestionDeCursos.cs

示例3: SetGlobalConfigurations

        private void SetGlobalConfigurations(ApplicationDbContext context)
        {

            if (context.ApplicationConfig.Any())
            {
                Configurations.ApplicationConfig = context.ApplicationConfig.First();
            }
            else
            {
                Configurations.ApplicationConfig = new ApplicationConfig();
                context.Add(Configurations.ApplicationConfig);
                context.SaveChanges();
            }

        }
开发者ID:ChavFDG,项目名称:Old-Stolons,代码行数:15,代码来源:Startup.cs

示例4: CreateProductsSamples

        private void CreateProductsSamples(ApplicationDbContext context)
        {
            if (context.Products.Any())
                return;
            Product pain = new Product();
            pain.Name = "Pain complet";
            pain.Description = "Pain farine complete T80";
            pain.Labels.Add(Product.Label.Ab);
            pain.PicturesSerialized= Path.Combine(Configurations.ProductsStockagePath, "pain.png");
            pain.Price = 15.5F;
	    pain.UnitPrice = 4;
            pain.Producer = context.Producers.First();
            pain.ProductUnit = Product.Unit.Kg;
            pain.RemainingStock = 10;
            pain.State = Product.ProductState.Enabled;
            pain.Type = Product.SellType.Piece;
            pain.WeekStock = 10;
            pain.Familly = context.ProductFamillys.First(x => x.FamillyName == "Pains");
            context.Add(pain);
            Product tomate = new Product();
            tomate.Name = "Tomates grappe";
            tomate.Description = "Avec ces tomates, c'est nous qui rougissons même si elles ne sont pas toutes nues!";
            tomate.Labels.Add(Product.Label.Ab);
            tomate.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "tomate.jpg");
	    tomate.Price = 3;
	    tomate.UnitPrice = 1.5F;
	    tomate.QuantityStep = 500;
            tomate.Producer = context.Producers.First();
            tomate.ProductUnit = Product.Unit.Kg;
            tomate.RemainingStock = 10;
            tomate.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            tomate.State = Product.ProductState.Enabled;
            tomate.Type = Product.SellType.Weigh;
            tomate.WeekStock = 10;
            context.Add(tomate);
            Product pommedeterre = new Product();
            pommedeterre.Name = "Pomme de terre";
            pommedeterre.Description = "Pataaaaaaaaaaaaaaaates!!";
            pommedeterre.Labels.Add(Product.Label.Ab);
            pommedeterre.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "pommedeterre.jpg");
            pommedeterre.Price = 1.99F;
	    pommedeterre.UnitPrice = 1.99F;
	    pommedeterre.QuantityStep = 1000;
            pommedeterre.Producer = context.Producers.First();
            pommedeterre.ProductUnit = Product.Unit.Kg;
            pommedeterre.RemainingStock = 10;
            pommedeterre.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            pommedeterre.State = Product.ProductState.Enabled;
            pommedeterre.Type = Product.SellType.Weigh;
            pommedeterre.WeekStock = 10;
            context.Add(pommedeterre);
            Product radis = new Product();
            radis.Name = "Radis";
            radis.Description = "Des supers radis (pour ceux qui aiment)";
            radis.Labels.Add(Product.Label.Ab);
            radis.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "radis.jpg");
            radis.Price = 0;
	    radis.UnitPrice = 4;
            radis.Producer = context.Producers.First();
            radis.ProductUnit = Product.Unit.Kg;
            radis.RemainingStock = 10;
            radis.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            radis.State = Product.ProductState.Enabled;
            radis.Type = Product.SellType.Piece;
            radis.WeekStock = 10;
            context.Add(radis);
            Product salade = new Product();
            salade.Name = "Salade";
            salade.Description = "Une bonne salade pour aller avec les bonnes tomates!";
            salade.Labels.Add(Product.Label.Ab);
            salade.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "salade.jpg");
            salade.UnitPrice = 0.80F;
	    salade.Price = 0;
            salade.Producer = context.Producers.First();
            salade.ProductUnit = Product.Unit.Kg;
            salade.RemainingStock = 10;
            salade.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            salade.State = Product.ProductState.Enabled;
            salade.Type = Product.SellType.Piece;
            salade.WeekStock = 10;
            context.Add(salade);

            //
            context.SaveChanges();
        }
开发者ID:ChavFDG,项目名称:Old-Stolons,代码行数:85,代码来源:Startup.cs

示例5: CreateStolons

        private List<Stolon> CreateStolons(ApplicationDbContext context)
        {
            List<Stolon> stolons = new List<Stolon>();
            Stolon stolon = new Stolon();
            stolon.IsInMaintenance = false;
            stolon.IsModeSimulated = false;

            stolon.Label = "Stolons de Privas";
            stolon.AboutPageText = "Les Stolons de Privas est une association loi 1901";
            stolon.Address = "07000 PRIVAS";
            stolon.PhoneNumber = "06 64 86 66 93";
            stolon.ContactMailAddress = "[email protected]";

            stolon.DeliveryAndStockUpdateDayStartDate = DayOfWeek.Wednesday;
            stolon.DeliveryAndStockUpdateDayStartDateHourStartDate = 12;
            stolon.DeliveryAndStockUpdateDayStartDateMinuteStartDate = 00;
            stolon.OrderDayStartDate = DayOfWeek.Sunday;
            stolon.OrderHourStartDate = 16;
            stolon.OrderMinuteStartDate = 00;

            stolon.UseSubscipstion = true;
            stolon.SubscriptionStartMonth = Stolon.Month.September;

            stolon.OrderDeliveryMessage = "Votre panier est disponible jeudi de 17h30 à 19h au : 10 place de l'hotel de ville, 07000 Privas";

            stolon.UseProducersFee = true;
            stolon.ProducersFee = 5;

            stolon.UseSympathizer = true;
            stolon.SympathizerSubscription = 2;
            stolon.ConsumerSubscription = 10;
            stolon.ProducerSubscription = 20;

            context.Add(stolon);
            context.SaveChanges();

            stolons.Add(stolon);
            return stolons;
        }
开发者ID:ChavFDG,项目名称:Stolons,代码行数:39,代码来源:Startup.cs

示例6: CreateProductsSamples

        private void CreateProductsSamples(ApplicationDbContext context)
        {
            if (context.Products.Any())
                return;
            Product pain = new Product();
            pain.Name = "Pain complet";
            pain.Description = "Pain farine complete T80";
            pain.Labels.Add(Product.Label.Ab);
            pain.PicturesSerialized = Path.Combine("pain.png");
            pain.Price = Convert.ToDecimal(15.5);
            pain.UnitPrice = 4;
            pain.TaxEnum = Product.TAX.Ten;
            pain.Producer = context.Producers.First();
            pain.ProductUnit = Product.Unit.Kg;
            pain.StockManagement = Product.StockType.Week;
            pain.RemainingStock = 10;
            pain.State = Product.ProductState.Enabled;
            pain.Type = Product.SellType.Piece;
            pain.WeekStock = 10;
            pain.Familly = context.ProductFamillys.First(x => x.FamillyName == "Pains");
            context.Add(pain);
            Product tomate = new Product();
            tomate.Name = "Tomates grappe";
            tomate.Description = "Avec ces tomates, c'est nous qui rougissons même si elles ne sont pas toutes nues!";
            tomate.Labels.Add(Product.Label.Ab);
            tomate.PicturesSerialized = Path.Combine("tomate.jpg");
            tomate.Price = 3;
            tomate.TaxEnum = Product.TAX.FiveFive;
            tomate.UnitPrice = Convert.ToDecimal(1.5);
            tomate.QuantityStep = 500;
            tomate.Producer = context.Producers.First();
            tomate.ProductUnit = Product.Unit.Kg;
            tomate.StockManagement = Product.StockType.Week;
            tomate.RemainingStock = 10;
            tomate.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            tomate.State = Product.ProductState.Enabled;
            tomate.Type = Product.SellType.Weigh;
            tomate.WeekStock = 10;
            context.Add(tomate);
            Product pommedeterre = new Product();
            pommedeterre.Name = "Pomme de terre";
            pommedeterre.Description = "Pataaaaaaaaaaaaaaaates!!";
            pommedeterre.Labels.Add(Product.Label.Ab);
            pommedeterre.PicturesSerialized = Path.Combine("pommedeterre.jpg");
            pommedeterre.Price = Convert.ToDecimal(1.99);
            pommedeterre.TaxEnum = Product.TAX.FiveFive;
            pommedeterre.UnitPrice = Convert.ToDecimal(1.99);
            pommedeterre.QuantityStep = 1000;
            pommedeterre.Producer = context.Producers.First();
            pommedeterre.ProductUnit = Product.Unit.Kg;
            pommedeterre.StockManagement = Product.StockType.Week;
            pommedeterre.RemainingStock = 10;
            pommedeterre.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            pommedeterre.State = Product.ProductState.Enabled;
            pommedeterre.Type = Product.SellType.Weigh;
            pommedeterre.WeekStock = 10;
            context.Add(pommedeterre);
            Product radis = new Product();
            radis.Name = "Radis";
            radis.Description = "Des supers radis (pour ceux qui aiment)";
            radis.Labels.Add(Product.Label.Ab);
            radis.PicturesSerialized = Path.Combine("radis.jpg");
            radis.Price = 0;
            radis.UnitPrice = 4;
            radis.TaxEnum = Product.TAX.FiveFive;
            radis.Producer = context.Producers.First();
            radis.ProductUnit = Product.Unit.Kg;
            radis.StockManagement = Product.StockType.Week;
            radis.RemainingStock = 10;
            radis.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            radis.State = Product.ProductState.Enabled;
            radis.Type = Product.SellType.Piece;
            radis.WeekStock = 10;
            context.Add(radis);
            Product salade = new Product();
            salade.Name = "Salade";
            salade.Description = "Une bonne salade pour aller avec les bonnes tomates!";
            salade.Labels.Add(Product.Label.Ab);
            salade.PicturesSerialized = Path.Combine("salade.jpg");
            salade.UnitPrice = Convert.ToDecimal(0.80);
            salade.TaxEnum = Product.TAX.FiveFive;
            salade.Price = 0;
            salade.Producer = context.Producers.First();
            salade.ProductUnit = Product.Unit.Kg;
            salade.StockManagement = Product.StockType.Week;
            salade.RemainingStock = 10;
            salade.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            salade.State = Product.ProductState.Enabled;
            salade.Type = Product.SellType.Piece;
            salade.WeekStock = 10;
            context.Add(salade);
            Product conserveTomate = new Product();
            conserveTomate.Name = "Bocaux de tomate 500ml";
            conserveTomate.Description = "Bocaux de tomate du jardin, cuillie mur et transformé dans la semaine. Bocaux en verre d'une contenance de 500ml";
            conserveTomate.PicturesSerialized = Path.Combine("ConserveTomate.jpg");
            conserveTomate.UnitPrice = Convert.ToDecimal(4);
            conserveTomate.TaxEnum = Product.TAX.None;
            conserveTomate.Price = 0;
            conserveTomate.Producer = context.Producers.First();
            conserveTomate.ProductUnit = Product.Unit.L;
//.........这里部分代码省略.........
开发者ID:ChavFDG,项目名称:Stolons,代码行数:101,代码来源:Startup.cs

示例7: SeedOfficers

        private void SeedOfficers(IServiceProvider applicationServices)
        {
            using (var context = new ApplicationDbContext(
                applicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>()))
            {
                if (context.List2.Any())
                {
                    return;   // DB has been seeded
                }

                var lines = File.ReadAllLines("wwwroot/MUleader_V2.csv");

                for (int i = 1; i < lines.Count(); i++)
                {
                    var items = lines[i].Split(',');
                    context.Add(new List2
                    {
                        //officerID,nameID,name,beginyr,endyr,cname,pos,cityID
                        officerID = long.Parse(items[0]),
                        nameID = long.Parse(items[1]),
                        name = items[2],
                        beginyr = long.Parse(items[3]),
                        endyr = long.Parse(items[4]),
                        cname = items[5],
                        pos = items[6],
                        cityID = items[7] != "" ? long.Parse(items[7]) : 0,
                        rid = -1
                    });
                }
                context.SaveChanges();
            }
        }
开发者ID:ZhangYuef,项目名称:Survey_Platform_ccer,代码行数:32,代码来源:Startup.cs

示例8: PerformActions

        public static void PerformActions(ApplicationDbContext db, ClientActionModel model, DataCache data)
        {
            var actionCounter = new Dictionary<string, int>();
            actionCounter[Constants.Constants.ActionTypeResearch] = 0;
            string currentObjectName = "";

            if (string.IsNullOrEmpty(model.Actions))
            {
                LogService.Log(db, data.Corporation, "You made no actions the previous turn.");
                return;
            }

            var actions = model.Actions.Split('|');
            foreach (var actionType in actions)
            {
                var currentActionDict = new Dictionary<string, string>();
                var actionItems = actionType.Split(';');
                foreach (var a in actionItems)
                {
                    var parameters = a.Split('=');
                    if (string.IsNullOrEmpty(parameters[0])) continue;
                    currentActionDict[parameters[0]] = parameters[1];
                }

                //Handle action types---
                if (currentActionDict.ContainsKey(Constants.Constants.ActionType))
                {
                    if (currentActionDict[Constants.Constants.ActionType] == Constants.Constants.ActionTypeResearch)
                        actionCounter[Constants.Constants.ActionTypeResearch]++;
                }

                //Handle actions---
                if (currentActionDict.ContainsKey(Constants.Constants.Action))
                {
                    var specifierSplit = currentActionDict[Constants.Constants.Action].Split(':');
                    currentObjectName = specifierSplit[1];

                    //#LearnResearch
                    if (specifierSplit[0] == Constants.Constants.LearnResearch)
                    {
                        var researchNode = db.ResearchNodes.FirstOrDefault(n => n.Name == currentObjectName);

                        if (currentActionDict[Constants.Constants.ActionParameter] == Constants.Constants.LearnByCash) //Research is bought with cash
                        {
                            var node = data.ResearchNodes.FirstOrDefault(n => n.Name == currentObjectName);
                            if (node == null)
                                LogService.Log(db, data.Corporation, "ERROR: Attempting to add node " + currentObjectName +
                                             " that does not exist.");
                            else
                            {
                                if (node.CashCost > data.Corporation.Cash)
                                    LogService.Log(db, data.Corporation, "Error: Not enough cash to purchase research node " + currentObjectName);
                                else
                                {
                                    data.Corporation.Cash -= node.CashCost;
                                    var lrn = new LearnedResearchNode
                                    {
                                        Corporation = data.Corporation,
                                        ResearchNode = researchNode
                                    };
                                    db.Add(lrn);
                                    LogService.Log(db, data.Corporation, "Research " + currentObjectName + " purchased.");
                                }
                            }
                        }
                        else if (currentActionDict[Constants.Constants.ActionParameter] == Constants.Constants.SetActiveResearch) //Research is set to active
                        {

                            data.ActiveResearchNodes.ForEach(n => n.Active = false);

                            var active =
                                data.ActiveResearchNodes.FirstOrDefault(n => n.ResearchNode.Name == currentObjectName);

                            if (active != null) //If not null, we have already started researching it, so set to false
                            {
                                active.Active = true;
                                var toRemove = data.ActiveResearchNodes.Where(n => n.Id != active.Id);
                                db.Remove(toRemove);
                            }
                            else
                            {
                                active = new ActiveResearchNode();
                                active.ResearchNode = researchNode;
                                active.Corporation = data.Corporation;
                                active.Active = true;
                                db.Add(active);
                            }
                            LogService.Log(db, data.Corporation, "Set " + currentObjectName + " to active research. ");
                        }

                        var validated = data.LearnableResearchNodeNames.Contains(currentObjectName);
                        if (!validated)
                        {
                            LogService.Log(db, data.Corporation, "Error: Already learned node " + currentObjectName);
                        }
                    }
                    //#CancelActiveResearch
                    else if (specifierSplit[0] == Constants.Constants.CancelActiveResearch)
                    {
                        if (!data.ActiveResearchNodesSchemaNodes.Select(n => n.Name).Contains(specifierSplit[1]))
//.........这里部分代码省略.........
开发者ID:taylorrobert,项目名称:WebRPG,代码行数:101,代码来源:ActionService.cs

示例9: CreateTestTreeInDB

        public static void CreateTestTreeInDB(ApplicationDbContext db, Corporation corp)
        {
            var node1 = new ResearchNode
            {
                Name = "Basic Rocketry",
                Description = "The basics.",
                RDCost = 10,
                CashCost = 50000,
                Script = "Action=LearnResearch:Basic Rocketry;Unlocks=Intermediate Rocketry;"
            };

            var node2 = new ResearchNode
            {
                Name = "Intermediate Rocketry",
                Description = "Werner von Braun would be delighted.",
                RDCost = 30,
                CashCost = 400000,
                Script = "Action=LearnResearch:Intermediate Rocketry;Prereq=Basic Rocketry;Unlocks=Advanced Rocketry"
            };

            var node3 = new ResearchNode
            {
                Name = "Advanced Rocketry",
                Description = "Einstein ain't got shit on these badass rockets.",
                RDCost = 75,
                CashCost = 4000000,
                Script = "Action=LearnResearch:Advanced Rocketry;Prereq=Intermediate Rocketry&Basic Rocketry;"
            };

            var learnedNode1 = new LearnedResearchNode()
            {
                Corporation = corp,
                ResearchNode = node1
            };

            db.Add(node1);
            db.Add(node2);
            db.Add(node3);
            db.Add(learnedNode1);
            db.SaveChanges();
        }
开发者ID:taylorrobert,项目名称:WebRPG,代码行数:41,代码来源:ResearchTree.cs


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