public ActionResult Create()
        {
            var viewModel = new InventoryEditModel
            {
                Inventory = new InventoryDto()
            };

            return(View(viewModel));
        }
        public ActionResult Edit(InventoryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.Inventory.Updated = DateTime.Now;
            model.Inventory.ByUser  = User.Identity.Name;
            _service.Update(model.Inventory);

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public void Inventory_InventoryEdit_ReturnsInventoryIndexView()
        {
            var viewModel = new InventoryEditModel()
            {
                Inventory = new InventoryDto()
                {
                    Name = "Test"
                }
            };

            var result = _controller.Edit(viewModel) as RedirectToRouteResult;

            Assert.That(result.RouteValues["Action"], Is.EqualTo("Index"));
        }
Esempio n. 4
0
        public void Inventory_InventoryEdit_ReturnsInventoryServiceUpdate()
        {
            var viewModel = new InventoryEditModel()
            {
                Inventory = new InventoryDto()
                {
                    Name = "Test"
                }
            };

            var result = _controller.Edit(viewModel) as RedirectToRouteResult;

            _service.Received().Update(viewModel.Inventory);
        }
Esempio n. 5
0
        public void InventoriesController_PostEditViewModel_DbSetReceivedFind()
        {
            var viewModel = new InventoryEditModel
            {
                Inventory = new InventoryDto()
                {
                    Name = "Test", IsDeleted = false
                }
            };

            _inventoriesController.Edit(viewModel);

            _dbSet.Received(1).Attach(Arg.Any <Inventory>());
            _context.Received(1).SaveChanges();
        }
Esempio n. 6
0
        public void InventoriesController_PostCreateViewModel_DbSetReceivedAddAndContextReceivedSaveChanges()
        {
            var viewModel = new InventoryEditModel
            {
                Inventory = new InventoryDto()
                {
                    Name = "Test", IsDeleted = false
                }
            };

            _inventoriesController.Create(viewModel);

            _dbSet.Received(1).Add(Arg.Any <Inventory>());
            _context.Received(1).SaveChanges();
        }
        public ActionResult Edit(int id)
        {
            var modelDto = _service.GetSingle(id);

            if (modelDto == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new InventoryEditModel
            {
                Inventory = modelDto
            };

            return(View(viewModel));
        }
        // [Audit]
        public JsonResult UpdateDrugSerialNoAndExpDate(InventoryEditModel inventoryEditModel)
        {
            var response = new ResponseData <string>();

            try
            {
                var service = IoC.Container.Resolve <IInventoryAdjustmentService>();

                service.UpdateDrugSerialNoAndExpDate(MedSessionManager.CurrentDrugStoreCode, inventoryEditModel);
            }
            catch (ValidationException ex)
            {
                response.SetErrors(ex.Errors);
                response.SetStatus(HttpStatusCode.PreconditionFailed);
            }

            return(Json(response));
        }
Esempio n. 9
0
        // cap nhat gia/lo/han dung cho tung thuoc o trong Phieu kiem ke
        public void UpdateDrugSerialNoAndExpDate(String maNhaThuoc, InventoryEditModel inventoryEditModel)
        {
            int inventoryId = inventoryEditModel.InventoryId;

            // return khi ma phieu kiem ke khong hop le
            if (inventoryId <= 0)
            {
                return;
            }

            bool     canKho  = inventoryEditModel.DaCanKho;
            decimal  gia     = inventoryEditModel.Gia;
            string   soLo    = inventoryEditModel.SoLo;
            DateTime?hanDung = inventoryEditModel.HanDung;

            var phieuKiemKeRepo        = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKe> >().GetAll();
            var phieuKiemKeChiTietRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKeChiTiet> >();
            var phieuNhapChiTietRepo   = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuNhapChiTiet> >();
            var phieuXuatChiTietRepo   = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuXuatChiTiet> >();

            InventoryDetailModel inventoryDetailModel = GetInventoryDetailInfo(maNhaThuoc, inventoryId);
            var thuocId = inventoryDetailModel.MedicineList.Where(x => x.MaThuoc == inventoryEditModel.MaThuoc).FirstOrDefault().ThuocId;
            // lay thong tin phieu kiem ke chi tiet theo PhieuKiemKe_MaPhieuKiemKe va Thuoc_ThuocId
            var pkkctQuery = from pkkct in phieuKiemKeChiTietRepo.GetAll()
                             where (pkkct.PhieuKiemKe_MaPhieuKiemKe == inventoryId && pkkct.RecordStatusID == (byte)RecordStatus.Activated &&
                                    pkkct.Thuoc_ThuocId == thuocId)

                             select pkkct;

            var pkkctQueryResult = pkkctQuery.FirstOrDefault();
            PhieuKiemKeChiTiet phieuKiemKeChiTietEntity = pkkctQueryResult;

            phieuKiemKeChiTietEntity.DonGia  = gia;
            phieuKiemKeChiTietEntity.SoLo    = soLo;
            phieuKiemKeChiTietEntity.HanDung = hanDung;

            // cap nhat gia/lo/han vao bang PhieuKiemKeChiTiets
            phieuKiemKeChiTietRepo.Update(phieuKiemKeChiTietEntity);
            phieuKiemKeChiTietRepo.Commit();

            // TH phieu da can kho, cap nhat gia/lo/han trong phieu Nhap/xuat chi tiet
            if (canKho)
            {
                inventoryDetailModel.PhieuCanKhoChiTiet.ForEach(p =>
                {
                    // TH Phieu Nhap thì update giá nhập/lô/hạn dùng vào phiếu nhập chi tiết
                    if (p.LoaiPhieu == NoteInOutType.Receipt && p.SoLuong > 0)
                    {
                        // tim Phieu Nhap Chi Tiet theo MaPhieu va thuocId
                        var pnctQuery = from pnct in phieuNhapChiTietRepo.GetAll()
                                        where (pnct.PhieuNhap_MaPhieuNhap == p.MaPhieu &&
                                               pnct.Thuoc_ThuocId == thuocId)

                                        select pnct;

                        var pnctQueryResult = pnctQuery.FirstOrDefault();
                        if (pnctQueryResult != null)
                        {
                            PhieuNhapChiTiet phieuNhapChiTietEntity = pnctQueryResult;
                            phieuNhapChiTietEntity.GiaNhap          = gia;
                            phieuNhapChiTietEntity.SoLo             = soLo;
                            phieuNhapChiTietEntity.HanDung          = hanDung;

                            phieuNhapChiTietRepo.Update(phieuNhapChiTietEntity);
                            phieuNhapChiTietRepo.Commit();
                        }
                    }
                    // TH Phieu Xuat thì update giá xuất
                    if (p.LoaiPhieu == NoteInOutType.Delivery && p.SoLuong > 0)
                    {
                        // tim Phieu Xuat Chi Tiet theo MaPhieu va thuocId
                        var pxctQuery = from pxct in phieuXuatChiTietRepo.GetAll()
                                        where (pxct.PhieuXuat_MaPhieuXuat == p.MaPhieu &&
                                               pxct.Thuoc_ThuocId == thuocId)

                                        select pxct;
                        var pxctQueryResult = pxctQuery.FirstOrDefault();
                        if (pxctQueryResult != null)
                        {
                            PhieuXuatChiTiet phieuXuatChiTietEntity = pxctQueryResult;
                            phieuXuatChiTietEntity.GiaXuat          = gia;

                            phieuXuatChiTietRepo.Update(phieuXuatChiTietEntity);
                            phieuXuatChiTietRepo.Commit();
                        }
                    }
                });
            }
        }