Esempio n. 1
0
        public GL_LineDTO AddOrUpdateLine(dynamic values)
        {
            GL_LineDTO dto          = JsonConvert.DeserializeObject <GL_LineDTO>(values.ToString());
            string     errorMessage = string.Empty;

            dto = _goldenLineService.AddOrUpdateLine(dto, out errorMessage);
            if (string.IsNullOrEmpty(errorMessage))
            {
                return(dto);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        // Add or update line entity
        public GL_LineDTO AddOrUpdateLine(GL_LineDTO dto, out string errorMessage)
        {
            errorMessage = string.Empty;
            GL_Line entity = AutoMapper.Mapper.Map <GL_Line>(dto);

            try
            {
                GL_Line entityContext;
                if (dto.LineID == 0)
                {
                    //新增
                    //新增Line
                    entityContext = _lineRepository.Add(entity);
                    //新增负责人
                    if (dto.GL_LineShiftResposibleUserList != null)
                    {
                        //User_UID 不为0才是有效的责任人
                        var responsibleUserDtoList = dto.GL_LineShiftResposibleUserList.Where(x => x.User_UID != 0).ToList();
                        if (responsibleUserDtoList.Count > 0)
                        {
                            var responsibleUserList = AutoMapper.Mapper.Map <List <GL_LineShiftResposibleUser> >(responsibleUserDtoList);
                            foreach (var item in responsibleUserList)
                            {
                                item.LineID = entityContext.LineID;
                            }
                            _lineShiftResposibleUserRepository.AddList(responsibleUserList);
                        }
                    }

                    _unitOfWork.Commit();
                }
                else
                {
                    //编辑
                    entityContext            = _lineRepository.GetById(entity.LineID);
                    entityContext.CustomerID = entity.CustomerID;
                    entityContext.CycleTime  = entity.CycleTime;
                    //entityContext.ProjectName = entity.ProjectName;
                    //entityContext.MESProjectName = entity.MESProjectName ?? "";
                    entityContext.Plant_Organization_UID    = entity.Plant_Organization_UID;
                    entityContext.BG_Organization_UID       = entity.BG_Organization_UID;
                    entityContext.FunPlant_Organization_UID = entity.FunPlant_Organization_UID;
                    entityContext.Phase         = entity.Phase;
                    entityContext.LineName      = entity.LineName;
                    entityContext.MESLineName   = entity.MESLineName ?? "";
                    entityContext.Modified_UID  = entity.Modified_UID;
                    entityContext.Modified_Date = entity.Modified_Date;
                    entityContext.Seq           = entity.Seq;
                    entityContext.IsEnabled     = entity.IsEnabled;
                    _lineRepository.Update(entityContext);

                    //更新负责人
                    var responsibleUserList_new = new List <GL_LineShiftResposibleUser>();
                    if (dto.GL_LineShiftResposibleUserList != null)
                    {
                        responsibleUserList_new = AutoMapper.Mapper.Map <List <GL_LineShiftResposibleUser> >(dto.GL_LineShiftResposibleUserList);
                        foreach (var item in responsibleUserList_new)
                        {
                            item.LineID = entityContext.LineID;
                            //从数据库找到对应的数据
                            var responsibleOld = _lineShiftResposibleUserRepository.GetFirstOrDefault(x => x.LineID == item.LineID && x.ShiftTimeID == item.ShiftTimeID);
                            if (responsibleOld == null)
                            {
                                if (item.User_UID != 0)
                                {
                                    //没有的,新增
                                    var responsibleNew = AutoMapper.Mapper.Map <GL_LineShiftResposibleUser>(item);
                                    _lineShiftResposibleUserRepository.Add(responsibleNew);
                                }
                            }
                            else
                            {
                                //删除
                                if (item.User_UID == 0)
                                {
                                    _lineShiftResposibleUserRepository.Delete(responsibleOld);
                                }
                                else
                                {
                                    if (item.User_UID != responsibleOld.User_UID)
                                    {
                                        responsibleOld.User_UID = item.User_UID;
                                        _lineShiftResposibleUserRepository.Update(responsibleOld);
                                    }
                                }
                            }
                        }
                    }
                    //var responsibleUserList_old = entityContext.GL_LineShiftResposibleUser.ToList();
                    ////删除负责人
                    //responsibleUserList_old.Where(x=>)

                    _unitOfWork.Commit();
                }

                var returnDto = AutoMapper.Mapper.Map <GL_LineDTO>(entityContext);
                return(returnDto);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(null);
            }
        }