public async Task <IActionResult> PutTinh(int id, Tinh tinh) { if (id != tinh.Ma) { return(BadRequest()); } _context.Entry(tinh).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TinhExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> update([FromBody] Users users) { try { var us = _context.Users.Find(users.Id); us.HoTen = users.HoTen; us.Email = users.Email; us.Phone = users.Phone; _context.Update(us); await _context.SaveChangesAsync(); return(Ok(users)); } catch (DbUpdateConcurrencyException) { if (!UsersExists(users.Id)) { return(NotFound()); } else { throw; } } }
public async Task <ActionResult <Images> > PostImages(Images images) { _context.Images.Add(images); await _context.SaveChangesAsync(); return(CreatedAtAction("GetImages", new { id = images.Id }, images)); }
public async Task <IActionResult> PutDonHang(int id, DonHang donHang) { if (id != donHang.Id) { return(BadRequest()); } _context.Entry(donHang).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DonHangExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,MaXe,MaUs,MaLoaiThanhToan,NgayLap,TuNgay,DenNgay,TinhTrangThanhToan,Status,Songay,TongTien,Giamgia")] DonHang donHang) { if (id != donHang.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(donHang); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DonHangExists(donHang.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaLoaiThanhToan"] = new SelectList(_context.HinhThucThanhToan, "Id", "Id", donHang.MaLoaiThanhToan); ViewData["MaUs"] = new SelectList(_context.Users, "Id", "Id", donHang.MaUs); ViewData["MaXe"] = new SelectList(_context.Xe, "Id", "Id", donHang.MaXe); return(View(donHang)); }
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> 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 <ActionResult <DonHang> > GetDonHang(int id) { var donHang = await _context.DonHang.Where(x => x.MaUs == id && x.Readed == true).ToListAsync(); if (donHang.Count == 0) { return(NotFound()); } foreach (var item in donHang) { _context.DonHang.Remove(item); await _context.SaveChangesAsync(); } return(Ok(donHang)); }
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> Edit(int id, [Bind("Id,UserName,PassWord,HoTen,NgaySinh,NgayNhap,DiaChi,Gioitinh,Status,Email,Phone")] Users users) { var u = await _context.Users.FindAsync(id); u.NgaySinh = users.NgaySinh; u.Email = users.Email; u.Phone = users.Phone; if (id != users.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(u); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(users.Id)) { return(NotFound()); } else { throw; } } string url = "/User/Profile/Details?id=" + id; return(Redirect(url)); } return(View(users)); }
// GET: Carts/Delete/5 public async Task <IActionResult> Delete(int?id) { var cart = await _context.Cart.FindAsync(id); _context.Cart.Remove(cart); await _context.SaveChangesAsync(); string referer1 = "~/Carts?id=" + CommonConstants.UserID; return(Redirect(referer1)); }
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,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([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 <ActionResult <Xe> > Readedrequest(int id) { var xe = await _context.DonHang.FindAsync(id); if (xe == null) { return(NotFound()); } xe.Readed = true; _context.DonHang.Update(xe); await _context.SaveChangesAsync(); return(Ok(xe)); }
public async Task <ActionResult <Xe> > PostImages(int id) { var xe = _context.Xe.Find(id); if (xe == null) { return(NotFound()); } xe.Moban = !xe.Moban; _context.Entry(xe).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch { return(NotFound()); } return(Ok(xe)); }
public async Task <IActionResult> update([FromBody] Tinh tinh) { try { _context.Entry(tinh).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(tinh)); } catch (DbUpdateConcurrencyException) { if (!TinhExists(tinh.Ma)) { return(NotFound()); } else { throw; } } }
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)); }
public async Task <IActionResult> PutXe(Xe xe) { var x = _context.Xe.Find(xe.Id); Xe ren = new Xe(); if (xe.MaHuyen != null) { x.MaHuyen = xe.MaHuyen; var huyen = _context.Huyen.Include(a => a.MaTinhNavigation).Where(a => a.Id == xe.MaHuyen).SingleOrDefault(); if (huyen == null) { return(NotFound()); } x.Huyen = huyen.TenHuyen; x.Tinh = huyen.MaTinhNavigation.TenTinh; } else if (xe.MaHangXe != null) { var Hangxe = _context.HangXe.Find(xe.MaHangXe); if (Hangxe == null) { return(NotFound()); } if (!string.IsNullOrEmpty(xe.Tenxe)) { x.Tenxe = xe.Tenxe; } x.MaHangXe = xe.MaHangXe; x.TenHang = Hangxe.TenHang; } else { x.BienSo = xe.BienSo; x.SoKM = xe.SoKM; x.Gia = xe.Gia; } _context.Entry(x).State = EntityState.Modified; try { await _context.SaveChangesAsync(); ren = _context.Xe.Find(xe.Id); ren.MaHuyenNavigation = null; ren.MaHangXeNavigation = null; } catch (DbUpdateConcurrencyException) { if (!XeExists(xe.Id)) { return(NotFound()); } else { throw; } } return(Ok(ren)); }
public async Task <IActionResult> PutImages(int id, [FromForm(Name = "file")] IFormFile file, string loai) { if (file == null) { return(NotFound()); } var ima = _context.Images.Find(id); string src; var image = new Images(); DateTime s = DateTime.Now; string date = s.ToString(); var charsToRemove = new string[] { "@", ",", ".", ";", "'", "-", ":", " " }; foreach (var c in charsToRemove) { date = date.Replace(c, string.Empty); } if (file != null) { string path_Root = _env.WebRootPath; if (path_Root == null) { return(NotFound()); } string path_to_Images = path_Root + "\\Images\\" + date + file.FileName; //< Copy File to Target > src = "\\Images\\" + date + file.FileName; using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await file.CopyToAsync(stream); } if (id == 0) { string idcar = file.FileName; var charsToRemove2 = new string[] { " ", ".", "p", "n", "g" }; foreach (var c in charsToRemove2) { idcar = idcar.Replace(c, string.Empty); } var xe = _context.Xe.Find(Convert.ToInt32(idcar)); if (xe == null) { return(NotFound()); } else { xe.Hinh = src; _context.Entry(xe).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(Ok(xe)); } catch { } } } else { image.XeId = ima.XeId; ima.Src = src; _context.Entry(ima).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch { } } //</ Copy File to Target > } return(Ok(image)); }