private void SeedData()
 {
     if (!dbContext.Customers.Any())
     {
         dbContext.Add(new Db.Customer()
         {
             Id = 1, Name = "Bhavin Modi", Address = "Vadodara"
         });
         dbContext.Add(new Db.Customer()
         {
             Id = 2, Name = "Naksh Modi", Address = "Mumbai"
         });
         dbContext.Add(new Db.Customer()
         {
             Id = 3, Name = "Rajesh Modi", Address = "Pune"
         });
         dbContext.Add(new Db.Customer()
         {
             Id = 4, Name = "Akta Modi", Address = "Delhi"
         });
         dbContext.Add(new Db.Customer()
         {
             Id = 5, Name = "Purnima Modi", Address = "Udaipur"
         });
         dbContext.SaveChanges();
     }
 }
Пример #2
0
        public async Task <ActionResult <CustomersForInsertModel> > InputCustomerAsync(CustomersForInsertModel customer)
        {
            try
            {
                CustomersModel newCustomer = GetNewCustomer(customer);
                _context.Add(newCustomer);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("ID,Title,Author,Price,Rating")] Books books)
        {
            if (ModelState.IsValid)
            {
                _context.Add(books);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Mobile,Email,Address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("Id,Place,Address,Description,Open_Hours")] Attraction attraction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(attraction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(attraction));
        }
        public async Task <IActionResult> Create([Bind("Id,Number_of_Tickets,Ticket_Price,CustomerId,AttractionId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AttractionId"] = new SelectList(_context.Attraction, "Id", "Address", booking.AttractionId);
            ViewData["CustomerId"]   = new SelectList(_context.Customer, "Id", "Id", booking.CustomerId);
            return(View(booking));
        }
        public async Task <IActionResult> Create([Bind("ID,CustomerID,BooksID,OrderDate")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BooksID"]    = new SelectList(_context.Books, "ID", "ID", order.BooksID);
            ViewData["CustomerID"] = new SelectList(_context.Customer, "ID", "ID", order.CustomerID);
            return(View(order));
        }
        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);
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("Id,Type,IdentityNo,FirstName,LastName,City,Street,Number,Phone")] CustomerViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customer(viewModel.Type, viewModel.IdentityNo, viewModel.FirstName, viewModel.LastName, viewModel.City, viewModel.Street,
                                            viewModel.Number, viewModel.Phone);
                context.Add(customer);
                await this.context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }
Пример #10
0
 private void SeedData(CustomersDbContext dbContext)
 {
     if (!dbContext.Customers.Any())
     {
         for (int i = 100; i < 110; i++)
         {
             dbContext.Add(new Db.Customer()
             {
                 Id      = i,
                 Name    = $"John Dow{i}",
                 Address = $"Salt Lake, Street {i}, Hathway, US"
             });
         }
     }
 }