public IActionResult getBook(int?id) { DonHang donHang = new DonHang(); var xe = _context.Xe.SingleOrDefault(x => x.Id == id); if (ModelState.IsValid) { donHang.MaXe = id; donHang.NgayLap = DateTime.Now; donHang.TuNgay = Seacrch.ngaynhan; donHang.DenNgay = Seacrch.ngaytra; donHang.MaUs = CommonConstants.UserID; donHang.Songay = Convert.ToInt32(Seacrch.daydiff); donHang.TongTien = Convert.ToInt32(Seacrch.daydiff * xe.Gia + 2500000); donHang.Status = false; donHang.Huy = false; _context.Add(donHang); _context.SaveChanges(); return(RedirectToAction(nameof(CustomerOder))); } return(NotFound()); }
public async Task <IActionResult> Create([Bind("Id,UserName,PassWord,HoTen,NgaySinh,NgayNhap,DiaChi,Gioitinh,Status,GroudId,Email,Phone,Xacthuc")] Users users) { if (ModelState.IsValid) { _context.Add(users); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(users)); }
public async Task <IActionResult> Index([Bind("Id,NgayGui,NguoiGui,NoiDung,Email")] HomThuLienHe homThuLienHe) { if (ModelState.IsValid) { homThuLienHe.NgayGui = DateTime.Now; _context.Add(homThuLienHe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homThuLienHe)); }
public async Task <IActionResult> Create([Bind("Id,UserName,PassWord,HoTen,NgaySinh,NgayNhap,DiaChi,Email")] Users users) { if (ModelState.IsValid) { users.PassWord = Encryptor.MD5Hash(users.PassWord); users.NgayNhap = DateTime.Now; _context.Add(users); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(users)); }
public async Task <IActionResult> Create([Bind("Id,Ma,Maxe,Tenxe,Gia,Manguoidang")] Cart cart) { if (ModelState.IsValid) { _context.Add(cart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Ma"] = new SelectList(_context.Users, "Id", "Id", cart.Ma); ViewData["Maxe"] = new SelectList(_context.Xe, "Id", "Id", cart.Maxe); return(View(cart)); }
public async Task <IActionResult> Create([Bind("Id,NgayNhap,MaNguoiDang,Tinh,Huyen,TenLoai,TenNguoiDang,Doi,Tenxe,TenHang,Hinh,Mota,Gia,LoaiXe,Status,Moban,MaHuyen,MaHangXe,MaTenXe,Diachi")] Xe xe) { if (ModelState.IsValid) { _context.Add(xe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MaHangXe"] = new SelectList(_context.HangXe, "Id", "Id", xe.MaHangXe); ViewData["MaHuyen"] = new SelectList(_context.Huyen, "Id", "Id", xe.MaHuyen); ViewData["MaNguoiDang"] = new SelectList(_context.Users, "Id", "Id", xe.MaNguoiDang); ViewData["MaTenXe"] = new SelectList(_context.TenXe, "Id", "Id", xe.MaTenXe); return(View(xe)); }
public async Task <IActionResult> Create([Bind("Id,UserName,PassWord,HoTen,NgaySinh,NgayNhap,DiaChi,Status,GroudId")] Admin admin) { if (ModelState.IsValid) { Admin ad = new Admin(); ad = admin; ad.NgayNhap = DateTime.Now; ad.PassWord = Encryptor.MD5Hash(admin.PassWord); ad.Status = true; ad.GroudId = 2; if (_context.Admin.Where(x => x.UserName == ad.UserName).SingleOrDefault() != default) { ViewData["TrungUser"] = "******"; return(View()); } _context.Add(ad); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(admin)); }
public async Task <IActionResult> Create(Xe xe, [FromForm(Name = "file")] IFormFile file) { //mã người đăng = UserID //ngày đăng = datetime //tên loaị = mahang + tên loại //tên người đưang = userid+tên người đăng //status =false //mở bán = true //tên hãng= mahang+tên hãng //loại xe = tên loại //đời xe, năm sản xuất Xe sa = new Xe(); if (ModelState.IsValid) { if (sa == null) { return(Content("not found")); } else { int a = Convert.ToInt32(xe.MaHangXe); sa = xe; sa.NgayNhap = DateTime.Now; sa.MaNguoiDang = Models.UserDao.UserId; var s = _context.HangXe.Find(xe.MaHangXe); sa.TenNguoiDang = _context.Users.Find(UserDao.UserId).HoTen; sa.TenLoai = _context.HangXe.Include(x => x.MaLoaiXeNavigation).FirstOrDefault(x => x.Id == xe.MaHangXe).MaLoaiXeNavigation.TenLoai; sa.TenHang = s.TenHang; sa.Huyen = _context.Huyen.Find(xe.MaHuyen).TenHuyen; var t = _context.Huyen.Include(x => x.MaTinhNavigation).FirstOrDefault(x => x.Id == xe.MaHuyen); sa.Tinh = t.MaTinhNavigation.TenTinh; sa.LoaiXe = s.MaLoaiXeNavigation.TenLoai; sa.LoaiXe = sa.TenLoai; sa.Status = false; sa.Moban = true; if (file != null) { string path_Root = _env.WebRootPath; string path_to_Images = path_Root + "\\Images\\" + file.FileName; //</ get Path > if (System.IO.File.Exists(path_to_Images)) { for (int i = 1; i <= 5; i++) { path_to_Images = path_Root + "\\Images\\x" + i + "\\" + file.FileName; sa.Hinh = "\\Images\\" + file.FileName; if (!System.IO.File.Exists(path_to_Images)) { break; } if (i == 5) { return(Content("something is wrong!!")); } } } else { //< Copy File to Target > sa.Hinh = "\\Images\\" + file.FileName; } using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await file.CopyToAsync(stream); } //</ Copy File to Target > } _context.Add(sa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ViewData["MaNguoiDang"] = new SelectList(_context.Users, "Id", "Id", xe.MaNguoiDang); ViewData["MaTenXe"] = new SelectList(_context.TenXe, "Id", "Id", xe.MaHangXe); return(View(xe)); }