Ejemplo n.º 1
0
        public Product CreateProduct(Product product)
        {
            var add = _ctx.Products.Add(product).Entity;

            _ctx.SaveChanges();
            return(add);
        }
Ejemplo n.º 2
0
        public Customer CreateCustomer(Customer customer)
        {
            var customer2Add = _ctx.Customers.Add(customer).Entity;

            _ctx.SaveChanges();
            return(customer2Add);
        }
Ejemplo n.º 3
0
        //public ActionResult PlaceOderItems(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    OrderItem orderItem = db.OrderItems.Find(id);
        //    if (orderItem == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    if (orderItem.Amount < 1)
        //    {
        //        return RedirectToAction("Details", "Orders");
        //    }
        //    // orderItem need loop
        //    foreach (var item in OrderItem)
        //    {
        //        OrderItem orderItem = new OrderItem();//assign DateTime to orderItem table in db
        //        orderItem.Amount = item.Amount;
        //        orderItem.Price = item.Products.Price;
        //        orderItem.Products = item.Products;//we assign all properties from this product object
        //        order.OrderItems.Add(orderItem); //we assign every sub object 'orderItem' to main object 'order' added every order item to dabaBase  OrderItems table
        //    }

        //    return View();
        //}
        // GET: Orders/Create
        public ActionResult PlaceOrder()
        {
            //we need new object to use it to disply just user Cart, but not all users from dbase
            var userId = User.Identity.GetUserId();                                                                                                              // we have id of user by this code to assign his cart to display in recipt not for all users
            var user   = db.Users.Include("Cart").Include("Cart.CartItems").Include("Orders").Include("Orders.OrderItems").SingleOrDefault(u => u.Id == userId); // by this way we fitch the database table

            ViewBag.userName = "******" + user.FirstName + ",LastName : " + user.LastName;
            if (user.Cart.CartItems.Count < 1)
            {
                return(RedirectToAction("Details", "Carts"));
            }
            Order order = new Order();

            order.OrderDate = DateTime.Now;
            foreach (var item in user.Cart.CartItems)
            {
                OrderItem orderItem = new OrderItem();//assign DateTime to orderItem table in db
                orderItem.Amount   = item.Amount;
                orderItem.Price    = item.Products.Price;
                orderItem.Products = item.Products; //we assign all properties from this product object
                order.OrderItems.Add(orderItem);    //added every order item to dabaBase  OrderItems table
            }
            user.Orders.Add(order);                 //we add order list to 'user' object
            user.Cart.CartItems.Clear();            //reset CartItem list

            db.SaveChanges();

            return(View(order));
        }
