コード例 #1
0
        public IHttpActionResult PostWithClinicalItem([FromBody] ProductSuiteDto value)
        {
            try
            {
                var originalEntity = ((ProductSuiteSerivce)_service)
                                     .GetDependents(value.Id).FirstOrDefault();

                // For Deleted Link records
                var deletedVersionEntities =
                    originalEntity?
                    .Versions.Where(e => !value.Versions.Select(x => x.Id).Contains(e.Id)).ToList()
                    ?? Enumerable.Empty <ProductVersion>().ToList();
                _versionSerivce.RemoveRange(deletedVersionEntities, false);

                var entity = value.ToDomain(originalEntity);

                entity.Versions
                    = value.Versions?.Select(v => v.ToDomain()).ToList();

                foreach (var version in value.Versions)
                {
                    var deletedLineEntities =
                        originalEntity?.Versions.SelectMany(x => x.Lines)
                        .Where(e =>
                               !value.Versions.SelectMany(x => x.ProductLines)
                               .Select(x => x.Id).Contains(e.Id)).ToList()
                        ?? Enumerable.Empty <ProductLine>().ToList();

                    _lineSerivce.RemoveRange(deletedLineEntities, false);

                    var lines = version.ProductLines?.Select(v => v.ToDomain()).ToList();
                    entity.Versions.ForEach(v => v.SuiteId = entity.Id);
                    entity.Versions.ForEach(x => _service.UpdateData(x));
                    entity.Versions.FirstOrDefault(x => x.Id == version.Id).Lines = lines;
                }

                entity.Versions.ForEach(v => v.SuiteId = entity.Id);
                entity.Versions.ForEach(x => _service.UpdateData(x));



                _service.Add(entity);
                return(Ok(entity.ToDto()));
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }
        }
コード例 #2
0
        //[Route("api/ProductVersion/Dependents/")]
        //public IHttpActionResult PostWithDependents([FromBody]ProductVersionDto value)
        //{
        //    try
        //    {
        //        ProductVersion entity = AddVersion(value);
        //        return Ok(entity.ToDto());
        //    }
        //    catch (Exception ex)
        //    {
        //        return InternalServerError();
        //    }
        //}

        private ProductVersion AddVersion(ProductVersionDto value)
        {
            var originalEntity = ((ProductVersionSerivce)_service).GetDependents(value.Id).FirstOrDefault();

            // For Deleted Link records
            var deletedLinesEntities =
                originalEntity?
                .Lines.Where(e => !value.ProductLines.Select(x => x.Id).Contains(e.Id)).ToList()
                ?? Enumerable.Empty <ProductLine>().ToList();

            _productLineSerivce.RemoveRange(deletedLinesEntities, false);


            var entity = value.ToDomain(originalEntity);

            entity.Lines = value.ProductLines?.Select(v => v.ToDomain(entity.Lines.FirstOrDefault(x => x.Id == v.Id))).ToList();
            entity.Lines.ForEach(v => v.VersionId = entity.Id);
            entity.Lines.ForEach(x => _service.UpdateData(x));

            _service.Add(entity);
            return(entity);
        }