public IHttpActionResult GetPhieuXuatById(int id) { PhieuXuatViewModel phieuxuat = null; using (var ctx = new BANHANGONLINEEntities5()) { phieuxuat = ctx.PHIEUXUATs.Where(s => s.MAPX == id) .Select(s => new PhieuXuatViewModel() { MAPX = s.MAPX, MAKH = s.MAKH, MASP = s.MASP, MANV = s.MANV, MADH = s.MADH, SLX = s.SLX, THANHTIEN = s.THANHTIEN, NGAYXUAT = s.NGAYXUAT }).FirstOrDefault <PhieuXuatViewModel>(); } if (phieuxuat == null) { return(NotFound()); } return(Ok(phieuxuat)); }
public ActionResult ThemPhieuXuat(PhieuXuatViewModel pxViewModel, string TenDaiLy) { if (ModelState.IsValid) { var daiLy = daiLyService.GetSingleByName(TenDaiLy); if (daiLy == null) { ModelState.AddModelError("", "Thông tin đại lý không tồn tại."); } else { pxViewModel.IdDaiLy = daiLy.Id; var soTienNo = congNoDLService.GetSingleByIdAndDate(daiLy.Id, pxViewModel.ThoiGianXuat).TongTienConNo; if (soTienNo > CommonConstant.NO_CHO_PHEP) { ModelState.AddModelError("", "Đã vượt quá số tiền cho phép nợ, không thể lập phiếu nữa."); } else { pxViewModel.DaiLy = Mapper.Map <DaiLy, DaiLyViewModel>(daiLy); pxViewModel.TongTien = 0; pxViewModel.TongSoLuong = 0; Session["PhieuXuat"] = pxViewModel; // Open current session to save the Export data info Session["dsCtPhieuXuat"] = new List <CtPhieuXuatViewModel>(); return(Redirect("them-chi-tiet/")); } } } return(View(pxViewModel)); }
public ActionResult ThemChiTietPhieuXuat(PhieuXuatViewModel pxViewModel, string TenSach) { if (ModelState.IsValid) { var sach = sachService.GetSingleByName(TenSach); if (sach == null) { ModelState.AddModelError("", "Thông tin sách không tồn tại."); } else { pxViewModel.ctPhieuXuat.IdSach = sach.Id; var giaBan = sach.GiaBan; var newCtPhieuXuatVm = new CtPhieuXuatViewModel(); newCtPhieuXuatVm = pxViewModel.ctPhieuXuat; newCtPhieuXuatVm.DonGiaXuat = (double)giaBan; newCtPhieuXuatVm.ThanhTien = newCtPhieuXuatVm.SoLuongXuat * newCtPhieuXuatVm.DonGiaXuat; newCtPhieuXuatVm.Sach = Mapper.Map <Sach, SachViewModel>(sach); var sachDaNhap = ((List <CtPhieuXuatViewModel>)Session["dsCtPhieuXuat"]).Find(x => x.IdSach == newCtPhieuXuatVm.IdSach); if (sachDaNhap == null) { var tonKho = tonKhoService.GetSingleByIdAndDate(sach.Id, pxViewModel.ThoiGianXuat); var soLuongTon = tonKho != null ? tonKho.SoLuong : 0; if (soLuongTon < newCtPhieuXuatVm.SoLuongXuat) { ModelState.AddModelError("", "Số lượng tồn là " + soLuongTon + " không đủ đáp ứng yêu cầu."); } else { if (!tonKhoService.CheckCreatePermission(sach.Id, newCtPhieuXuatVm.SoLuongXuat)) { ModelState.AddModelError("", "Thời gian xuất không cho phép tạo phiếu xuất này."); } else { // Con phai kiem tra co cho them cac phieu truoc do pxViewModel.ctPhieuXuat = null; ((PhieuXuatViewModel)Session["PhieuXuat"]).TongTien += newCtPhieuXuatVm.ThanhTien; ((PhieuXuatViewModel)Session["PhieuXuat"]).TongSoLuong += newCtPhieuXuatVm.SoLuongXuat; ((List <CtPhieuXuatViewModel>)Session["dsCtPhieuXuat"]).Add(newCtPhieuXuatVm); TempData["Success"] = "Đã lưu thành công một chi tiết."; return(Redirect("them-chi-tiet/")); } } } else { ModelState.AddModelError("", "Mã sách đã được thêm vào danh sách chi tiết rồi."); } } } return(View(pxViewModel)); }
public static void UpdatePhieuXuat(this PhieuXuat px, PhieuXuatViewModel pxVm) { px.Id = pxVm.Id; px.IdDaiLy = pxVm.IdDaiLy; px.NguoiNhan = pxVm.NguoiNhan; px.ThoiGianXuat = pxVm.ThoiGianXuat; px.TongSoLuong = pxVm.TongSoLuong; px.TongTien = pxVm.TongTien; px.TrangThai = true; }
public IHttpActionResult PostNewPhieuXuat(PhieuXuatViewModel phieuxuat) { if (!ModelState.IsValid) { return(BadRequest("Invalid data")); } using (var ctx = new BANHANGONLINEEntities5()) { ctx.sp_ThemPhieuXuat(phieuxuat.MAKH, phieuxuat.MASP, phieuxuat.MANV, phieuxuat.MADH, phieuxuat.SLX, phieuxuat.THANHTIEN, phieuxuat.NGAYXUAT); ctx.SaveChanges(); } return(Ok()); }
public ActionResult Edit(PhieuXuatViewModel phieuxuat) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:53017/api/nhanvien"); //HTTP POST var putTask = client.PutAsJsonAsync <PhieuXuatViewModel>("phieuxuat", phieuxuat); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(phieuxuat)); }
public ActionResult create(PhieuXuatViewModel phieuxuat) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:53017/api/phieuxuat"); // HTTP POST var postTask = client.PostAsJsonAsync <PhieuXuatViewModel>("phieuxuat", phieuxuat); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server error. Please contact administractor"); return(View(phieuxuat)); }
public ActionResult Edit(int id) { PhieuXuatViewModel phieuxuat = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:53017/api/"); // HTTP GET var responseTask = client.GetAsync("phieuxuat?id=" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <PhieuXuatViewModel>(); readTask.Wait(); phieuxuat = readTask.Result; } } return(View(phieuxuat)); }
// PUT: public IHttpActionResult PutPhieuXuat(PhieuXuatViewModel phieuxuat) { if (!ModelState.IsValid) { return(BadRequest("Invalid data")); } using (var ctx = new BANHANGONLINEEntities5()) { var existingPhieuXuat = ctx.PHIEUXUATs.Where(s => s.MAPX == phieuxuat.MAPX).FirstOrDefault <PHIEUXUAT>(); if (existingPhieuXuat != null) { ctx.sp_SuaPhieuXuat(phieuxuat.MASP, phieuxuat.MAKH, phieuxuat.MANV, phieuxuat.MADH, phieuxuat.SLX, phieuxuat.THANHTIEN, phieuxuat.NGAYXUAT, phieuxuat.MAPX); ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }