コード例 #1
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,ImageURL,Price,Type,Style,Country,City,Adress,Date,Time,Age,Accepted")] Product product)
        {
            if (User.IsInRole("admin"))
            {
                if (ModelState.IsValid)
                {
                    product.Accepted = "1";
                    _context.Add(product);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(product));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    product.Accepted = "0";
                    _context.Add(product);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(product));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,order_no,user_id,product_id,quantity")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cart));
        }
コード例 #3
0
        public IActionResult Save([FromBody] HangXe model)
        {
            try
            {
                if (model != null)
                {
                    if (ModelState.IsValid)
                    {
                        if (model.HangXeId == 0)
                        {
                            _context.Add(model);
                        }
                        else
                        {
                            _context.Update(model);
                        }
                        var result = _context.SaveChanges();

                        if (result > 0)
                        {
                            return(new JsonResult(new {
                                status = 1,
                                message = "Thanh Cong"
                            }));
                        }
                    }
                }
                return(new JsonResult(new
                {
                    status = -1,
                    message = "That Bai"
                }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new
                {
                    status = -1,
                    message = "Tao That Bai"
                }));
            }
            return(new JsonResult(new
            {
                status = -1,
                message = "Tao That Bai"
            }));
        }
コード例 #4
0
 public IActionResult Usuario(Usuario u)
 {
     if (ModelState.IsValid)
     {
         _context.Add(u);
         _context.SaveChanges();
         return(RedirectToAction("Listar"));
     }
     return(View());
 }
コード例 #5
0
 public IActionResult Producto(Producto p)
 {
     if (ModelState.IsValid)
     {
         _context.Add(p);
         _context.SaveChanges();
         return(RedirectToAction("Listar"));
     }
     return(View());
 }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,date_added,image_id,category,brand,model_name,description,price,screen_size,panel_type,operating_system,processor,graphic_card,ram,main_storage,extra_storage,webcam,hdmi,touchscreen,dvd_drive,staff_picked,recommended_purpose")] Laptop laptop)
        {
            if (ModelState.IsValid)
            {
                _context.Add(laptop);
                await _context.SaveChangesAsync();

                return(RedirectToAction("IndexAdmin", "Laptop"));
            }
            return(View(laptop));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] ApplicationUser applicationUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(applicationUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(applicationUser));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("XuatXuId,TenXuatXu")] XuatXu xuatXu)
        {
            if (ModelState.IsValid)
            {
                _context.Add(xuatXu);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(xuatXu));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("Id,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("DiaDiemTinhId,TenDiaDiemTinh")] DiaDiemTinh diaDiemTinh)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diaDiemTinh);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(diaDiemTinh));
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("TinhTrangId,TenTinhTrang")] TinhTrang tinhTrang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tinhTrang);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tinhTrang));
        }
コード例 #12
0
ファイル: Roles2Controller.cs プロジェクト: m0jovazky/Sphere
        public async Task <IActionResult> Create([Bind("Id,ConcurrencyStamp,Name,NormalizedName")] Roles2 roles2)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roles2);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(roles2));
        }
コード例 #13
0
        public async Task <IActionResult> Create([Bind("PhanKhoiId,TenPhanKhoi")] PhanKhoi phanKhoi)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phanKhoi);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(phanKhoi));
        }
コード例 #14
0
ファイル: HomeController.cs プロジェクト: kasi7777/Web1
        public async Task <IActionResult> Create([Bind("PeopleID,Name,DisplayName,Skill")] People people)
        {
            if (ModelState.IsValid)
            {
                _context.Add(people);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(people));
        }
コード例 #15
0
        public async Task <IActionResult> Create([Bind("DoiXeId,TenDoiXe")] DoiXe doiXe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(doiXe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(doiXe));
        }
