コード例 #1
0
        public void Commodity_Create_Post_For_InValid_Model_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            Commodity           commodity  = new Commodity
            {
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = 1
            };

            //SetModelError(target);

            int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(5, commodityPreCount); // Verify the expected Number pre-insert
            PartialViewResult expected = new PartialViewResult();
            ActionResult      actual;


            //Act
            actual = target.Create(commodity);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);
            //no increase in the number of commodities
            int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(commodityPreCount, commodityPostCount);
        }
コード例 #2
0
        public void Commodity_Create_Post_For_Valid_Model_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            Commodity           commodity  = new Commodity
            {
                Name            = "Gebse",
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = 1
            };

            int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(5, commodityPreCount);
            JsonResult   expected = new JsonResult();
            ActionResult actual;

            //Act
            actual = target.Create(commodity);
            JsonResult result = actual as JsonResult;

            expected.Data = new { success = true };

            //the number of commodities should increase by 1
            int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(commodityPreCount + 1, commodityPostCount);
            Assert.AreEqual(expected.Data.ToString(), result.Data.ToString());
        }
コード例 #3
0
        public void Commodity_Create_Parent_Commodity_Get_Test()
        {
            IUnitOfWork repository = this.MockCommodityRepository;

            CommodityController target = new CommodityController(repository);
            int            type        = 1;
            Nullable <int> Parent      = null; //parent commodity is set to null cos it's the parent itself
            ActionResult   expected    = null;
            ActionResult   actual;

            actual = target.Create(type, Parent);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.AreEqual(result.Model.GetType(), typeof(Commodity));

            Assert.IsNotNull(result.ViewBag.CommodityTypeID);
            //major diff between parent and child
            Assert.IsNull(result.ViewBag.ParentID);
            Assert.AreEqual(result.ViewBag.isParent, false);
            Assert.IsNull(result.ViewBag.CommodityType);
            Assert.IsNull(result.ViewBag.ParentCommodity);
        }
コード例 #4
0
        public void Commodity_List_Partial_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();
            ActionResult        actual     = null;

            //act call the index will call getall() from the repo and returns a list of comods
            actual = target.CommodityListPartial();

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable <Commodity>));

            Assert.IsNull(result.ViewBag.Title);
            Assert.IsNotNull(result.ViewBag.ParentID);
            Assert.IsNotNull(result.ViewBag.SelectedCommodityID);
            Assert.AreEqual("_CommodityPartial", result.ViewName);

            //just for testing that we are really using the test model objects
            var count = result.ViewData.Model as IEnumerable <Commodity>;

            Assert.AreEqual(2, count.Count());
        }
コード例 #5
0
        public void Commodity_Edit_Post_InValid_Model_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            Commodity           commodity  = new Commodity
            {
                CommodityID     = 1,
                Name            = "aja",
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = 1
            };

            //SetModelError(target);

            PartialViewResult expected = new PartialViewResult();
            ActionResult      actual;

            //Act
            actual = target.Edit(commodity);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);
        }
コード例 #6
0
        public void Init()
        {
            var commodities = new List <Commodity>
            {
                new Commodity {
                    CommodityID = 1, Name = "Cereal", CommodityCode = "CER", CommodityTypeID = 1, ParentID = null
                },
                new Commodity {
                    CommodityID = 5, Name = "Wheat", CommodityCode = null, CommodityTypeID = 1, ParentID = 1
                },
            };
            var commodityService = new Mock <ICommodityService>();

            commodityService.Setup(t => t.GetAllCommodity()).Returns(commodities);

            var commodityTypes = new List <CommodityType>
            {
                new CommodityType {
                    CommodityTypeID = 1, Name = "Food"
                },
                new CommodityType {
                    CommodityTypeID = 2, Name = "Non Food"
                }
            };
            var commodityTypeService = new Mock <ICommodityTypeService>();

            commodityTypeService.Setup(t => t.GetAllCommodityType()).Returns(commodityTypes);

            _commodityController = new CommodityController(commodityTypeService.Object, commodityService.Object);
        }
