示例#1
0
        public IList <GroupModel> GetGroupsByMember(int memberId, OrgComm.Data.Models.GroupMember.JoinedStatusType?joinedType)
        {
            List <GroupModel> groupList = null;

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                groupList = (from g in dbc.Groups
                             join gm in dbc.GroupMembers on g.Id equals gm.GroupId
                             join l in dbc.Lookups on new { type = (int)OrgComm.Data.Models.Lookup.LookupType.GroupType, groupType = g.Type } equals new { type = l.TypeId, groupType = l.Value } into gl
                             from gex in gl.DefaultIfEmpty()
                             join l2 in dbc.Lookups on new { type = (int)OrgComm.Data.Models.Lookup.LookupType.GroupMemberJoinedStatus, joinedType = gm.JoinedStatus } equals new { type = l2.TypeId, joinedType = l2.Value } into gml
                             from gmex in gml.DefaultIfEmpty()
                             where gm.MemberId.Equals(memberId) && ((joinedType == null) || gm.JoinedStatus.Equals((int)joinedType.Value))
                             orderby g.Id
                             select new GroupModel
                {
                    Id = g.Id,
                    Type = g.Type,
                    TypeDescription = (gex == null) ? null : gex.Description,
                    FounderId = g.FounderId,
                    Title = g.Title,
                    SubTitle = g.SubTitle,
                    WelcomeMessage = g.WelcomeMessage,
                    Logo = (g.Logo == null) ? null : g.Id.ToString(),
                    Status = gm.JoinedStatus,
                    StatusDescription = (gmex == null) ? null : gmex.Description
                }).ToList();

                groupList.ForEach(r =>
                {
                    if (r.Logo != null)
                    {
                        r.Logo = String.Format(GroupBL.LogoUrlFormatString, r.Id);
                    }

                    r.RoomId  = ChatBL.GetChatRoomId(new int[] { r.Id }, ChatBL.ParticipationType.Group);
                    r.Members = GroupBL.GetGroupMember(dbc, r.Id);
                });
            }

            return(groupList);
        }
