public int AddPerson(TEntity p)
 {
     try
     {
         var  dbP = p.ToDbModel();
         bool r   = db.Personnels.Add(dbP);
         if (r == false)
         {
             return(-1);
         }
         else
         {
             if (p.TagId != null)//如果新增的人,设置了定位卡ID。得把关系添加到cardToPersonnel
             {
                 var s     = new PersonService(db);
                 var value = s.BindWithTag(dbP.Id, (int)p.TagId);
             }
         }
         return(dbP.Id);
     }
     catch (Exception ex)
     {
         LogEvent.Error(ex);
         return(-1);
     }
 }
        public TEntity Post(string pid, TEntity item)
        {
            item.ParentId = pid.ToInt();
            var dbItem = item.ToDbModel();
            var result = dbSet.Add(dbItem);

            return(result ? dbItem.ToTModel() : null);
        }
        public TEntity Put(TEntity item)
        {
            var dbItem = item.ToDbModel();
            var result = dbSet.Edit(dbItem);

            if (result)
            {
                if (item.TagId != null)
                {
                    BindWithTag(item.Id, (int)item.TagId);
                }
            }
            return(result ? dbItem.ToTModel() : null);
        }
 public TEntity Post(string pid, TEntity item)
 {
     try
     {
         item.ParentId = pid.ToInt();
         var dbItem = item.ToDbModel();
         var result = dbSet.Add(dbItem);
         return(result ? dbItem.ToTModel() : null);
     }
     catch (System.Exception ex)
     {
         Log.Error(tag, "Post", "Exception:" + ex);
         return(null);
     }
 }
 public TEntity Put(TEntity item)
 {
     try
     {
         var dbItem = item.ToDbModel();
         var result = dbSet.Edit(dbItem);
         if (result)
         {
             if (item.TagId != null)
             {
                 BindWithTag(item.Id, (int)item.TagId);
             }
         }
         return(result ? dbItem.ToTModel() : null);
     }
     catch (System.Exception ex)
     {
         Log.Error(tag, "Put", "Exception:" + ex);
         return(null);
     }
 }
 public List <TEntity> GetList(bool detail)
 {
     if (detail)
     {
         var list  = new List <TEntity>();
         var query = from p in dbSet.DbSet
                     join r in db.LocationCardToPersonnels.DbSet on p.Id equals r.PersonnelId
                     join tag in db.LocationCards.DbSet on r.LocationCardId equals tag.Id
                     join pos in db.LocationCardPositions.DbSet on tag.Code equals pos.Id
                     select new { Person = p, Tag = tag, Pos = pos };
         foreach (var item in query)
         {
             TEntity entity = item.Person.ToTModel();
             entity.Tag = item.Tag.ToTModel();
             entity.Pos = item.Pos.ToTModel();
             list.Add(entity);
         }
         return(list);
     }
     else
     {
         return(dbSet.DbSet.ToList().ToTModel());
     }
 }
Exemple #7
0
        public Personnel Clone()
        {
            Personnel copy = this.CloneObjectByBinary();

            return(copy);
        }
 public TEntity Put(TEntity item)
 {
     return(service.Put(item));
 }
 public TEntity Post(string pid, TEntity item)
 {
     return(service.Post(pid, item));
 }
Exemple #10
0
 public int AddPerson(TEntity p)
 {
     return(service.AddPerson(p));
 }
        public List <TEntity> GetList(bool detail, bool showAll)
        {
            try
            {
                if (detail)
                {
                    return(GetListEx(false));
                }
                else
                {
                    var list  = new List <TEntity>();
                    var list1 = dbSet.ToList();
                    var query = from p in dbSet.DbSet
                                join r in db.LocationCardToPersonnels.DbSet on p.Id equals r.PersonnelId
                                into rList
                                from r2 in rList.DefaultIfEmpty() //left join
                                join tag in db.LocationCards.DbSet on r2.LocationCardId equals tag.Id
                                into tagList
                                from tag2 in tagList.DefaultIfEmpty()
                                join pos in db.LocationCardPositions.DbSet on tag2.Code equals pos.Id
                                into posList
                                from pos2 in posList.DefaultIfEmpty() //left join
                                select new { Person = p, Tag = tag2, Pos = pos2 };

                    var pList = query.ToList();
                    foreach (var item in pList)
                    {
                        try
                        {
                            LocationCardPositionBll.SetPostionState(item.Pos);
                            TEntity p   = item.Person.ToTModel();
                            var     tag = item.Tag.ToTModel();
                            var     pos = item.Pos.ToTModel();
                            if (pos != null)
                            {
                                p.AreaId = pos.AreaId ?? 2; //要是AreaId为空就改为四会电厂区域
                            }
                            if (showAll == false)
                            {
                                if (pos == null || (pos != null && pos.IsHide))
                                {
                                    //隐藏待机的人员
                                }
                                else
                                {
                                    list.Add(p);
                                }
                            }
                            else
                            {
                                list.Add(p);
                            }

                            if (detail)
                            {
                                p.Tag = tag;
                                p.Pos = pos;
                                //tag.Pos = pos;
                            }
                        }
                        catch (Exception ex1)
                        {
                            Log.Error("PersonService.GetList Item:" + ex1);
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                Log.Error(tag, "PersonService.GetList:" + ex);
                return(null);
            }
        }