コード例 #7
0
        public void UpdateTest()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();
            Nullable <int>      param      = 1; // TODO: Initialize to an appropriate value
            ActionResult        actual;

            //act call the index will call getall() from the repo and returns a list of comods
            actual = target.Update(param);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable <Commodity>));

            Assert.IsNull(result.ViewBag.Title);
            Assert.IsNotNull(result.ViewBag.ParentID);
            Assert.IsNotNull(result.ViewBag.SelectedCommodityID);
            Assert.IsNotNull(result.ViewBag.Parents);


            //just for testing that we are really using the test model objects
            var count = result.ViewData.Model as IEnumerable <Commodity>;

            Assert.AreEqual(count.Count(), 5);
        }
コード例 #8
0
        public void Commodity_Controller_Index_Test()
        {
            //this three lines are good for testing null pointer exception validations
            //Mock<IUnitOfWork> mockCommodityRepository = new Mock<IUnitOfWork>();
            //CommodityController target = new CommodityController(mockCommodityRepository.Object); // TODO: Initialize to an appropriate value
            // mockCommodityRepository.Object.GetAll();//SetupGet(d => d.GetAllParents()).SetupGet(d => d.GetAll()).Returns(mockCommodityRepository.Object.GetAll());

            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();


            //act call the index will call getall() from the repo and returns a list of comods
            ActionResult actual = target.Index();


            ViewResult result = actual as ViewResult;

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable <Commodity>));

            Assert.IsNull(result.ViewBag.Title);
            Assert.IsNotNull(result.ViewBag.ParentID);
            Assert.IsNotNull(result.ViewBag.SelectedCommodityID);
            Assert.IsNotNull(result.ViewBag.Parents);


            //just for testing that we are really using the test model objects
            var count = result.ViewData.Model as IEnumerable <Commodity>;

            Assert.AreEqual(count.Count(), 5);
        }
コード例 #9
0
        public void Commodity_Edit_Post_Valid_Model_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            Commodity           commodity  = new Commodity
            {
                CommodityID     = 1,
                Name            = "Wheat",
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = null
            };

            //SetModelError(target);

            JsonResult   expected = new JsonResult();
            ActionResult actual;

            //Act
            actual = target.Edit(commodity);

            JsonResult result = actual as JsonResult;

            expected.Data = new { success = true };

            Assert.AreEqual(expected.Data.ToString(), result.Data.ToString());
        }
コード例 #10
0
        public void Commodity_Delete_Confirmed_Faliure_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            Commodity           commodity  = new Commodity
            {
                Name            = "Gebse",
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = null
            };
            int id = 1; //delete the wheat commodity

            int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(5, commodityPreCount);
            JsonResult   expected = new JsonResult();
            ActionResult actual;

            //Act
            actual = target.DeleteConfirmed(id);
            ViewResult result = actual as ViewResult;

            //the number of commodities should decrease by 1
            int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(commodityPreCount, commodityPostCount);

            Assert.AreEqual(result.ViewBag.ERROR, true);
            Assert.IsNotNull(result.ViewBag.ERROR_MSG);
        }
コード例 #11
0
        public void Commodity_Delete_Confirmed_Success_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            //Commodity commodity = new Commodity
            //{
            //    Name = "Gebse",
            //    LongName = "",
            //    CommodityTypeID = 1,
            //    ParentID = 1
            //};
            int id = 6; //delete the child yellow wheat commodity

            int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(5, commodityPreCount);
            JsonResult   expected = new JsonResult();
            ActionResult actual;
            const string testUrl = "/Commodity";

            //Act
            actual = target.DeleteConfirmed(id);
            RedirectToRouteResult result = actual as RedirectToRouteResult;

            //the number of commodities should decrease by 1
            int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count;

            Assert.AreEqual(commodityPreCount - 1, commodityPostCount);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