示例#2
0
        public GroupModel CreateGroup(int memberId, CreateGroupRequestModel model, OrgComm.Data.Models.Group.GroupType groupType)
        {
            GroupModel groupModel = null;

            OrgComm.Data.Models.Group group = new OrgComm.Data.Models.Group
            {
                FounderId      = memberId,
                Type           = (int)groupType,
                Title          = model.Title,
                SubTitle       = model.SubTitle,
                WelcomeMessage = model.WelcomeMessage,
                CreatedDate    = DateTime.Now
            };

            if (model.Logo != null)
            {
                byte[] logo = model.Logo.Buffer;

                using (System.IO.MemoryStream msReader = new System.IO.MemoryStream(logo))
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromStream(msReader))
                    {
                        string imageType = ImageHelper.GetImageFormat(img);

                        if (imageType == null)
                        {
                            throw new OrgException("Not support image type");
                        }

                        int?  width, height;
                        Image imgResize = null;

                        //Size Max constraint
                        width  = AppConfigs.GroupPhotoWidthMax;
                        height = AppConfigs.GroupPhotoHeightMax;

                        imgResize  = ImageHelper.ReSize(img, width, height, ImageHelper.ResizeMode.KeepAspectRatio);
                        group.Logo = ImageHelper.ImageToByteArray(imgResize, img.RawFormat);
                    }
                }
            }

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                if (groupType == OrgComm.Data.Models.Group.GroupType.Other)
                {
                    if (!dbc.Members.Any(r => (r.Id.Equals(group.FounderId))))
                    {
                        throw new OrgException("Invalid member");
                    }
                }
                else if (groupType == OrgComm.Data.Models.Group.GroupType.Company)
                {
                    if (!dbc.Company.Any(r => (r.Id.Equals(group.FounderId))))
                    {
                        throw new OrgException("Invalid Company");
                    }
                }

                dbc.Groups.Add(group);
                dbc.SaveChanges();

                var lookupGroupType    = dbc.Lookups.SingleOrDefault(r => (r.TypeId == (int)OrgComm.Data.Models.Lookup.LookupType.GroupType) && (r.Value == (int)groupType));
                var lookupJoinedStatus = dbc.Lookups.SingleOrDefault(r => (r.TypeId == (int)OrgComm.Data.Models.Lookup.LookupType.GroupMemberJoinedStatus) && (r.Value == (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Active));

                groupModel = new GroupModel
                {
                    Id                = group.Id,
                    FounderId         = group.FounderId,
                    Type              = group.Type,
                    TypeDescription   = (lookupGroupType == null) ? null : lookupGroupType.Description,
                    Title             = group.Title,
                    SubTitle          = group.SubTitle,
                    WelcomeMessage    = group.WelcomeMessage,
                    Logo              = (group.Logo == null) ? null : String.Format(GroupBL.LogoUrlFormatString, group.Id),
                    Status            = (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Active,
                    StatusDescription = (lookupJoinedStatus == null) ? null : lookupJoinedStatus.Description,
                    RoomId            = ChatBL.GetChatRoomId(new int[] { group.Id }, ChatBL.ParticipationType.Group),
                };

                if (groupType == OrgComm.Data.Models.Group.GroupType.Other)
                {
                    try
                    {
                        var groupmember = new OrgComm.Data.Models.GroupMember
                        {
                            GroupId      = group.Id,
                            MemberId     = group.FounderId,
                            JoinedDate   = group.CreatedDate,
                            JoinedStatus = (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Active
                        };

                        dbc.GroupMembers.Add(groupmember);

                        dbc.SaveChanges();
                    }
                    catch (System.Exception ex)
                    {
                        throw new OrgException("Cannot member to group", ex);
                    }

                    groupModel.Members = GroupBL.GetGroupMember(dbc, group.Id);
                }
            }

            return(groupModel);
        }
示例#3
0
        public IList <FriendMemberModel> GetFriends(int memberId, bool?isFavourite, OrgComm.Data.Models.Friend.StatusType?type)
        {
            List <FriendMemberModel> friendList = null;

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                OrgComm.Data.Models.Member member = dbc.Members.SingleOrDefault(r => r.Id.Equals(memberId));

                if (member == null)
                {
                    throw new OrgException(1, "Invalid profile");
                }

                var    lookup           = dbc.Lookups.SingleOrDefault(r => (r.TypeId == (int)OrgComm.Data.Models.Lookup.LookupType.FriendStatus) && (r.Value == (int)OrgComm.Data.Models.Friend.StatusType.Active));
                string friendStatusDesc = String.Empty;

                if (lookup != null)
                {
                    friendStatusDesc = lookup.Description;
                }

                var qry = from m in dbc.Members
                          join f in dbc.Friends on m.Id equals f.FriendMemberId into fm
                          from mwithf in fm.DefaultIfEmpty()
                          join l in dbc.Lookups on new { type = (int)OrgComm.Data.Models.Lookup.LookupType.FriendStatus, status = ((mwithf == null) ? (int)OrgComm.Data.Models.Friend.StatusType.Active : mwithf.Status) } equals new { type = l.TypeId, status = l.Value }
                where m.CompanyId == member.CompanyId &&        // friend must be in same company
                m.Id != member.Id &&                 // not request member
                m.DelFlag == false &&                 // not delete account
                ((type == null) || (((mwithf == null) ? (int)OrgComm.Data.Models.Friend.StatusType.Active : mwithf.Status) == (int)type.Value)) &&
                ((isFavourite == null) || (((mwithf == null) ? false : mwithf.IsFavourite) == isFavourite.Value))
                orderby m.Id
                select new FriendMemberModel
                {
                    Id                = m.Id,
                    FacebookId        = m.FacebookId,
                    Email             = m.Email,
                    FirstName         = m.FirstName,
                    LastName          = m.LastName,
                    NickName          = m.Nickname,
                    DisplayName       = m.DisplayName,
                    Gender            = m.Gender,
                    Company           = m.Company.Name,
                    Department        = m.Department.Name,
                    Position          = m.Position.Name,
                    EmployeeId        = m.EmployeeId,
                    Phone             = m.Phone,
                    Photo             = (m.Photo == null) ? null : m.Id.ToString(),
                    Status            = (mwithf == null) ? (int)OrgComm.Data.Models.Friend.StatusType.Active : mwithf.Status,
                    StatusDescription = l.Description
                };

                friendList = qry.ToList();

                string templateUrl = MemberBL.PhotoUrlFormatString;

                friendList.ForEach(r =>
                {
                    if (r.Photo != null)
                    {
                        r.Photo = string.Format(templateUrl, r.Id);
                    }

                    r.RoomId = ChatBL.GetChatRoomId(new int[] { memberId, r.Id }, ChatBL.ParticipationType.Member);
                });
            }

            return(friendList);
        }