public async Task <ActionResult <XaPhuong> > PostXaPhuong(XaPhuong xaPhuong) { _context.xaPhuongs.Add(xaPhuong); await _context.SaveChangesAsync(); return(CreatedAtAction("GetXaPhuong", new { id = xaPhuong.MaXaPhuong }, xaPhuong)); }
public IHttpActionResult allDS(int page, int size) { try { List <DiaChiKhachHang> ldc = db.DiaChiKhachHangs.Where(e => e.trang_thai == true).ToList().ToPagedList(page, size).ToList(); if (ldc.Count == 0) { return(StatusCode(HttpStatusCode.NotFound)); } List <dynamic> list = new List <dynamic>(); for (int i = 0; i < ldc.Count; i++) { TinhThanh tinh = db.TinhThanhs.FirstOrDefault(x => x.ma_tinh == ldc[i].id_tinh); QuanHuyen quan = db.QuanHuyens.FirstOrDefault(x => x.ma_quan_huyen == ldc[i].id_quan); XaPhuong xa = db.XaPhuongs.FirstOrDefault(x => x.ma_xa_phuong == ldc[i].id_xa_phuong); string diaChi = "" + ldc[i].dia_chi + ", " + xa.ten + ", " + quan.ten_quan_huyen + ", " + tinh.ten; var tam = new { idDiaChi = ldc[i].id, tenKhachHang = ldc[i].ten_khach_hang, idKhachHang = ldc[i].id_khach_hang, soDT = ldc[i].so_dt, diaChi = diaChi, }; list.Add(tam); } return(Ok(list)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> PutXaPhuong(int id, XaPhuong xaPhuong) { if (id != xaPhuong.MaXaPhuong) { return(BadRequest()); } _context.Entry(xaPhuong).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!XaPhuongExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static XaPhuongDTO FromEntity(XaPhuong item) { return(new XaPhuongDTO() { Id = item.Id, TenXaPhuong = item.TenXaPhuong, QuanHuyen = item.QuanHuyen != null?QuanHuyenDTO.FromEntity(item.QuanHuyen) : null, }); }
public IHttpActionResult getHoaDon(int id) //id { try { HienThiDonHang ctDonHang = new HienThiDonHang(); string diaChi = ""; DonDatHang donHang = db.DonDatHangs.FirstOrDefault(x => x.id_don_hang == id); DiaChiKhachHang dc = db.DiaChiKhachHangs.FirstOrDefault(x => x.id == donHang.id_dia_chi); TinhThanh tinh = db.TinhThanhs.FirstOrDefault(x => x.ma_tinh == dc.id_tinh); QuanHuyen quan = db.QuanHuyens.FirstOrDefault(x => x.ma_quan_huyen == dc.id_quan); XaPhuong xa = db.XaPhuongs.FirstOrDefault(x => x.ma_xa_phuong == dc.id_xa_phuong); if (donHang == null) { return(StatusCode(HttpStatusCode.NoContent)); } ctDonHang.idDonDatHang = donHang.id_don_hang; ctDonHang.trangThai = db.TinhTrangDonHangs.FirstOrDefault(x => x.id_tinh_trang == donHang.id_tinh_trang).tinh_trang_don_hang; ctDonHang.ngayLap = donHang.ngay_lap.ToShortDateString(); ctDonHang.tenNguoiNhan = db.KhachHangs.FirstOrDefault(x => x.id_khach_hang == donHang.id_khach_hang).ten_nguoi_dung; ctDonHang.soDT = "0" + donHang.so_dt_nguoi_nhan; diaChi = "" + dc.dia_chi + ", " + xa.ten + ", " + quan.ten_quan_huyen + ", " + tinh.ten; ctDonHang.diaChi = diaChi; // add danh sach san pham List <ChiTietDonHang> list = db.ChiTietDonHangs.Where(x => x.id_don_hang == id).ToList(); List <DSSanPham> lDanhSanPham = new List <DSSanPham>(); for (int i = 0; i < list.Count; i++) { DSSanPham dsp = new DSSanPham(); dsp.soLuong = list[i].so_luong; dsp.tongGia = (float)list[i].tong_tien; dsp.giaKM = (float)list[i].gia_km; //gan san pham SanPham tam = db.SanPhams.FirstOrDefault(x => x.id_san_pham == list[i].id_san_pham); SanPham sp = new SanPham(); sp.id_san_pham = tam.id_san_pham; sp.id_danh_muc = tam.id_danh_muc; sp.mo_ta = tam.mo_ta; sp.phan_tram_km = tam.phan_tram_km; sp.ten_sp = tam.ten_sp; sp.url_hinh_chinh = "http://www.3anhem.somee.com" + tam.url_hinh_chinh; sp.gia_sp = tam.gia_sp; sp.gia_km = tam.gia_km; dsp.sanPham = sp; lDanhSanPham.Add(dsp); } ctDonHang.danhSachHang = lDanhSanPham; return(Ok(ctDonHang)); }catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult getListHoaDon([FromBody] PhanTrang phanTrang) { try { // List <DonDatHang> list = db.DonDatHangs.Where(x => x.id_khach_hang == phanTrang.id).ToPagedList(phanTrang.trang, phanTrang.size).ToList(); List <HTListHoaDon> lhd = new List <HTListHoaDon>(); if (list == null) { return(StatusCode(HttpStatusCode.NoContent)); } for (int i = 0; i < list.Count; i++) { HTListHoaDon hoaDonTam = new HTListHoaDon(); // tao dia chi noi nhan hang DiaChiKhachHang dc = db.DiaChiKhachHangs.FirstOrDefault(e => e.id == list[i].id_dia_chi); TinhThanh tinh = db.TinhThanhs.FirstOrDefault(x => x.ma_tinh == dc.id_tinh); QuanHuyen quan = db.QuanHuyens.FirstOrDefault(x => x.ma_quan_huyen == dc.id_quan); XaPhuong xa = db.XaPhuongs.FirstOrDefault(x => x.ma_xa_phuong == dc.id_xa_phuong); string diaChi = "" + dc.dia_chi + ", " + xa.ten + ", " + quan.ten_quan_huyen + ", " + tinh.ten; hoaDonTam.id = list[i].id_don_hang; hoaDonTam.KhachHang = db.KhachHangs.FirstOrDefault(e => e.id_khach_hang == list[i].id_khach_hang).ten_nguoi_dung; hoaDonTam.TinhTrang = db.TinhTrangDonHangs.FirstOrDefault(e => e.id_tinh_trang == list[i].id_tinh_trang).tinh_trang_don_hang; hoaDonTam.ngayLap = list[i].ngay_lap.ToShortDateString(); hoaDonTam.DiaChi = diaChi; hoaDonTam.soDT = list[i].so_dt_nguoi_nhan; hoaDonTam.tongGia = (float)list[i].tong_tien; hoaDonTam.ghiChu = list[i].ghi_chu; lhd.Add(hoaDonTam); } return(Ok(lhd)); }catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult danhSach(int id) { try { List <DiaChiKhachHang> list = db.DiaChiKhachHangs.Where(e => e.id_khach_hang == id && e.trang_thai == true).ToList().Select(e => { e.DonDatHangs = null; return(e); }).ToList(); List <dynamic> ldt = new List <dynamic>(); if (list.Count == 0) { return(StatusCode(HttpStatusCode.NoContent)); } for (int i = 0; i < list.Count; i++) { List <QuanHuyen> listQuanHuyen = db.QuanHuyens.Where(e => e.ma_tinh == list[i].id_tinh).ToList(); List <dynamic> listQuan = new List <dynamic>(); for (int j = 0; j < listQuanHuyen.Count; j++) { var a = new { ma_quan_huyen = listQuanHuyen[i].ma_quan_huyen, ten_quan_huyen = listQuanHuyen[i].ten_quan_huyen, loai = listQuanHuyen[i].loai, ma_tinh = listQuanHuyen[i].ma_tinh, }; listQuan.Add(a); } List <XaPhuong> listXaPhuong = db.XaPhuongs.Where(e => e.ma_quan_huyen == list[i].id_quan).ToList(); List <dynamic> lx = new List <dynamic>(); for (int k = 0; k < listXaPhuong.Count; k++) { var b = new { ma_quan_huyen = listXaPhuong[k].ma_quan_huyen, ten = listXaPhuong[i].ten, loai = listXaPhuong[i].loai, ma_xa_phuong = listXaPhuong[i].ma_xa_phuong, }; lx.Add(b); } TinhThanh tinh = db.TinhThanhs.FirstOrDefault(x => x.ma_tinh == list[i].id_tinh); QuanHuyen quan = db.QuanHuyens.FirstOrDefault(x => x.ma_quan_huyen == list[i].id_quan); XaPhuong xa = db.XaPhuongs.FirstOrDefault(x => x.ma_xa_phuong == list[i].id_xa_phuong); string diaChi = list[i].dia_chi + ", " + xa.ten + ", " + quan.ten_quan_huyen + ", " + tinh.ten; var tam = new { idXaPhuong = list[i].id_xa_phuong, tenXaPhuong = xa.ten, diaChi = list[i].dia_chi, id = list[i].id, idKhachHang = list[i].id_khach_hang, tenKhachHang = list[i].ten_khach_hang, soDT = list[i].so_dt, idQuanHuyen = list[i].id_quan, tenQuanHuyen = quan.ten_quan_huyen, idTinh = list[i].id_tinh, tenTinh = tinh.ten, diaChiCuThe = list[i].dia_chi + ", " + xa.ten + ", " + quan.ten_quan_huyen + ", " + tinh.ten, dsQuanHuyen = listQuan, dsXaPhuong = lx }; ldt.Add(tam); } return(Ok(ldt)); }catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task UpdateXaPhuong(XaPhuong xaPhuong) { await _xaPhuongRepository.UpdateAsync(xaPhuong); }
public async Task CreateXaPhuong(XaPhuong xaPhuong) { await _xaPhuongRepository.AddAsync(xaPhuong); }