コード例 #12
0
        public void Get_Parent_List_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = null;
            ActionResult        actual;

            actual = target.GetParentList();

            JsonResult result = actual as JsonResult;


            Assert.AreEqual(result.Data.GetType(), typeof(SelectList));

            var count = result.Data as SelectList;

            Assert.AreEqual(2, count.Count());
        }
コード例 #13
0
        public void Sub_Commodity_List_Partial_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();

            //get all childrens of id (i.e. wheat for this case)
            int          id = 1;
            ActionResult actual;

            actual = target.SubCommodityListPartial(id);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable <Commodity>));
            Assert.AreEqual(result.ViewBag.SelectedCommodityID, id);
            Assert.AreEqual(result.ViewBag.ShowParentCommodity, true);
        }
コード例 #14
0
        public void Commodity_Delete_Get_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            int        id       = 1; //details of wheat
            ViewResult expected = new ViewResult();

            expected.ViewData.Model = new Commodity
            {
                CommodityID     = 1,
                Name            = "Wheat",
                LongName        = "",
                CommodityTypeID = 1,
                ParentID        = null
            };
            ActionResult actual;

            actual = target.Delete(id);

            ViewResult result = actual as ViewResult;

            Assert.IsNotNull(result);

            Assert.AreEqual(result.ViewData.Model.GetType(), typeof(Commodity));


            //displays the correct info for deletion process

            Commodity CommodityX = result.ViewData.Model as Commodity;
            Commodity CommodityY = expected.ViewData.Model as Commodity;

            Assert.AreEqual(CommodityY.CommodityID, CommodityX.CommodityID);
            Assert.AreEqual(CommodityY.Name, CommodityX.Name);
            Assert.AreEqual(CommodityY.LongName, CommodityX.LongName);
            Assert.AreEqual(CommodityY.CommodityTypeID, CommodityX.CommodityTypeID);
            Assert.AreEqual(CommodityY.ParentID, CommodityX.ParentID);

            Assert.AreEqual("Delete", result.ViewName);
            Assert.AreEqual(result.ViewData.ModelState.IsValid, true);
        }
コード例 #15
0
        public void Commodity_Edit_Get_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            int          id = 1;
            ActionResult actual;

            actual = target.Edit(id);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.AreEqual(result.Model.GetType(), typeof(Commodity));

            Assert.IsNotNull(result.ViewBag.CommodityTypeID);

            //major diff between parent and child
            //Assert.IsNull(result.ViewBag.ParentID);
            Assert.AreEqual(result.ViewBag.isParent, false);
            Assert.IsNull(result.ViewBag.CommodityType);
            Assert.IsNull(result.ViewBag.ParentCommodity);
        }
コード例 #16
0
 public void Commodity_Controller_Constructor_With_Two_Repos_Test()
 {
     IUnitOfWork commodityRepository = this.MockCommodityRepository; // TODO: Initialize to an appropriate value
     ICommodityTypeRepository commodityTypeRepository = null;        // TODO: Initialize to an appropriate value
     CommodityController      target = new CommodityController(commodityRepository);
 }
