コード例 #1
0
        public IActionResult DeleteConfirmed(int id)
        {
            var order = _context.Orders.Find(id);

            _context.Orders.Remove(order);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public IActionResult Create([Bind("Id,Name,Lat,Lng")] Store store)
        {
            if (ModelState.IsValid)
            {
                _context.Stores.Add(store);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Manage)));
            }

            return(View(store));
        }
コード例 #3
0
        public void Add(ProductAddViewModel model)
        {
            var product = new Product()
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Category    = _context.Categories.Single(x => x.Id == model.CategoryId)
            };

            _context.Products.Add(product);
            _context.SaveChanges();
        }
コード例 #4
0
        public void Save(AddCustomerViewModel model)
        {
            var customer = new Customer
            {
                Name     = model.Name,
                LastName = model.LastName,
                Email    = model.Email,
                Phone    = model.Phone,
                Sex      = model.Sex
            };

            _dbContext.Customers.Add(customer);
            _dbContext.SaveChanges();
        }
コード例 #5
0
ファイル: ProductRepository.cs プロジェクト: Wychu1/SportShop
        public void Add(ProductAddViewModel model)
        {
            var product = new Product
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Category    = model.CategoryId
            };

            _context.Products.Add(product);
            _context.SaveChanges();
        }
コード例 #6
0
        public IActionResult Create([Bind("OrderProducts, Sum")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.CustomerId   = (int)HttpContext.Session.GetInt32("User");
                order.CreationDate = DateTime.Now;
                _context.Orders.Add(order);
                _context.SaveChanges();

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

            return(View());
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,VideoUrl")]
                                                 Product product, bool isFacebookShare = false)
        {
            if (ModelState.IsValid)
            {
                // Generate random file locally
                var image = Request.Form.Files[0];
                if (image.Length > 0)
                {
                    var ImageExtension = image.FileName.Split('.')[1];
                    // generate unique name for each uploaded image so it won't collide with other users uploaded images
                    var ImageName = Guid.NewGuid().ToString() + '.' + ImageExtension;

                    product.ImageName = ImageName;
                    var imagePath = Path.Combine(this.Environment.ContentRootPath, "wwwroot\\images",
                                                 product.ImageName);

                    // Creates the images in ImagePath
                    using (var stream = System.IO.File.Create(imagePath))
                    {
                        await image.CopyToAsync(stream);
                    }
                }

                _context.Products.Add(product);
                _context.SaveChanges();

                if (isFacebookShare)
                {
                    PostProductOnFacebook(product);
                }

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

            return(View(product));
        }
コード例 #8
0
        public ActionResult Index([Bind("Id,FirstName,LastName,BirthDate,UserName,Password,Phone,Address,City,ZipCode")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                var userNameFound = context.Customers.Count(c => c.UserName == customer.UserName);
                if (userNameFound > 0)
                {
                    ModelState.AddModelError("UserNameExists", "User name like this already exists");
                }
                else
                {
                    customer.IsAdmin = false;
                    context.Customers.Add(customer);
                    context.SaveChanges();
                    return(RedirectToAction("Success"));
                }
            }

            return(View(customer));
        }