Ejemplo n.º 1
0
        public ActionResult PhieuGuiSua(PhieuGuiHangModel model, bool continueEditing)
        {
            var phieugui = _phieuguihangService.GetPhieuGuiById(model.Id);

            if (phieugui == null || phieugui.TinhTrangVanChuyen == ENTinhTrangVanChuyen.Huy)
            {
                //No manufacturer found with the specified id
                return(RedirectToAction("QLGuiHang"));
            }

            if (ModelState.IsValid)
            {
                //them nguoi gui
                var nguoigui = CapNhatKhachHang(model.NguoiGui.HoTen, model.NguoiGui.SoDienThoai, model.NguoiGui.DiaChi, model.NguoiGui.Id);
                //them nguoi nhan
                var nguoinhan = CapNhatKhachHang(model.NguoiNhan.HoTen, model.NguoiNhan.SoDienThoai, model.NguoiNhan.DiaChi, model.NguoiNhan.Id);
                //update phieu gui hang
                PhieuGuiHangModelToPhieuGuiHang(phieugui, model);
                if (!model.DaThuCuoc)
                {
                    phieugui.NgayThanhToan      = null;
                    phieugui.NhanVienNhanHangId = null;
                }
                else
                {
                    phieugui.NgayThanhToan     = model.NgayThanhToan;
                    phieugui.NhanVienThuTienId = _workContext.CurrentNhanVien.Id;
                }
                _phieuguihangService.UpdatePhieuGuiHang(phieugui);
                // update hang hoa
                if (model.HangHoa.Id > 0)
                {
                    var hanghoa = _hanghoaService.GetHangHoaById(model.HangHoa.Id);

                    HangHoaModelToHangHoa(model.HangHoa, hanghoa);
                    hanghoa.GiaCuoc = hanghoa.GiaCuoc * 1000m;
                    _hanghoaService.UpdateHangHoa(hanghoa);
                }


                if (continueEditing)
                {
                    return(RedirectToAction("PhieuGuiSua", new { id = phieugui.Id }));
                }
                return(RedirectToAction("QLGuiHang"));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Co 2 truong hop luc xuong la: tra that, hoac huy hang
        /// </summary>
        /// <param name="NhaXeId"></param>
        /// <param name="CustomerId"></param>
        /// <param name="XeXuatBenId"></param>
        /// <param name="PhieuGuiHangId"></param>
        /// <param name="isTranhang"></param>
        /// <param name="apiToken"></param>
        /// <returns></returns>
        public ActionResult TraHang(int NhaXeId, int CustomerId, int XeXuatBenId, int PhieuGuiHangId, string DiemTra, int isTraHang, string apiToken)
        {
            //kiem tra xac thuc
            string _checkauthentication = isAuthentication(NhaXeId, CustomerId, apiToken, XeXuatBenId);

            if (!String.IsNullOrEmpty(_checkauthentication))
            {
                return(ErrorOccured(_checkauthentication));
            }


            var phieuguihang = _phieuguihangService.GetPhieuGuiById(PhieuGuiHangId);

            if (phieuguihang == null)
            {
                return(ErrorOccured("Phiếu gửi hàng không hợp lệ"));
            }

            if (isTraHang == 1)
            {
                phieuguihang.DiemTra = DiemTra;
                if (!phieuguihang.DaThuCuoc)
                {
                    phieuguihang.DaThuCuoc         = true;
                    phieuguihang.NgayThanhToan     = DateTime.Now;
                    phieuguihang.NhanVienThuTienId = currentNhanVien.Id;
                }
                phieuguihang.TinhTrangVanChuyen = ENTinhTrangVanChuyen.KetThuc;
            }
            else
            {
                //truong hop la huy ve
                //kiem tra phai cung nguoi dat ve thi moi dc huy
                if (phieuguihang.NguoiTaoId != currentNhanVien.Id)
                {
                    return(ErrorOccured("Bạn không thể hủy phiếu này"));
                }
                //kiem tra thoi gian, qua thoi gian 30p thi ko dc huy
                if (phieuguihang.NgayTao.AddMinutes(30) < DateTime.Now)
                {
                    return(ErrorOccured("Quá thời hạn hủy 30 phút, bạn không thể hủy phiếu này"));
                }
                phieuguihang.TinhTrangVanChuyen = ENTinhTrangVanChuyen.Huy;
            }
            _phieuguihangService.UpdatePhieuGuiHang(phieuguihang);
            return(SuccessfulSimple("OK"));
        }