public ActionResult Create(DemotblEmployee emp)
        {
            SampleDb sampleDb = new SampleDb();

            sampleDb.DemotblEmployees.Add(emp);
            sampleDb.SaveChanges();
            return(RedirectToAction("Index"));
        }
            public override async Task <bool> InvokeAsync(string paramList)
            {
                var shipperCities = new[]
                {
                    "Guadalajara, JAL, Mexico", "Los Angeles, CA, USA", "Portland, OR, USA", "Leon, GTO, Mexico",
                    "Boston, MA, USA"
                };

                var companies = new[]
                {
                    "Unosquare LLC", "Advanced Technology Systems", "Super La Playa", "Vesta", "Microsoft", "Oxxo",
                    "Simian"
                };

                var rand     = new Random();
                var products = _context.Products.ToArray();

                var order = new Order
                {
                    CustomerName = companies[rand.Next(companies.Length - 1)],
                    IsShipped    = rand.Next(10) > 5,
                    ShipperCity  = shipperCities[rand.Next(shipperCities.Length - 1)],
                    ShippedDate  = DateTime.Now.AddDays(1 - rand.Next(10)),
                    OrderType    = rand.Next(30),
                    Amount       = 10
                };

                //for (var k = 0; k < rand.Next(10); k++)
                //{
                //    order.Details.Add(new OrderDetail
                //    {
                //        Price = rand.Next(10),
                //        Description = "Product ID" + rand.Next(1000),
                //        Quantity = rand.Next(10),
                //        ProductID = products[rand.Next(products.Length - 1)].ProductID
                //    });
                //}

                // order.Amount = order.Details.Sum(x => x.Price*x.Quantity);

                OutputInformation("OrderID {0}", order.OrderID);
                OutputInformation("OrderType {0}", order.OrderType);
                OutputInformation("ShippedDate {0}", order.ShippedDate);
                OutputInformation("ShipperCity {0}", order.ShipperCity);

                _context.Orders.Add(order);

                _context.SaveChanges();

                OutputInformation("After save");

                OutputInformation("OrderID {0}", order.OrderID);
                OutputInformation("OrderType {0}", order.OrderType);
                OutputInformation("ShippedDate {0}", order.ShippedDate);
                OutputInformation("ShipperCity {0}", order.ShipperCity);

                return(true);
            }
        public ActionResult Delete(DemotblEmployee demoemp)
        {
            SampleDb        sampleDb         = new SampleDb();
            DemotblEmployee selectedEmployee = sampleDb.DemotblEmployees.FirstOrDefault(x => x.Id == demoemp.Id);

            sampleDb.DemotblEmployees.Remove(selectedEmployee);
            sampleDb.SaveChanges();

            return(RedirectToAction("Index"));
        }
            public override async Task <bool> InvokeAsync(string paramList)
            {
                OutputInformation("Last Order");

                var lastitem = _context.Orders.OrderByDescending(x => x.OrderID).FirstOrDefault();

                if (lastitem != null)
                {
                    lastitem.ShipperCity = "Modified";
                    _context.SaveChanges();
                }

                return(true);
            }
        private static void Main(string[] args)
        {
            var console = new ClientConsole();

            Effort.Provider.EffortProviderConfiguration.RegisterProvider();
            var connection = DbConnectionFactory.CreateTransient();

            using (var context = new SampleDb(connection, "geo"))
            {
                console.WriteLine("Welcome to EF Test Console, type help to check available commands",
                                  OutputLevel.Information, null);

                context.Products.AddRange(new[]
                {
                    new Product {
                        Name = "CocaCola"
                    },
                    new Product {
                        Name = "Pepsi"
                    },
                    new Product {
                        Name = "Starbucks"
                    },
                    new Product {
                        Name = "Donut"
                    }
                });

                context.SaveChanges();

                var ct = new System.Threading.CancellationToken();
                Task.Run(() => { SingletonSampleJob.Instance.RunBackgroundWork(ct); }, ct);

                var command = new RootCommand(console);

                command.RegisterCommand(new FillOrderCommand(context));
                command.RegisterCommand(new EditOrder(context));
                command.RegisterCommand(new QueryAuditTrail(context));
                command.RegisterCommand(new QueryOrder(context));
                command.RegisterCommand(new ToggleController(context));
                command.RegisterCommand(new JobController(context));

                var commandEngine = new CommandEngine(command);

                commandEngine.Run(args);
            }
        }
        public ActionResult Edit(DemotblEmployee demoemp)
        {
            SampleDb sampleDb = new SampleDb();

            //DemotblEmployee selectedEmployee = sampleDb.DemotblEmployees.FirstOrDefault(x => x.Id == demoemp.Id);
            //selectedEmployee.FullName = demoemp.FullName;
            //selectedEmployee.Gender = demoemp.Gender;
            //selectedEmployee.Age = demoemp.Age;
            //selectedEmployee.EmailAddress = demoemp.EmailAddress;
            //selectedEmployee.HireDate = demoemp.HireDate;
            //selectedEmployee.Salary= demoemp.Salary;
            //selectedEmployee.PersonalWebSite = demoemp.PersonalWebSite;

            sampleDb.Entry(demoemp).State = System.Data.Entity.EntityState.Modified;
            sampleDb.SaveChanges();
            return(RedirectToAction("Index"));
        }