コード例 #17
0
        public bool ImportExcel(string fileName, string sheetName)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                OleDbAPIs oleDbAPIs = new OleDbAPIs(CommonNinject.Kernel.Get <IOleDbAPIRepository>(), GlobalEnums.MappingTaskID.Lavie);

                CommodityViewModel  commodityViewModel  = CommonNinject.Kernel.Get <CommodityViewModel>();
                CommodityController commodityController = new CommodityController(CommonNinject.Kernel.Get <ICommodityService>(), commodityViewModel);


                int            intValue; decimal decimalValue; DateTime dateTimeValue;
                ExceptionTable exceptionTable = new ExceptionTable(new string[2, 2] {
                    { "ExceptionCategory", "System.String" }, { "Description", "System.String" }
                });

                //////////TimeSpan timeout = TimeSpan.FromMinutes(90);
                //////////using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, timeout))
                //////////{
                //////////if (!this.Editable(this.)) throw new System.ArgumentException("Import", "Permission conflict");


                DataTable excelDataTable = oleDbAPIs.OpenExcelSheet(fileName, sheetName);
                if (excelDataTable != null && excelDataTable.Rows.Count > 0)
                {
                    foreach (DataRow excelDataRow in excelDataTable.Rows)
                    {
                        exceptionTable.ClearDirty();

                        this.lavieController.Create();

                        this.lavieViewModel.EntryDate    = new DateTime(2000, 1, 1);
                        this.lavieViewModel.PrintedTimes = 0;

                        if (int.TryParse(excelDataRow["SerialID"].ToString(), out intValue))
                        {
                            this.lavieViewModel.SerialID = intValue;
                        }
                        else
                        {
                            exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu No", "No: " + excelDataRow["SerialID"].ToString() });
                        }

                        if (DateTime.TryParse(excelDataRow["ExpirationDate"].ToString(), out dateTimeValue))
                        {
                            this.lavieViewModel.ExpirationDate = dateTimeValue;
                        }
                        else
                        {
                            exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu ExpirationDate", "No: " + this.lavieViewModel.SerialID + ": " + excelDataRow["ExpirationDate"].ToString() });
                        }
                        if (decimal.TryParse(excelDataRow["Qty"].ToString(), out decimalValue))
                        {
                            this.lavieViewModel.Qty = decimalValue;
                        }
                        else
                        {
                            exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Qty", "No: " + this.lavieViewModel.SerialID + ": " + excelDataRow["Qty"].ToString() });
                        }
                        if (decimal.TryParse(excelDataRow["Layers"].ToString(), out decimalValue))
                        {
                            this.lavieViewModel.Layers = decimalValue;
                        }
                        else
                        {
                            exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Layers", "No: " + this.lavieViewModel.SerialID + ": " + excelDataRow["Layers"].ToString() });
                        }

                        this.lavieViewModel.ItemNumber  = excelDataRow["ItemNumber"].ToString();
                        this.lavieViewModel.ProductName = excelDataRow["ProductName"].ToString();
                        this.lavieViewModel.GTIN        = excelDataRow["GTIN"].ToString();
                        this.lavieViewModel.PalletID    = excelDataRow["PalletID"].ToString();
                        this.lavieViewModel.BatchNumber = excelDataRow["BatchNumber"].ToString();
                        this.lavieViewModel.GTINBarcode = excelDataRow["GTINBarcode"].ToString();
                        this.lavieViewModel.Barcode     = excelDataRow["Barcode"].ToString();


                        if (!this.lavieViewModel.IsValid)
                        {
                            exceptionTable.AddException(new string[] { "Lỗi dữ liệu không hợp lệ, dòng No: ", this.lavieViewModel.SerialID + ": " + this.lavieViewModel.Error });
                        }
                        ;
                        if (!exceptionTable.IsDirty)
                        {
                            if (this.lavieViewModel.IsDirty && !this.lavieController.Save())
                            {
                                exceptionTable.AddException(new string[] { "Lỗi lưu dữ liệu, dòng No: ", this.lavieViewModel.SerialID + this.lavieController.BaseService.ServiceTag });
                            }
                        }
                    }
                }

                Cursor.Current = Cursors.WaitCursor;

                if (exceptionTable.Table.Rows.Count <= 0)
                {
                    return(true);
                }
                else
                {
                    throw new CustomException("Lỗi import file excel. Vui lòng xem danh sách đính kèm. Click vào từng nội dung để xem chi tiết.", exceptionTable.Table);
                }
            }
            catch (System.Exception exception)
            {
                Cursor.Current = Cursors.WaitCursor;
                throw exception;
            }
        }
