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"
            }));
        }
 public IActionResult Usuario(Usuario u)
 {
     if (ModelState.IsValid)
     {
         _context.Add(u);
         _context.SaveChanges();
         return(RedirectToAction("Listar"));
     }
     return(View());
 }
 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));
        }
        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
        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
        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
        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);
 }
        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();
 }