Esempio n. 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SpecificationViewModel = await _specificationViewModelService
                                     .GetSpecificationViewModel((int)id);

            if (SpecificationViewModel == null)
            {
                return(NotFound());
            }

            return(Page());
        }
        public ActionResult GenerateSpecification(
            [Bind(
                 "Id,Name,Description,ShortDescription,Icon,IsPublished,ProductTypeId,CategoryProductId,ProductImages,Specifications")]
            ProductViewModel product)
        {
            var specification = new SpecificationViewModel();

            if (product.Specifications == null)
            {
                product.Specifications = new List <SpecificationViewModel>();
            }

            product.Specifications.Add(specification);

            product = FillViewModelSpecifications(product);

            return(PartialView("_SpecificationsCreate", product));
        }
Esempio n. 3
0
        public bool Create(SpecificationViewModel model, IDataSourceError error)
        {
            var specification = new ProductSpecification {
                Name = model.Text, ProductCategoryId = model.Parent
            };

            this.DbContext.ProductSpecifications.Add(specification);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.Value = specification.ProductSpecificationId;
                result      = true;
            }
            catch { }

            return(result);
        }
Esempio n. 4
0
        public bool?Update(int key, SpecificationViewModel model, IDataSourceError error)
        {
            var specification = this.SingleOrDefault(key);

            if (specification == null)
            {
                return(null);
            }

            specification.Name = model.Text;
            specification.ProductCategoryId = model.Parent;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
Esempio n. 5
0
        public ActionResult Detail(Guid?id = null)
        {
            if (id != null)
            {
                Guid company_Id = WorkContext.CurrentMembershipUser.Company.Id;
                var  entity     = _specificationService.Single(id.Value, company_Id);
                if (entity != null)
                {
                    var model = new SpecificationViewModel()
                    {
                        Id            = entity.Id,
                        Product_Name  = entity.Product_Name,
                        CN_Name       = entity.CN_Name,
                        Purpose       = entity.Purpose,
                        Product_State = entity.Product_State,
                        Product_UN    = entity.Product_UN,
                        Product_HazardousDescription = entity.Product_HazardousDescription,
                        UnHazardousChemical          = entity.UnHazardousChemical,
                        CASCode                     = entity.CASCode,
                        Supplier_Name               = entity.Supplier_Name,
                        Supplier_Address            = entity.Supplier_Address,
                        Supplier_Phone              = entity.Supplier_Phone,
                        Supplier_UrgencyCall        = entity.Supplier_UrgencyCall,
                        Product_HazardousSubstances = entity.HazardousSubstance,
                        AttachmentPath              = entity.AttachmentPath,

                        GHS_Category           = entity.GHS_Category,
                        GHS_Warning            = entity.GHS_Warning,
                        GHS_HazardouDes_Append = entity.GHS_HazardouDes_Append,
                        GHS_DefenceDes_Append  = entity.GHS_DefenceDes_Append,
                        GHS_DealDES_Append     = entity.GHS_DealDES_Append,
                        GHS_StoreDes_Append    = entity.GHS_StoreDes_Append,
                        IsExplosive            = entity.IsExplosive,
                        IsFlammable            = entity.IsFlammable,
                        IsCorrosive            = entity.IsCorrosive,
                        IsHealthHazard         = entity.IsHealthHazard,
                        IsToxic                  = entity.IsToxic,
                        IsOxidizing              = entity.IsOxidizing,
                        IsGasUnderPressure       = entity.IsGasUnderPressure,
                        IsIrritant               = entity.IsIrritant,
                        IsDangerousToEnvironment = entity.IsDangerousToEnvironment,

                        Product_Protection_FaceAndEye = entity.Product_Protection_FaceAndEye,
                        Product_Protection_Hand       = entity.Product_Protection_Hand,
                        Product_Protection_Breathing  = entity.Product_Protection_Breathing,
                        Product_Protection_Foot       = entity.Product_Protection_Foot,
                        Product_Protection_Body       = entity.Product_Protection_Body,
                        Product_Protection_Other      = entity.Product_Protection_Other,
                        IsProtection_FaceAndEye       = entity.IsProtection_FaceAndEye,
                        IsProtection_Other            = entity.IsProtection_Other,
                        IsProtection_Breathing        = entity.IsProtection_Breathing,
                        IsProtection_Body             = entity.IsProtection_Body,
                        IsProtection_Foot             = entity.IsProtection_Foot,
                        IsProtection_Hand             = entity.IsProtection_Hand,

                        Product_ET_FaceAndEye  = entity.Product_ET_FaceAndEye,
                        Product_ET_SkinAndHand = entity.Product_ET_SkinAndHand,
                        Product_ET_Inhalation  = entity.Product_ET_Inhalation,
                        Product_ET_Ingestion   = entity.Product_ET_Ingestion,

                        Product_FireProtection   = entity.Product_FireProtection,
                        Product_LeakageHanding   = entity.Product_LeakageHanding,
                        Product_OperationSecure  = entity.Product_OperationSecure,
                        Product_StoreRequirement = entity.Product_StoreRequirement,
                        Product_WasteHanding     = entity.Product_WasteHanding,
                        Product_Note             = entity.Product_Note,

                        Policie_UN            = entity.Policie_UN,
                        Policie_Local         = entity.Policie_Local,
                        ExposedLimit_Solid    = entity.ExposedLimit_Solid,
                        ExposedLimit_Gas      = entity.ExposedLimit_Gas,
                        PhysicalState         = entity.PhysicalState,
                        AppearanceAndSmell    = entity.AppearanceAndSmell,
                        BoilingPoint_Liquid_C = entity.BoilingPoint_Liquid.HasValue ? (double?)entity.BoilingPoint_Liquid.Value : null,
                        BoilingPoint_Liquid_F = ((entity.BoilingPoint_Liquid.HasValue ? (double?)(entity.BoilingPoint_Liquid.Value * 1.8M + 32) : null)),
                        FlashingPoint_C       = entity.FlashingPoint.HasValue ? (double?)entity.FlashingPoint.Value : null,
                        FlashingPoint_F       = ((entity.FlashingPoint.HasValue ? (double?)(entity.FlashingPoint.Value * 1.8M + 32) : null)),
                        BurningLimit_Max      = entity.BurningLimit_Max,
                        BurningLimit_Min      = entity.BurningLimit_Min,
                        VaporPressure         = entity.VaporPressure.HasValue ? (double?)entity.VaporPressure.Value : null,
                        VaporPressure_Pa      = (entity.VaporPressure.HasValue ? (double?)(entity.VaporPressure.Value * 133.32M) : null),
                        LD50_KG = entity.LD50_KG,
                        LD50_L  = entity.LD50_L
                    };
                    PrepareSpecificationViewModel(model, entity);
                    return(View(model));
                }
                else
                {
                    ErrorNotification(new Exception("编辑失败,未找到Id为" + id.ToString() + "的化学品"));
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                SpecificationViewModel model = new SpecificationViewModel();
                PrepareSpecificationViewModel(model, null);
                return(View(model));
            }
        }
Esempio n. 6
0
        private void PrepareSpecificationViewModel(SpecificationViewModel model, MSDS_Specification entity)
        {
            #region 加载状态DropDownList
            List <Product_State> stateList = new List <Product_State>();
            stateList.Add(new Product_State {
                State_Id = 0, State_Name = ""
            });
            stateList.Add(new Product_State {
                State_Id = 1, State_Name = "气态"
            });
            stateList.Add(new Product_State {
                State_Id = 2, State_Name = "液态"
            });
            stateList.Add(new Product_State {
                State_Id = 3, State_Name = "固态"
            });
            stateList.Add(new Product_State {
                State_Id = 4, State_Name = "气溶胶"
            });
            stateList.Add(new Product_State {
                State_Id = 5, State_Name = "凝胶"
            });
            stateList.Add(new Product_State {
                State_Id = 6, State_Name = "膏状物"
            });
            stateList.Add(new Product_State {
                State_Id = 7, State_Name = "其他"
            });

            List <string> warningSign = new List <string>();
            warningSign.Add("警 告");
            warningSign.Add("危 险");

            IList <MSDS_H_Statement> statments   = _h_StatementService.GetAll();
            IList <MSDS_P_Statement> p_statments = _p_StatementService.GetAll();

            foreach (var item in stateList)
            {
                model.ProductStateItems.Add(new SelectListItem {
                    Text = item.State_Name, Value = item.State_Id.ToString(), Selected = entity != null && item.State_Id == entity.Product_State
                });
            }

            foreach (var item in warningSign)
            {
                model.ProductWarningSignItems.Add(new SelectListItem {
                    Text = item, Value = item, Selected = entity != null && item == entity.GHS_Warning
                });
            }
            #endregion

            if (entity != null && entity.UnHazardousChemical.HasValue && !entity.UnHazardousChemical.Value)
            {
                model.UnHazardousChemicalItems.Add(new SelectListItem {
                    Text = "是", Value = "true", Selected = false
                });
                model.UnHazardousChemicalItems.Add(new SelectListItem {
                    Text = "否", Value = "false", Selected = true
                });
            }
            else
            {
                model.UnHazardousChemicalItems.Add(new SelectListItem {
                    Text = "是", Value = "true", Selected = true
                });
                model.UnHazardousChemicalItems.Add(new SelectListItem {
                    Text = "否", Value = "false", Selected = false
                });
            }

            if (entity != null)
            {
                model.Id = entity.Id;
                char[] sp = new char[1] {
                    ','
                };
                #region
                foreach (MSDS_H_Statement item in statments)
                {
                    string[] tempArray = entity.GHS_HazardouDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries);
                    if (tempArray != null && tempArray.Any(o => o == item.Code))
                    {
                        model.GHS_HazardouDes_String += item.Description + "\r\n";
                    }
                }

                foreach (MSDS_P_Statement item in p_statments)
                {
                    string[] tempArray1 = entity.GHS_DefenceDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries);
                    if (tempArray1 != null && tempArray1.Any(o => o == item.Code))
                    {
                        model.GHS_DefenceDes_String += item.Description + "\r\n";
                    }
                    string[] tempArray2 = entity.GHS_DealDES_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries);
                    if (tempArray2 != null && tempArray2.Any(o => o == item.Code))
                    {
                        model.GHS_DealDES_String += item.Description + "\r\n";
                    }
                    string[] tempArray3 = entity.GHS_StoreDes_Values?.Split(sp, StringSplitOptions.RemoveEmptyEntries);
                    if (tempArray3 != null && tempArray3.Any(o => o == item.Code))
                    {
                        model.GHS_StoreDes_String += item.Description + "\r\n";
                    }
                }
                #endregion
            }
        }
