Пример #1
0
        public void UpdateCustomer()
        {
            var _dbContext = new CustomersDBContext(new DbContextOptionsBuilder <CustomersDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            var customer = new Customer {
                FirstName = "John", LastName = "Doe", DateOfBirth = new DateTime(1976, 2, 11)
            };

            customer.ID = _dbContext.UpdateCustomer(customer);

            customer.FirstName = "Jim";

            customer.LastName = "Johnson";

            customer.DateOfBirth = new DateTime(1975, 1, 10);

            _dbContext.UpdateCustomer(customer);

            var customerinDb = _dbContext.GetCustomer(customer.ID);

            Assert.AreEqual(customerinDb.FirstName, customer.FirstName);

            Assert.AreEqual(customerinDb.LastName, customer.LastName);

            Assert.AreEqual(customerinDb.DateOfBirth, customer.DateOfBirth);
        }
Пример #2
0
        public CustomersProvider(CustomersDBContext dbContext, ILogger <CustomersProvider> logger, IMapper mapper)
        {
            this.dbContext = dbContext;
            this.logger    = logger;
            this.mapper    = mapper;

            SeedData();
        }
Пример #3
0
        public void SearchCustomerSuccess_3()
        {
            var _dbContext = new CustomersDBContext(new DbContextOptionsBuilder <CustomersDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            var customer = new Customer {
                FirstName = "John", LastName = "Doe", DateOfBirth = new DateTime(1976, 2, 11)
            };

            customer.ID = _dbContext.UpdateCustomer(customer);

            var customerExists = _dbContext.FindCustomer("Do") != null;

            Assert.AreEqual(customerExists, true);
        }
Пример #4
0
        public void DeleteCsutomer()
        {
            var _dbContext = new CustomersDBContext(new DbContextOptionsBuilder <CustomersDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            var customer = new Customer {
                FirstName = "John", LastName = "Doe", DateOfBirth = new DateTime(1976, 2, 11)
            };

            customer.ID = _dbContext.UpdateCustomer(customer);

            _dbContext.DeleteCustomer(customer.ID);

            var customerExists = _dbContext.GetCustomer(customer.ID) != null;

            Assert.AreEqual(customerExists, false);
        }
Пример #5
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CustomersDBContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CustomersDBContext> >()))
            {
                // Look for any customers already in database.
                if (context.Customers.Any())
                {
                    return;   // Database has been seeded
                }

                var customers = GetCustomerData();
                context.Customers.AddRange(customers);

                context.SaveChanges();
            }
        }
        //
        // GET: /Support/

        public ActionResult Index()
        {
            Itemadder          t = new Itemadder();
            CustomersDBContext c = new CustomersDBContext();

            t.pv         = new List <string>();
            t.ind        = new List <int>();
            t.name_admin = new List <string>();
            var tt = from a in c.customer where a.Admin == 1 select a;

            foreach (var item in tt)
            {
                t.pv.Add(item.E_mail);
                t.name_admin.Add(item.Cust_Nme);
                t.ind.Add(item.Phone);
            }



            return(View(t));
        }
Пример #7
0
 public CustomersController(CustomersDBContext context)
 {
     _context = context;
 }
Пример #8
0
        public ActionResult Create(Shop shop)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "yes")
            {
                return(RedirectToAction("Index", "Customers"));
            }

            if (ModelState.IsValid)
            {
                if (shop != null)
                {
                    Shop x = new Shop();

                    x.Delevery = shop.Delevery;
                    x.Phone    = shop.Phone;
                    x.About    = shop.About;
                    x.Location = "";
                    Cust_ShopDBContext csss = new Cust_ShopDBContext();
                    int id    = (int)Session["swi"];
                    int count = (from a in csss.cust_shop where a.Cust_Id == id select a).Count();
                    CustomersDBContext cst = new CustomersDBContext();
                    var qq2          = from b in cst.customer where id == b.Cust_Id select b;
                    int accountcount = 0;
                    foreach (var item in qq2)
                    {
                        accountcount = item.Account_count;
                    }
                    if (count < accountcount)
                    {
                        if (shop.About == null || shop.Delevery == null)
                        {
                            return(RedirectToAction("Index"));
                        }
                        db.shop.Add(x);
                        db.SaveChanges();

                        Cust_ShopDBContext cs  = new Cust_ShopDBContext();
                        Cust_Shop          cos = new Cust_Shop();
                        cos.Cust_Id = id;
                        cos.S_Id    = x.S_Id;
                        cs.cust_shop.Add(cos);
                        cs.SaveChanges();



                        return(RedirectToAction("mapv"));
                    }

                    TempData["counters"] = "Sorry You already have the limit shops ";
                    return(RedirectToAction("Index", "Customers"));
                }
                else
                {
                    Shop s = new Shop();

                    return(View(s));
                }
            }

            return(View(shop));
        }
Пример #9
0
 public CustomerService(CustomersDBContext context)
 {
     _context = context;
 }