コード例 #18
0
 public Resources()
 {
     Repository = new Mock <ICommodityRepository>();
     Controller = new CommodityController(Repository.Object);
 }
コード例 #19
0
ファイル: BatchMasters.cs プロジェクト: Proerp/LAVIE12AUG
        public bool ImportExcel(string fileName, string sheetName)
        {
            try
            {
                OleDbAPIs oleDbAPIs = new OleDbAPIs(CommonNinject.Kernel.Get <IOleDbAPIRepository>(), GlobalEnums.MappingTaskID.BatchMaster);

                CommodityViewModel  commodityViewModel  = CommonNinject.Kernel.Get <CommodityViewModel>();
                CommodityController commodityController = new CommodityController(CommonNinject.Kernel.Get <ICommodityService>(), commodityViewModel);


                int            intValue; decimal decimalValue; DateTime dateTimeValue;
                ExceptionTable exceptionTable = new ExceptionTable(new string[2, 2] {
                    { "ExceptionCategory", "System.String" }, { "Description", "System.String" }
                });

                //////////TimeSpan timeout = TimeSpan.FromMinutes(90);
                //////////using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, timeout))
                //////////{
                //////////if (!this.Editable(this.)) throw new System.ArgumentException("Import", "Permission conflict");


                DataTable excelDataTable = oleDbAPIs.OpenExcelSheet(fileName, sheetName);
                if (excelDataTable != null && excelDataTable.Rows.Count > 0)
                {
                    foreach (DataRow excelDataRow in excelDataTable.Rows)
                    {
                        exceptionTable.ClearDirty();

                        string code = excelDataRow["Code"].ToString().Trim();
                        if (code.Length < 5)
                        {
                            code = new String('0', 5 - code.Length) + code;
                        }

                        BatchMasterBase batchMasterBase = this.batchMasterAPIs.GetBatchMasterBase(code);

                        if (batchMasterBase == null)
                        {
                            this.batchMasterController.Create();

                            this.batchMasterViewModel.EntryDate = new DateTime(2000, 1, 1);
                            this.batchMasterViewModel.Code      = code;


                            if (DateTime.TryParse(excelDataRow["PlannedDate"].ToString(), out dateTimeValue))
                            {
                                this.batchMasterViewModel.PlannedDate = dateTimeValue;
                            }
                            else
                            {
                                exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Plan start date", "Batch: " + code + ": " + excelDataRow["PlannedDate"].ToString() });
                            }
                            if (decimal.TryParse(excelDataRow["PlannedQuantity"].ToString(), out decimalValue))
                            {
                                this.batchMasterViewModel.PlannedQuantity = decimalValue;
                            }
                            else
                            {
                                exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu SL Kế hoạch", "Batch: " + code + ": " + excelDataRow["PlannedQuantity"].ToString() });
                            }

                            CommodityBase commodityBase = this.commodityAPIs.GetCommodityBase(excelDataRow["CommodityCode"].ToString());
                            if (commodityBase != null)
                            {
                                this.batchMasterViewModel.CommodityID = commodityBase.CommodityID;
                            }
                            else
                            {
                                commodityController.Create();

                                commodityViewModel.Code         = excelDataRow["CommodityCode"].ToString();
                                commodityViewModel.APICode      = excelDataRow["CommodityAPICode"].ToString().Replace("'", "");
                                commodityViewModel.CartonCode   = excelDataRow["CommodityCartonCode"].ToString().Replace("'", "");
                                commodityViewModel.Name         = excelDataRow["CommodityName"].ToString();
                                commodityViewModel.OfficialName = excelDataRow["CommodityName"].ToString();

                                commodityViewModel.CommodityCategoryID = 2;
                                commodityViewModel.FillingLineIDs      = "1,2";

                                if (decimal.TryParse(excelDataRow["Volume"].ToString(), out decimalValue))
                                {
                                    commodityViewModel.Volume = decimalValue / 1000;
                                }
                                else
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Trọng lượng", "Batch: " + code + ": " + excelDataRow["Volume"].ToString() });
                                }
                                if (int.TryParse(excelDataRow["PackPerCarton"].ToString(), out intValue))
                                {
                                    commodityViewModel.PackPerCarton = intValue;
                                }
                                else
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu QC thùng", "Batch: " + code + ": " + excelDataRow["PackPerCarton"].ToString() });
                                }
                                if (int.TryParse(excelDataRow["CartonPerPallet"].ToString(), out intValue))
                                {
                                    commodityViewModel.CartonPerPallet = intValue / commodityViewModel.PackPerCarton;
                                }
                                else
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu QC pallet", "Batch: " + code + ": " + excelDataRow["CartonPerPallet"].ToString() });
                                }

                                commodityViewModel.PackageSize = commodityViewModel.PackPerCarton.ToString("N0") + "x" + commodityViewModel.Volume.ToString("N2") + "kg";

                                if (int.TryParse(excelDataRow["Shelflife"].ToString(), out intValue))
                                {
                                    commodityViewModel.Shelflife = intValue;
                                }
                                else
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Expiration months", "Batch: " + code + ": " + excelDataRow["Shelflife"].ToString() });
                                }

                                if (!commodityViewModel.IsValid)
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi dữ liệu sản phẩm không hợp lệ", excelDataRow["CommodityCode"].ToString() + ": " + commodityViewModel.Error });
                                }
                                else
                                if (commodityViewModel.IsDirty)
                                {
                                    if (commodityController.Save())
                                    {
                                        this.batchMasterViewModel.CommodityID = commodityViewModel.CommodityID;
                                    }
                                    else
                                    {
                                        exceptionTable.AddException(new string[] { "Lỗi lưu dữ liệu [thêm sản phẩm mới]", excelDataRow["CommodityCode"].ToString() + commodityController.BaseService.ServiceTag });
                                    }
                                }
                            }


                            BatchStatusBase batchStatusBase = this.batchStatusAPIs.GetBatchStatusBase(excelDataRow["BatchStatusCode"].ToString());
                            if (batchStatusBase != null)
                            {
                                this.batchMasterViewModel.BatchStatusID = batchStatusBase.BatchStatusID;
                            }
                            else
                            {
                                exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Trạng thái", "Batch: " + code + ": " + excelDataRow["BatchStatusCode"].ToString() });
                            }


                            if (!this.batchMasterViewModel.IsValid)
                            {
                                exceptionTable.AddException(new string[] { "Lỗi dữ liệu Batch không hợp lệ", "Batch: " + code + ": " + this.batchMasterViewModel.Error });
                            }
                            ;
                            if (!exceptionTable.IsDirty)
                            {
                                if (this.batchMasterViewModel.IsDirty && !this.batchMasterController.Save())
                                {
                                    exceptionTable.AddException(new string[] { "Lỗi lưu dữ liệu [thêm batch mới]", code + this.batchMasterController.BaseService.ServiceTag });
                                }
                            }
                        }
                        else
                        {
                            exceptionTable.AddException(new string[] { "Batch không được import, do đã tồn tại trên hệ thống", "Batch: " + code });
                        }
                    }
                }

                if (exceptionTable.Table.Rows.Count <= 0)
                {
                    return(true);
                }
                else
                {
                    throw new CustomException("Lỗi import file excel. Vui lòng xem danh sách đính kèm. Click vào từng nội dung để xem chi tiết.", exceptionTable.Table);
                }
            }
            catch (System.Exception exception)
            {
                throw exception;
            }
        }
コード例 #20
0
 public void CommodityControllerConstructorTest2()
 {
     CommodityController target = new CommodityController();
 }
コード例 #21
0
 public void Commodity_Controller_Constructor_With_One_RepoTest()
 {
     IUnitOfWork         repository = this.MockCommodityRepository;
     CommodityController target     = new CommodityController(repository);
 }