Ejemplo n.º 4
0
 public ActionResult Create([Bind(Include = "Id,Name,Price,Description,AvailableStorage,Image")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Products.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> Index()
        {
            Cart cart = cService.ReadCart();

            if (cart.Items.Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (cart.Items.Count() == 1)
            {
                ViewBag.Message = "Product will be delivered to your home address";
            }
            else
            {
                ViewBag.Message = "Products will be delivered to your home address";
            }

            ApplicationUser user = await um.GetUserAsync(User);

            string        id = user.Id;
            PurchaseOrder p1 = new PurchaseOrder
            {
                PersonId    = id,
                DateOfOrder = DateTime.Now
            };

            try
            {
                db.PurchaseOrders.Add(p1);
                db.SaveChanges();

                int pId = p1.PurchaseOrderId;

                foreach (CartItem ci in cart.Items)
                {
                    Item it1 = new Item
                    {
                        PurchaseOrderId = pId,
                        ProductId       = ci.Product.ProductId,
                    };
                    db.Items.Add(it1);
                    db.SaveChanges();
                }

                cService.DeleteCart();

                return(View());
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Create(Categories categories)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(categories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(categories));
        }
        public ActionResult Create([Bind(Include = "Id,Amount")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                db.Carts.Add(cart);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cart));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "Id,Price,Amount")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                db.OrderItems.Add(orderItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(orderItem));
        }
Ejemplo n.º 9
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                product.ProductKey = Guid.NewGuid();
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 10
0
        public Order CreateOrder(Order order)
        {
            if (order.Customer != null)
            {
                _ctx.Attach(order.Customer);
            }

            _ctx.Attach(order.Product);
            var order2Add = _ctx.Orders.Add(order).Entity;

            _ctx.SaveChanges();
            return(order2Add);
        }
Ejemplo n.º 11
0
        private void CreateEditions()
        {
            Edition defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
Ejemplo n.º 12
0
        private Role GetStaticRole(string roleName)
        {
            Role role = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == roleName);

            if (role == null)
            {
                role = _context.Roles.Add(new Role(_tenantId, roleName, roleName)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            return(role);
        }
Ejemplo n.º 13
0
 private void CreateProductCategorySample(WebShopDbContext context)
 {
     if (context.ProductCategories.Count() == 0)
     {
         List <ProductCategory> listProductCategory = new List <ProductCategory>()
         {
             new ProductCategory()
             {
                 Name = "Pháo khói màu", Alias = "phao-khoi-mau", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 1
             },
             new ProductCategory()
             {
                 Name = "Pháo điện", Alias = "phao-dien", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 2
             },
             new ProductCategory()
             {
                 Name = "Các loại pháo khác", Alias = "cac-loai-phao-khac", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 3
             },
             new ProductCategory()
             {
                 Name = "Thiết bị sân khấu", Alias = "thiet-bi-san-khau", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 4
             },
         };
         context.ProductCategories.AddRange(listProductCategory);
         context.SaveChanges();
     }
 }
Ejemplo n.º 14
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Ejemplo n.º 15
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Ejemplo n.º 16
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
Ejemplo n.º 17
0
 protected void UsingDbContext(int?tenantId, Action <WebShopDbContext> action)
 {
     using (UsingTenantId(tenantId))
     {
         using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
         {
             action(context);
             context.SaveChanges();
         }
     }
 }
Ejemplo n.º 18
0
        protected T UsingDbContext <T>(int?tenantId, Func <WebShopDbContext, T> func)
        {
            T result;

            using (UsingTenantId(tenantId))
            {
                using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
                {
                    result = func(context);
                    context.SaveChanges();
                }
            }

            return(result);
        }
        [HttpPost]                                      //we need to add more check if then for null user
        public ActionResult Edit(IndexViewModel inUser) // we need to fitch info from user to save it in dataBase
        {
            //now we fitch part of info from user to save it but we do not know how is owner of it so we fitch id user to assing it to hem
            var userId = User.Identity.GetUserId();         // I fitch the Id but not from database It comes from Login by Identity FrameWroke
            var user   = db.Users.Find(userId);             //we use this Id to fitch user object from dbase  We do not use SingelOrdDefault because we do not need including nested tables or we do not have loop list

            //we have old info object from db and new info to replace it instead of old one
            user.FirstName   = inUser.FirstName;            //we transfer the changes info from IndexViewModel class by inUser to database by ApplicationUser class and
            user.LastName    = inUser.LastName;
            user.Age         = inUser.Age;
            user.PhoneNumber = inUser.Phone;

            db.SaveChanges();
            //we have to return not by Return view(); but by  ' return RedirectToAction("Index"); '
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 20
0
        private void CreateDefaultTenant()
        {
            // Default tenant

            Tenant defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                Abp.Application.Editions.Edition defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email, Name = Input.Name, LastName = Input.LastName, Address = Input.Address, City = Input.City, Country = Input.Country
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    Person p = new Person {
                        PersonId  = user.Id,
                        FirstName = user.Name,
                        LastName  = user.LastName,
                        Address   = user.Address,
                        City      = user.City,
                        Country   = user.Country
                    };

                    db.Persons.Add(p);
                    db.SaveChanges();


                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Ejemplo n.º 22
0
        public void CreateItem(CreateItemDTO item)
        {
            switch (EnumExtensionMethods.GetValueFromDescription <Category>(item.Category))
            {
            case Category.Cpu:
            {
                var cpu = new Cpu()
                {
                    Name             = item.Name,
                    Category         = Category.Cpu,
                    Available        = 20,
                    PicturePath      = item.PicturePath,
                    OriginalPrice    = item.OriginalPrice,
                    DiscountedPrice  = item.DiscountedPrice,
                    Manufacturer     = item.Manufacturer,
                    ShortDescription = item.ShortDescription,
                    Description      = item.Description,
                    Warranty         = item.Warranty,
                    GamingFlag       = item.GamingFlag,
                    IsUsed           = item.IsUsed,
                    HasRGB           = item.HasRGB,
                    DateSinceInStore = DateTime.Now,

                    BaseClock       = item.BaseClock.Value,
                    TDP             = item.TDP.Value,
                    ProcessorFamily = item.ProcessorFamily,
                    Technology      = item.Technology == null ? 0 : item.Technology.Value,
                    CoreNumber      = item.CoreNumber == null ? 0 : item.CoreNumber.Value,
                    ThreadNumber    = item.ThreadNumber == null ? 0 : item.ThreadNumber.Value,
                    Socket          = item.Socket
                };

                this.context.Items.Add(cpu);
                break;
            }

            case Category.Case:
            {
                var pcCase = new Case()
                {
                    Name             = item.Name,
                    Category         = Category.Cpu,
                    Available        = 20,
                    PicturePath      = item.PicturePath,
                    OriginalPrice    = item.OriginalPrice,
                    DiscountedPrice  = item.DiscountedPrice,
                    Manufacturer     = item.Manufacturer,
                    ShortDescription = item.ShortDescription,
                    Description      = item.Description,
                    Warranty         = item.Warranty,
                    GamingFlag       = item.GamingFlag,
                    IsUsed           = item.IsUsed,
                    HasRGB           = item.HasRGB,
                    DateSinceInStore = DateTime.Now,

                    BuiltInFanNumber     = item.BuiltInFanNumber == null ? 0 : item.BuiltInFanNumber.Value,
                    SupportedMotherboard = item.SupportedMotherboard,
                    Height    = item.Height == null ? 0 : item.Height.Value,
                    Width     = item.Width == null ? 0 : item.Width.Value,
                    Depth     = item.Depth == null ? 0 : item.Depth.Value,
                    HDDNumber = item.HDDNumber == null ? 0 : item.HDDNumber.Value,
                };

                this.context.Items.Add(pcCase);
                break;
            }
                //TODO: case for all types
            }
            context.SaveChanges();
        }
Ejemplo n.º 23
0
 public void SubmitChanges()
 {
     _webShopDbContext.SaveChanges();
 }
Ejemplo n.º 24
0
 public TEntity Create(TEntity item)
 {
     _dbSet.Add(item);
     _context.SaveChanges();
     return(Get(item.Id));
 }
Ejemplo n.º 25
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }