Exemple #1
0
        public async Task <EquipmentDto> Update(EquipmentDto input)
        {
            var entity = input.MapTo <Equipment>();

            entity = await _repository.UpdateAsync(entity);

            return(entity.MapTo <EquipmentDto>());
        }
Exemple #2
0
        public async Task <EquipmentDto> Create(EquipmentDto input)
        {
            var entity = input.MapTo <Equipment>();

            var count = await _repository.CountAsync(p => p.FNumber == input.FNumber);

            if (count > 0)
            {
                throw new UserFriendlyException($"设备代码{input.FNumber}重复");
            }

            entity = await _repository.InsertAsync(entity);

            return(entity.MapTo <EquipmentDto>());
        }
        /// <summary>
        /// 加工点 设备批量添加或修改
        /// </summary>
        /// <param name="Equipmentlist"></param>
        /// <returns></returns>
        public virtual async Task ProcessEquipmentSaves(List <EquipmentDto> Equipmentlist)
        {
            var equipments = await EquipmentManager.GetAll().Include(o => o.EquipmentProcessTypes).ToListAsync();

            foreach (var EquipmentDto in Equipmentlist)
            {
                var Equipment = equipments.Where(o => o.Id == EquipmentDto.Id).SingleOrDefault();
                if (Equipment != null)
                {
                    EquipmentDto.MapTo(Equipment);
                }
                else
                {
                    Equipment = EquipmentDto.MapTo <Equipment>();
                }
                var imgpath = EquipmentDto.EquipmentPicPath;
                if (!string.IsNullOrEmpty(imgpath))
                {
                    var file = FileManager.GetAll().Where(o => o.FilePath == imgpath).FirstOrDefault();
                    if (file == null)
                    {
                        file = new File
                        {
                            TenantId = AbpSession.TenantId,
                            FileName = Equipment.EquipmentSN,
                            FilePath = imgpath,
                            FileSize = 1
                        };
                        await FileManager.InsertAsync(file);
                    }
                    else
                    {
                        Equipment.EquipmentPic = file.Id;
                    }
                }
                await EquipmentManager.SaveAsync(Equipment);

                //添加设备工艺类型
                var typeids = EquipmentDto.TypeID;
                foreach (var typeid in typeids)
                {
                    var eqType = Equipment.EquipmentProcessTypes.Where(o => o.ProcessTypeId == typeid).FirstOrDefault();
                    if (eqType == null)
                    {
                        eqType = new EquipmentProcessType
                        {
                            TenantId      = Convert.ToInt32(AbpSession.TenantId),
                            EquipmentId   = Equipment.Id,
                            ProcessTypeId = typeid
                        };
                        Equipment.EquipmentProcessTypes.Add(eqType);
                    }
                }
                //删除设备工艺类型
                foreach (var type in Equipment.EquipmentProcessTypes)
                {
                    int?eqType = typeids.Where(o => o == type.Id).FirstOrDefault();
                    if (eqType == null)
                    {
                        Equipment.EquipmentProcessTypes.Remove(type);
                    }
                }
            }
        }