예제 #1
0
        public ActionResult Create([Bind(Exclude = "ID")] ComponentViewModel componentViewModel)
        {
            if (!ModelState.IsValid)
            {
                TempData["ModelIsNotValid"] = "Wystąpił błąd w formularzu, spróbuj ponownie.";
                return(RedirectToAction("Index"));
            }
            var result = _mapper.Map <ComponentViewModel, Component>(componentViewModel);

            _repository.Insert(result);
            _repository.Save();
            return(RedirectToAction("Index"));
        }
        public void CreateInitialReportShell(int reportId, CoordinatePartsModel coordinatePart)
        {
            // check dbo.component.name on coordinatePart.Name
            // if it exists, return the id
            // else create, return the id
            var component   = _componentRepository.SelectByName(coordinatePart.Name.Trim());
            var componentId = component.Id;

            if (componentId == 0)
            {
                componentId = _componentRepository.Insert(new ComponentModel()
                {
                    Name = coordinatePart.Name.Trim()
                });
            }

            // check dbo.oss_index.component_id
            // if it exists, check `expire_date`
            //    - if older than 30 days, call remote api
            //    - insert results if any to dbo.oss_index_vulnerabilities
            //    - update `expire_date` = NOW
            // else
            //    - create with `expire_date` = NOW
            //    - call remote api
            //    - insert results if any to dbo.oss_index_vulnerabilities
            var ossIndex   = _ossIndexRepository.SelectByComponentId(componentId);
            var ossIndexId = ossIndex.Id;

            if (ossIndexId == 0)
            {
                ossIndex = new OssIndexModel()
                {
                    ComponentId    = componentId,
                    ExpireDate     = DateTime.Now.AddMonths(1),
                    HttpStatus     = (int)HttpStatusCode.Processing,
                    HttpStatusDate = DateTime.Now
                };

                ossIndexId = _ossIndexRepository.Insert(ossIndex);
                ossIndex   = _ossIndexRepository.Select(ossIndexId);
            }

            /* TODO
             *
             * 1. this is always zero as we cannot pass things like `1.4.0` as a decimal, consider deprecating `[vulnuscloud].[dbo].[oss_index].[version]` as this data is already in `[vulnuscloud].[dbo].[oss_index].[coordinates]`
             * 2. [vulnuscloud].[dbo].[oss_index].[coordinates] should be normalized:
             *      `pkg:Nuget/[email protected]`
             *      > pkg: is known, comes from `_coordinatesService`
             *      > Nuget/ should rather be stored as `[vulnuscloud].[dbo].[oss_index].[package_type_id]` - then this links to PackageTypeRepository
             *      > BeITMemcached@ can be read from [vulnuscloud].[dbo].[component].[id] = [vulnuscloud].[dbo].[oss_index].[component_id]
             *      > 1.4.0 could then be stored as [vulnuscloud].[dbo].[oss_index].[version]
             *
             *      [vulnuscloud].[dbo].[oss_index].[coordinates] could then be generated when needed.
             */

            if (decimal.TryParse(coordinatePart.Version, out decimal coordinatePartVersion))
            {
                ossIndex.Version = coordinatePartVersion;
            }

            ossIndex.Coordinates = _coordinatesService.GetCoordinates(coordinatePart);
            _ossIndexRepository.Update(ossIndex);

            _reportLinesRepository.Insert(new ReportLinesModel()
            {
                OssIndexId = ossIndexId,
                ReportId   = reportId
            });
        }