Esempio n. 1
0
        internal UserInfo GetUserInfo(IDataContext context, Worker user)
        {
//            Guid? orgUnitTypeId = null;
//            string orgUnitTypeName = "";
//            string positionName = "";

            var positionId = user.OrgPosition_Id;

/*
 *          if (!user.Org_PositionsReference.IsLoaded) user.Org_PositionsReference.Load();
 *          if (user.Org_Positions != null)
 *          {
 *              positionName = user.Org_Positions.Full_Name;
 *              if (user.Org_Positions.Parent_Id != null)
 *              {
 *                  var orgUnit = context.Defs<Org_Unit>()
 *                      .FirstOrDefault(ou => ou.Id == user.Org_Positions.Parent_Id);
 *
 *                  if (orgUnit != null)
 *                  {
 *                      orgUnitTypeId = user.Org_Positions.Parent_Id;
 *                      orgUnitTypeName = orgUnit.Full_Name;
 *                  }
 *              }
 * //                if (!user.Org_Positions.ParentReference.IsLoaded) user.Org_Positions.ParentReference.Load();
 * //                if (user.Org_Positions.Parent is Org_Unit)
 * //                {
 * //                    orgUnitTypeId = user.Org_Positions.Parent_Id;
 * //                    orgUnitTypeName = user.Org_Positions.Parent.Full_Name;
 * //                }
 *          }
 */

            var orgPosition = positionId != null?OrgRepo.FindOrgPosition((Guid)positionId) : null;

            var orgUnitType = orgPosition != null && orgPosition.OrgTypeId != null
                                  ? OrgRepo.FindOrgType((Guid)orgPosition.OrgTypeId)
                                  : null;

            /*Organization organization = null;
             *
             * if (user.Parent_Id != null)
             * {
             *  organization = context.Defs<Organization>()
             *      .FirstOrDefault(o => o.Id == user.Parent_Id);
             * }*/
            var orgInfo = user.Parent_Id != null?OrgRepo.Find((Guid)user.Parent_Id) : null;

            return(new UserInfo
            {
                Id = user.Id,
                UserName = user.User_Name,
                FirstName = user.First_Name ?? "",
                LastName = user.Last_Name ?? "",
                Position = orgPosition,
                PositionId = positionId,
                PositionName = orgPosition != null ? orgPosition.Name : String.Empty,
                OrgUnitTypeId = orgPosition != null ? orgPosition.OrgTypeId : null,
                OrgUnitTypeName = orgUnitType != null ? orgUnitType.Name : String.Empty,
                Organization = orgInfo,
                OrganizationId = orgInfo != null ? orgInfo.Id : (Guid?)null,
                OrganizationTypeId = orgInfo != null ? orgInfo.TypeId : null,
                OrganizationName = orgInfo != null ? orgInfo.Name : String.Empty,
                OrganizationCode = orgInfo != null ? orgInfo.Code : String.Empty,
                LanguageId = user.Language_Id ?? 0
            });
        }