Esempio n. 7
0
 public SpecificationView(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator) : base(container, regionManager, eventAggregator)
 {
     InitializeComponent();
     _viewModel       = container.Resolve <SpecificationViewModel>();
     this.DataContext = _viewModel;
 }
Esempio n. 8
0
        public async Task UpdateSpecificationFrom(SpecificationViewModel viewModel)
        {
            var specification = _mapper.Map <SpecificationViewModel, Specification>(viewModel);

            await _specificationService.UpdateSpecificationAsync(specification);
        }
        public DataSourceResponse <ProductDetailViewModel> Read(DataSourceRequest request)
        {
            var responseData = this.DbContext.ProductDetails.Select(d => d);

            if (request.ServerFiltering != null)
            {
                ServerFilterInfo filterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "ProductId").SingleOrDefault();
                int productId = Convert.ToInt32(filterInfo.Value);
                responseData = responseData.Where(d => d.ProductId == productId);
            }

            var response = new DataSourceResponse <ProductDetailViewModel> {
                TotalRowCount = responseData.Count()
            };

            if (request.ServerPaging != null)
            {
                int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0);
                responseData = responseData.OrderBy(d => d.ProductDetailId).Skip(skip).Take(request.ServerPaging.PageSize);
            }

            var collection = responseData.Select(d => new
            {
                ProductDetailId = d.ProductDetailId,
                ProductId       = d.ProductId,
                Price           = d.Price,
                SafeStock       = d.SafeStock,
                FirstSpecificationProductCategoryName = d.FirstSpecification.ProductCategory.Name,
                FirstSpecificationProductCategoryProductCategoryId = d.FirstSpecification.ProductCategory.ProductCategoryId,
                FirstSpecificationName = d.FirstSpecification.Name,
                FirstSpecificationProductSpecificationId = d.FirstSpecification.ProductSpecificationId,
                FirstSpecificationProductCategoryId      = d.FirstSpecification.ProductCategoryId,
                SecondSpecificationId = d.SecondSpecificationId,
                SecondSpecificationProductCategoryName = d.SecondSpecification.ProductCategory.Name,
                SecondSpecificationProductCategoryProductCategoryId = d.SecondSpecification.ProductCategory.ProductCategoryId,
                SecondSpecificationName = d.SecondSpecification.Name,
                SecondSpecificationProductSpecificationId = d.SecondSpecification.ProductSpecificationId,
                SecondSpecificationProductCategoryId      = d.SecondSpecification.ProductCategoryId
            }).ToList();

            foreach (var data in collection)
            {
                var viewModel = new ProductDetailViewModel
                {
                    ProductDetailId = data.ProductDetailId,
                    ProductId       = data.ProductId,
                    Price           = data.Price,
                    SafeStock       = data.SafeStock
                };

                var firstCategory = new SelectListItem
                {
                    Text  = data.FirstSpecificationProductCategoryName,
                    Value = data.FirstSpecificationProductCategoryProductCategoryId.ToString()
                };
                viewModel.FirstCategory = firstCategory;

                var firstSpecification = new FirstSpecificationViewModel
                {
                    Text   = data.FirstSpecificationName,
                    Value  = data.FirstSpecificationProductSpecificationId,
                    Parent = data.FirstSpecificationProductCategoryId
                };
                viewModel.FirstSpecification = firstSpecification;

                if (data.SecondSpecificationId.HasValue)
                {
                    var secondCategory = new SelectListItem
                    {
                        Text  = data.SecondSpecificationProductCategoryName,
                        Value = data.SecondSpecificationProductCategoryProductCategoryId.ToString()
                    };
                    viewModel.SecondCategory = secondCategory;

                    var secondSpecification = new SpecificationViewModel
                    {
                        Text   = data.SecondSpecificationName,
                        Value  = data.SecondSpecificationProductSpecificationId,
                        Parent = data.SecondSpecificationProductCategoryId
                    };
                    viewModel.SecondSpecification = secondSpecification;
                }

                response.DataCollection.Add(viewModel);
            }

            return(response);
        }
        public async Task PoliciesPageModel_OnGet_WhenPoliciesAreRequestedForASpecification_ThenResultIsReturned()
        {
            // Arrange
            ISpecsApiClient    specsApiClient    = CreateSpecsApiClient();
            IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient();

            PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient);

            string specificationId = "spec123";

            Specification specification = new Specification()
            {
                Id             = specificationId,
                Name           = "Test Specification",
                FundingPeriod  = new Reference("1617", "2016/2017"),
                Description    = "Test Description",
                FundingStreams = new List <FundingStream>()
                {
                    new FundingStream("fs1", "Funding Stream Name"),
                },
                Policies = new List <Policy>()
                {
                    new Policy()
                    {
                        Id           = "pol1",
                        Name         = "Policy 1",
                        Description  = "Policy 1 Description",
                        Calculations = new List <Calculation>()
                        {
                            new Calculation()
                            {
                                Id             = "calc1",
                                Name           = "Calculation 1",
                                Description    = "Calculation with allocation line",
                                AllocationLine = new Reference("al1", "Allocation Line 1"),
                            },
                            new Calculation()
                            {
                                Id             = "calc2",
                                Name           = "Calculation Two",
                                Description    = "Calculation without allocation line",
                                AllocationLine = null
                            },
                        },
                        SubPolicies = new List <Policy>(),
                    },
                }
            };

            specsApiClient.GetSpecification(Arg.Any <string>())
            .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification));

            datasetsApiClient
            .GetAssignedDatasetSchemasForSpecification(specificationId)
            .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>()));

            // Act
            IActionResult result = await policiesModel.OnGet(specificationId, null, null);

            // Assert
            result.Should().BeOfType <PageResult>();

            SpecificationViewModel expectedResult = new SpecificationViewModel()
            {
                Id             = specificationId,
                Name           = "Test Specification",
                FundingPeriod  = new ReferenceViewModel("1617", "2016/2017"),
                Description    = "Test Description",
                FundingStreams = new List <ReferenceViewModel>()
                {
                    new ReferenceViewModel("fs1", "Funding Stream Name"),
                },
                Policies = new List <PolicyViewModel>()
                {
                    new PolicyViewModel()
                    {
                        Id           = "pol1",
                        Name         = "Policy 1",
                        Description  = "Policy 1 Description",
                        Calculations = new List <CalculationViewModel>()
                        {
                            new CalculationViewModel()
                            {
                                Id             = "calc1",
                                Name           = "Calculation 1",
                                Description    = "Calculation with allocation line",
                                AllocationLine = new ReferenceViewModel("al1", "Allocation Line 1"),
                            },
                            new CalculationViewModel()
                            {
                                Id             = "calc2",
                                Name           = "Calculation Two",
                                Description    = "Calculation without allocation line",
                                AllocationLine = null
                            },
                        },
                        SubPolicies = new List <PolicyViewModel>(),
                    },
                }
            };

            policiesModel.Specification.Should().BeEquivalentTo(expectedResult, o => o.RespectingRuntimeTypes().WithAutoConversion().WithTracing());
        }