Beispiel #1
0
        /// <summary>
        /// 检验项目组合维护
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public LabItemSetDto AddOrUpdateLabItemSet(LabItemSetDto source)
        {
            var isAddNew = string.IsNullOrEmpty(source.Id);

            if (isAddNew)
            {
                source.Id = Guid.NewGuid().ToString();
                var entity = Mapper.Map <LabItemSetDto, LabItemSet>(source);
                _dbContext.Set <LabItemSet>().Add(entity);

                if (source.LabItems != null && source.LabItems.Count > 0)
                {
                    foreach (var detail in source.LabItems)
                    {
                        var detailEntity = new LabItemSetDetail();
                        detailEntity.Id    = Guid.NewGuid().ToString();
                        detailEntity.SetId = source.Id;
                        detailEntity.LmId  = detail.Id;
                        _dbContext.Set <LabItemSetDetail>().Add(detailEntity);
                    }
                }
            }
            else
            {
                var target = _dbContext.Set <LabItemSet>().Where(s => s.Id == source.Id).FirstOrDefault();
                if (target == null)
                {
                    CommonFunc.ThrowExceptionIfRecordNotExists(EntityNames.LabItemSet, source.Id, OperateType.Update, _logger);
                }

                else if (!Enumerable.SequenceEqual(source.Version, target.Version))
                {
                    var modifiedUser = GetEmployeeDetail(target.LastUpdateUserId);
                    CommonFunc.ThrowExceptionIfRecordHasBeenModified(EntityNames.LabItemSet, source.Id, modifiedUser.EmName, target.LastUpdateTime, OperateType.Update, _logger);
                }
                Mapper.Map(source, target);

                var exists = _dbContext.Set <LabItemSetDetail>().Where(s => s.SetId == source.Id).ToList();
                _dbContext.Set <LabItemSetDetail>().RemoveRange(exists);

                foreach (var detail in source.LabItems)
                {
                    var detailEntity = new LabItemSetDetail();
                    detailEntity.Id    = Guid.NewGuid().ToString();
                    detailEntity.SetId = source.Id;
                    detailEntity.LmId  = detail.Id;
                    _dbContext.Set <LabItemSetDetail>().Add(detailEntity);
                }
            }
            _dbContext.SaveChanges();
            return(GetLabItemSetDetail(source.Id));
        }
Beispiel #2
0
        /// <summary>
        /// 删除检验项目组合
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public bool DeleteLabItemSet(LabItemSetDto source)
        {
            var target = _dbContext.Set <LabItemSet>().Where(s => s.Id == source.Id).FirstOrDefault();

            if (target == null)
            {
                CommonFunc.ThrowExceptionIfRecordNotExists(EntityNames.LabItemSet, source.Id, OperateType.Delete, _logger);
            }

            else if (!Enumerable.SequenceEqual(source.Version, target.Version))
            {
                var modifiedUser = GetEmployeeDetail(target.LastUpdateUserId);
                CommonFunc.ThrowExceptionIfRecordHasBeenModified(EntityNames.LabItemSet, source.Id, modifiedUser.EmName, target.LastUpdateTime, OperateType.Delete, _logger);
            }
            _dbContext.Set <LabItemSet>().Remove(target);

            var details = _dbContext.Set <LabItemSetDetail>().Where(s => s.SetId == source.Id).ToList();

            _dbContext.Set <LabItemSetDetail>().RemoveRange(details);

            var affected = _dbContext.SaveChanges();

            return(affected > 1);
        }
Beispiel #3
0
        public bool DeleteLabItemSet(LabItemSetDto source)
        {
            var result = _systemService.DeleteLabItemSet(source);

            return(result);
        }
Beispiel #4
0
        public LabItemSetDto AddOrUpdateLabItemSet(LabItemSetDto source)
        {
            var result = _systemService.AddOrUpdateLabItemSet(source);

            return(result);
        }