コード例 #16
0
        public async Task <IActionResult> Create([Bind("Id,order_no,order_status,date_added,brand,model_name,description,quantity,price")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
コード例 #17
0
        public async Task <IActionResult> Create([Bind("Id,user_id,product_id,image_id,brand,model_name,description,price,supply,wishlist_no")] List list)
        {
            if (ModelState.IsValid)
            {
                _context.Add(list);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(list));
        }
コード例 #18
0
        public async Task <IActionResult> Create([Bind("KmDaDiId,TenKmDaDi")] KmDaDi kmDaDi)
        {
            if (ModelState.IsValid)
            {
                _context.Add(kmDaDi);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(kmDaDi));
        }
コード例 #19
0
        public async Task <IActionResult> Create([Bind("TheLoaiXeId,TenTheLoaiXe,LoaiXeId")] TheLoaiXe theLoaiXe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(theLoaiXe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiXeId"] = new SelectList(_context.LoaiXes, "LoaiXeId", "LoaiXeId", theLoaiXe.LoaiXeId);
            return(View(theLoaiXe));
        }
コード例 #20
0
ファイル: ProductController.cs プロジェクト: m0jovazky/Sphere
        public async Task <IActionResult> Create([Bind("Id,ImageId,ProductBrand,ProductName,ProductDesc,SubCategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubCategoryId"] = new SelectList(_context.Set <SubCategory>(), "Id", "Id", product.SubCategoryId);
            return(View(product));
        }
コード例 #21
0
        public async Task <IActionResult> Create([Bind("DiaDiemHuyenId,TenDiaDiemHuyen,DiaDiemTinhId")] DiaDiemHuyen diaDiemHuyen)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diaDiemHuyen);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DiaDiemTinhId"] = new SelectList(_context.DiaDiemTinhs, "DiaDiemTinhId", "DiaDiemTinhId", diaDiemHuyen.DiaDiemTinhId);
            return(View(diaDiemHuyen));
        }
コード例 #22
0
        public async Task <IActionResult> Create([Bind("Id,SubCategoryName,CategoryId")] SubCategory subCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", subCategory.CategoryId);
            return(View(subCategory));
        }
コード例 #23
0
        public async Task <IActionResult> Create([Bind("DoiXeDongXeId,DongXeId,DoiXeId")] DoiXeDongXe doiXeDongXe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(doiXeDongXe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoiXeId"]  = new SelectList(_context.DoiXes, "DoiXeId", "DoiXeId", doiXeDongXe.DoiXeId);
            ViewData["DongXeId"] = new SelectList(_context.DongXes, "DongXeId", "DongXeId", doiXeDongXe.DongXeId);
            return(View(doiXeDongXe));
        }
コード例 #24
0
        public async Task <IActionResult> Create([Bind("DongXeId,TenDongXe,HangXeId,PhanKhoiId,TheLoaiXeId")] DongXe dongXe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dongXe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HangXeId"]    = new SelectList(_context.HangXes, "HangXeId", "TenHangXe", dongXe.HangXeId);
            ViewData["PhanKhoiId"]  = new SelectList(_context.PhanKhois, "PhanKhoiId", "TenPhanKhoi", dongXe.PhanKhoiId);
            ViewData["TheLoaiXeId"] = new SelectList(_context.TheLoaiXes, "TheLoaiXeId", "TenTheLoaiXe", dongXe.TheLoaiXeId);
            return(View(dongXe));
        }
コード例 #25
0
        public Result Post(Cliente cliente)
        {
            try
            {
                using (_context = new WebContext())
                {
                    _context.Add(cliente);
                    _context.SaveChanges();
                }

                return(new Result(true, "Gravado com sucesso", cliente));
            }
            catch (Exception ex)
            {
                return(new Result(false, ex.Message, cliente));
            }
        }
コード例 #26
0
 public void Add <T>(T entity) where T : class
 {
     _context.Add(entity);
 }
コード例 #27
0
        public static void Initialize(WebContext context)
        {
            context.Database.EnsureCreated();

            if (context.Products.Any())
            {
                return;
            }

            var products = new Product[]
            {
                new Product {
                    Name = "Item1", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item2", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item3", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item4", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item5", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item6", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item7", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item8", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item9", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item10", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item11", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item12", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item13", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item14", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item15", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item16", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item17", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item18", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item19", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
                new Product {
                    Name = "Item20", Description = "Powerfull and effective product for you business. With help of this item you can achive everything you want. You'll be happy for sure.", ImageURL = "https://i.imgur.com/ydxzeqI.png", Price = 245.55m
                },
            };

            foreach (Product product in products)
            {
                context.Add(product);
            }
            context.SaveChanges();
        }
コード例 #28
0
 public void Add(T entity)
 {
     db.Add(entity);
     db.SaveChanges();
 }