예제 #1
0
        public async Task <Customer> InsertCustomerAsync(Customer customer)
        {
            _Context.Add(customer);
            try
            {
                await _Context.SaveChangesAsync();
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(InsertCustomerAsync)}: " + exp.Message);
            }

            return(customer);
        }
예제 #2
0
        //public async Task<PagingResult<Customer>> GetCustomersPageAsync(int skip, int take)
        //{
        //    var totalRecords = await _Context.Customers.CountAsync();
        //    var customers = await _Context.Customers
        //                         .OrderBy(c => c.LastName)
        //                         .Include(c => c.State)
        //                         .Include(c => c.Orders)
        //                         .Skip(skip)
        //                         .Take(take)
        //                         .ToListAsync();
        //    return new PagingResult<Customer>(customers, totalRecords);
        //}
        public async Task <PeriodicElement> InsertPeriodicElementAsync(PeriodicElement element)
        {
            _context.Add(element);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(InsertPeriodicElementAsync)}: " + exp.Message);
            }

            return(element);
        }
예제 #3
0
 public void Create(OrderLine orderLine)
 {
     db.Add(orderLine);
 }
        public async Task EnsureSeedData(UserManager <IdentityUser> userManager,
                                         RoleManager <IdentityRole> roleManager,
                                         ILoggerFactory loggerFactory,
                                         FoodDbContext context)
        {
            _context = context;

            context.Database.EnsureCreated();

            if (context.Users.Any())
            {
                return; // Db has been seeded.
            }
            await AddUserNotes();

            //context.Users.RemoveRange(context.Users);
            //context.SaveChanges();

            await AddPeriodicElements();

            // Creates Roles.
            await roleManager.CreateAsync(new IdentityRole("administrator"));

            await roleManager.CreateAsync(new IdentityRole("user"));

            // Adds Roles to Role Claims.
            var adminRole = await roleManager.FindByNameAsync("administrator");

            var userRole = await roleManager.FindByNameAsync("user");

            await roleManager.AddClaimAsync(adminRole, new Claim(JwtClaimTypes.Role, "administrator"));

            await roleManager.AddClaimAsync(userRole, new Claim(JwtClaimTypes.Role, "user"));

            // Seeds an admin user.
            var user = new IdentityUser
            {
                AccessFailedCount  = 0,
                Email              = "*****@*****.**",
                EmailConfirmed     = false,
                LockoutEnabled     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                TwoFactorEnabled   = false,
                UserName           = "******"
            };
            // password admin
            var result = await userManager.CreateAsync(user, "password");

            if (result.Succeeded)
            {
                var adminUser = await userManager.FindByNameAsync(user.UserName);

                // Assigns the 'administrator' role.
                await userManager.AddToRoleAsync(adminUser, "administrator");

                // Assigns claims.
                var claims = new List <Claim> {
                    new Claim(type: JwtClaimTypes.Name, value: user.UserName),
                    new Claim(type: JwtClaimTypes.Email, value: user.Email),
                };
                await userManager.AddClaimsAsync(adminUser, claims);
            }
            user = new IdentityUser
            {
                AccessFailedCount  = 0,
                Email              = "*****@*****.**",
                EmailConfirmed     = false,
                LockoutEnabled     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                TwoFactorEnabled   = false,
                UserName           = "******"
            };
            // password admin
            result = await userManager.CreateAsync(user, "password");

            if (result.Succeeded)
            {
                user = await userManager.FindByNameAsync(user.UserName);

                // Assigns the 'administrator' role.
                await userManager.AddToRoleAsync(user, "user");

                // Assigns claims.
                var claims = new List <Claim> {
                    new Claim(type: JwtClaimTypes.Name, value: user.UserName),
                    new Claim(type: JwtClaimTypes.Email, value: user.Email),
                };
                await userManager.AddClaimsAsync(user, claims);
            }

            context.FoodItems.Add(new FoodItem()
            {
                Calories = 1000, Name = "Lasagne", Created = DateTime.Now
            });
            context.FoodItems.Add(new FoodItem()
            {
                Calories = 1100, Name = "Hamburger", Created = DateTime.Now
            });
            context.FoodItems.Add(new FoodItem()
            {
                Calories = 1200, Name = "Spaghetti", Created = DateTime.Now
            });
            context.FoodItems.Add(new FoodItem()
            {
                Calories = 1300, Name = "Pizza", Created = DateTime.Now
            });

            context.SaveChanges();

            var foodItem = context.FoodItems.FirstOrDefault();

            context.Add(new Ingredient()
            {
                FoodItem = foodItem, Quantity = 1, Weight = 2, Description = "meat ball"
            });
            context.Add(new Ingredient()
            {
                FoodItem = foodItem, Quantity = 2, Weight = 3, Description = "suage ball"
            });
            context.SaveChanges();


            var states = GetStates();

            context.States.AddRange(states);
            try
            {
                int numAffected = context.SaveChanges();
            }
            catch (Exception exp)
            {
                throw;
            }
            context.Customers.RemoveRange(context.Customers);
            context.SaveChanges();

            var customers = GetCustomers(states);

            context.Customers.AddRange(customers);

            try
            {
                int numAffected = context.SaveChanges();
            }
            catch (Exception exp)
            {
                throw;
            }
        }
예제 #5
0
 public void Create(Product product)
 {
     db.Add(product);
 }
예제 #6
0
 public void Create(Customer customer)
 {
     db.Add(customer);
 }
 public void Add(Restaurant newRestaurant)
 {
     _context.Add(newRestaurant);
     _context.SaveChanges();
 }
예제 #8
0
 public void Create(Order order)
 {
     db.Add(order);
 }
예제 #9
0
 public Restaurant Add(Restaurant newRestaurant)
 {
     _dbContext.Add(newRestaurant);
     //_dbContext.Restaurants.Add(newRestaurant);
     return(newRestaurant);
 }