Пример #1
0
        public ActionResult Create([Bind(Include = "ID,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public void Insert(ProductColor item)
        {
            ProductColor newItem = new ProductColor()
            {
                Name      = item.Name,
                IsDeleted = false
            };

            _context.ProductColor.Add(newItem);
            _context.SaveChanges();
        }
Пример #3
0
        public void Insert(ProductType item)
        {
            ProductType newItem = new ProductType()
            {
                Name      = item.Name,
                IsDeleted = false
            };

            _context.ProductType.Add(newItem);
            _context.SaveChanges();
        }
        public void Insert(ProductStatus item)
        {
            ProductStatus newItem = new ProductStatus()
            {
                Name      = item.Name,
                IsDeleted = false
            };

            _context.ProductStatus.Add(newItem);
            _context.SaveChanges();
        }
Пример #5
0
        public void Insert(Gender item)
        {
            Gender newItem = new Gender()
            {
                Name      = item.Name,
                IsDeleted = false
            };

            _context.Gender.Add(newItem);
            _context.SaveChanges();
        }
Пример #6
0
        public void Insert(ProductMetal item)
        {
            ProductMetal newItem = new ProductMetal()
            {
                Name      = item.Name,
                IsDeleted = false
            };

            _context.ProductMetal.Add(newItem);
            _context.SaveChanges();
        }
Пример #7
0
        public void Insert(ProductImage item)
        {
            ProductImage newImage = new ProductImage()
            {
                Name      = item.Name,
                Path      = item.Path,
                Product   = item.Product,
                IsDeleted = false
            };

            _context.ProductImage.Add(newImage);
            _context.SaveChanges();
        }
Пример #8
0
        public void Insert(Employee item)
        {
            Employee newEmployee = new Employee()
            {
                Name       = string.Concat(item.FirstName, " ", " ", item.SecondName),
                FirstName  = item.FirstName,
                SecondName = item.SecondName,
                Patronymic = item.Patronymic,
                User       = item.User,
                IsDeleted  = false
            };

            _context.Employee.Add(newEmployee);
            _context.SaveChanges();
        }
Пример #9
0
        public string RegisterUser(RegisterModel model)
        {
            try
            {
                using (context = new WebStoreDbContext())
                {
                    Person user = context.People.Where(x => x.Email == model.Email).FirstOrDefault();
                    if (user == null)
                    {
                        Person person = new Person()
                        {
                            Email     = model.Email,
                            Password  = model.Password, // PasswordHash
                            FirstName = model.FirstName,
                            LastName  = model.LastName,
                            CreatedAt = DateTime.Now,
                            IsDeleted = false
                        };

                        context.People.Add(person);
                        context.SaveChanges();

                        return("");
                    }
                }
                return("Not added");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Пример #10
0
        public ActionResult Create([Bind(Include = "ID,ProductName,ShortDescription,FullDescription,UnitPrice,CategoryID")] Product product, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                // is image passed?
                if (image != null)
                {
                    uploadAzureBlobStorage(product, image);
                }

                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Пример #11
0
        public void Insert(Product item)
        {
            Product newProduct = new Product()
            {
                Name               = item.Name,
                Amount             = item.Amount,
                AvailabilityStatus = item.AvailabilityStatus,
                Gender             = item.Gender,
                Price              = item.Price,
                ProductColor       = item.ProductColor,
                ProductMetal       = item.ProductMetal,
                ProductStatus      = item.ProductStatus,
                ProductType        = item.ProductType,
                Weight             = item.Weight,
                IsDeleted          = false
            };

            _context.Product.Add(newProduct);
            _context.SaveChanges();
        }
Пример #12
0
        private void InitialSlides(WebStoreDbContext context)
        {
            if (context.Slides.Count() == 0)
            {
                List <Slide> slides = new List <Slide>()
                {
                    new Slide()
                    {
                        Name         = "<span>E</span>-SHOPPER",
                        Description  = "Free E-Commerce Template",
                        Image        = "/Assets/client/images/home/girl1.jpg",
                        Url          = "#",
                        DisplayOrder = 1,
                        Status       = true,
                        Content      = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
                    },
                    new Slide()
                    {
                        Name         = "<span>E</span>-SHOPPER",
                        Description  = "100% Responsive Design",
                        Image        = "/Assets/client/images/home/girl2.jpg",
                        Url          = "#",
                        DisplayOrder = 2,
                        Status       = true,
                        Content      = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
                    },
                    new Slide()
                    {
                        Name         = "<span>E</span>-SHOPPER",
                        Description  = "Free Ecommerce Template",
                        Image        = "/Assets/client/images/home/girl3.jpg",
                        Url          = "#",
                        DisplayOrder = 3,
                        Status       = true,
                        Content      = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
                    }
                };

                context.Slides.AddRange(slides);
                context.SaveChanges();
            }
        }
Пример #13
0
        public string Login(LoginModel loginModel)
        {
            if (this.IsValidUser(loginModel))
            {
                var token = this.GenerateUserToken(new RequestTokenModel()
                {
                    Email = loginModel.Email, Roles = MapperConfigurator.Mapper.Map <List <RoleModel> >(User.UserRoles.Select(x => x.Role).ToList())
                });
                if (token.Length > 0)
                {
                    dbContext.UserTokens.Add(new UserToken()
                    {
                        Token = token, User = User
                    });
                    dbContext.SaveChanges();

                    return(token);
                }
            }

            return("");
        }
Пример #14
0
 private void InitialProductCategory(WebStoreDbContext context)
 {
     if (context.ProductCategories.Count() == 0)
     {
         List <ProductCategory> list = new List <ProductCategory>()
         {
             new ProductCategory()
             {
                 Name = "Điện lạnh", Alias = "dien-lanh", Status = true
             },
             new ProductCategory()
             {
                 Name = "Viễn thông", Alias = "vien-thong", Status = true
             },
             new ProductCategory()
             {
                 Name = "Đồ gia dụng", Alias = "do-gia-dung", Status = true
             },
         };
         context.ProductCategories.AddRange(list);
         context.SaveChanges();
     }
 }
Пример #15
0
        public static void Initialize(WebStoreDbContext context)
        {
            context.Database.EnsureCreated();
            if (!context.Product.Any())
            {
                var deps = new Product[]
                {
                    new Product()
                    {
                        Name = "Product 01"
                    },
                    new Product()
                    {
                        Name = "Product 02"
                    }
                };
                foreach (var item in deps)
                {
                    context.Product.Add(item);
                }
                context.SaveChanges();
            }

            if (!context.ProductStatus.Any())
            {
                var companies = new ProductStatus[]
                {
                    new ProductStatus()
                    {
                        Name = "New"
                    }
                };
                foreach (var item in companies)
                {
                    context.ProductStatus.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.ProductAvailabilityStatus.Any())
            {
                var companies = new ProductAvailabilityStatus[]
                {
                    new ProductAvailabilityStatus()
                    {
                        Name = "Available"
                    },
                    new ProductAvailabilityStatus()
                    {
                        Name = "Not Available"
                    }
                };
                foreach (var item in companies)
                {
                    context.ProductAvailabilityStatus.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.ProductColor.Any())
            {
                var companies = new ProductColor[]
                {
                    new ProductColor()
                    {
                        Name = "White"
                    },
                    new ProductColor()
                    {
                        Name = "Black"
                    }
                };
                foreach (var item in companies)
                {
                    context.ProductColor.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.ProductMetal.Any())
            {
                var companies = new ProductMetal[]
                {
                    new ProductMetal()
                    {
                        Name = "Gold"
                    },
                    new ProductMetal()
                    {
                        Name = "Silver"
                    }
                };
                foreach (var item in companies)
                {
                    context.ProductMetal.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.ProductType.Any())
            {
                var types = new ProductType[]
                {
                    new ProductType()
                    {
                        Name = "Ring"
                    },
                    new ProductType()
                    {
                        Name = "Earring"
                    }
                };
                foreach (var item in types)
                {
                    context.ProductType.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.Gender.Any())
            {
                var items = new Gender[]
                {
                    new Gender()
                    {
                        Name = "Чоловіча"
                    },
                    new Gender()
                    {
                        Name = "Жіноча"
                    }
                };
                foreach (var item in items)
                {
                    context.Gender.Add(item);
                }
                context.SaveChanges();
            }
        }
Пример #16
0
 public void SaveChanges()
 {
     _dbContext.SaveChanges();
 }