예제 #1
0
        public void ResetPassword(ResetPasswordRequestModel model)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                OrgComm.Data.Models.Member member = dbc.Members.SingleOrDefault(r => (!r.DelFlag) && r.Email.Equals(model.Email));

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

                string password = System.Web.Security.Membership.GeneratePassword(8, 0);

                member.Salt         = SecurityHelper.GenerateBase64SaltString();
                member.PasswordHash = this.GenerateHash(member.Salt, password);

                member.UpdatedDate = DateTime.Now;

                dbc.SaveChanges();

                if (AppConfigs.MailSendMail)
                {
                    System.Collections.Specialized.ListDictionary listReplacement = new System.Collections.Specialized.ListDictionary();

                    listReplacement.Add("{password}", password);

                    MailSender.Send(AppConfigs.MailFrom, member.Email, "Reset password", listReplacement, AppConfigs.MailTemplateResetPassword);
                }
            }
        }
예제 #2
0
        public byte[] GetMemberPhoto(PhotoRequestModel model)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                var qry = dbc.Members.AsQueryable();
                OrgComm.Data.Models.Member member = null;

                if (model.Id.HasValue)
                {
                    member = qry.Where(r => (!r.DelFlag) && (r.Id == model.Id.Value)).FirstOrDefault();
                }
                else
                {
                    throw new OrgException("Invalid id");
                }

                if (member == null)
                {
                    throw new OrgException("Member not found");
                }
                else
                {
                    if (member.Photo == null)
                    {
                        throw new OrgException("Photo not found");
                    }

                    return(member.Photo);
                }
            }
        }
예제 #3
0
        public void ChangePassword(int memberId, ChangePasswordRequestModel model)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                OrgComm.Data.Models.Member member = dbc.Members.SingleOrDefault(r => (!r.DelFlag) && r.Id.Equals(memberId));

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

                if (!member.PasswordHash.Equals(GenerateHash(member.Salt, model.CurrentPassword)))
                {
                    throw new OrgException("Incorrect password");
                }

                string password = model.NewPassword;

                member.Salt         = SecurityHelper.GenerateBase64SaltString();
                member.PasswordHash = this.GenerateHash(member.Salt, password);

                member.UpdatedDate = DateTime.Now;

                dbc.SaveChanges();
            }
        }
예제 #4
0
        public MemberModel Activate(ActivateRequestModel model)
        {
            OrgComm.Data.Models.Member member = null;

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                member = dbc.Members.SingleOrDefault(r => (!r.DelFlag) && r.Id.Equals(model.MemberId));

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

                if (member.MemberStatus != (int)OrgComm.Data.Models.Member.StatusType.New)
                {
                    throw new OrgException(1, "Invalid activation key");
                }

                if (!member.ActivationKey.Equals(model.ActivationKey))
                {
                    throw new OrgException(2, "Invalid activation key");
                }

                member.MemberStatus = (int)OrgComm.Data.Models.Member.StatusType.Activated;

                if (!model.DeviceOSId.HasValue || String.IsNullOrWhiteSpace(model.DeviceToken))
                {
                    throw new OrgException("Invalid device token");
                }

                this.RegisterDevice(member.Id, new DeviceTokenRequestModel
                {
                    OSId  = model.DeviceOSId.Value,
                    Token = model.DeviceToken
                });

                dbc.SaveChanges();
            }

            return(new MemberModel
            {
                Id = member.Id,
                FacebookId = member.FacebookId,
                Email = member.Email,
                FirstName = member.FirstName,
                LastName = member.LastName,
                NickName = member.Nickname,
                DisplayName = member.DisplayName,
                Gender = member.Gender,
                Company = member.Company.Name,
                Department = member.Department.Name,
                Position = member.Position.Name,
                EmployeeId = member.EmployeeId,
                Phone = member.Phone,
                Photo = (member.Photo == null) ? null : MemberBL.PhotoUrlFormatString.Replace("{0}", member.Id.ToString())
            });
        }
예제 #5
0
        public MemberModel SignInWithFacebookId(SignInWithFacebookRequestModel model)
        {
            OrgComm.Data.Models.Member member = null;

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                member = dbc.Members.FirstOrDefault(r => (!r.DelFlag) && (r.FacebookId.Equals(model.FacebookId)));

                if (member == null)
                {
                    return(null);
                }

                if (!model.DeviceOSId.HasValue || String.IsNullOrWhiteSpace(model.DeviceToken))
                {
                    throw new OrgException("Invalid device token");
                }

                this.RegisterDevice(member.Id, new DeviceTokenRequestModel
                {
                    OSId  = model.DeviceOSId.Value,
                    Token = model.DeviceToken
                });
            }

            return(new MemberModel
            {
                Id = member.Id,
                FacebookId = member.FacebookId,
                Email = member.Email,
                FirstName = member.FirstName,
                LastName = member.LastName,
                NickName = member.Nickname,
                DisplayName = member.DisplayName,
                Gender = member.Gender,
                Company = member.Company.Name,
                Department = member.Department.Name,
                Position = member.Position.Name,
                EmployeeId = member.EmployeeId,
                Phone = member.Phone,
                Photo = (member.Photo == null) ? null : MemberBL.PhotoUrlFormatString.Replace("{0}", member.Id.ToString())
            });
        }
예제 #6
0
        public void SetFavouriteFriend(int memberId, FriendFavouriteRequestModel model)
        {
            if (!model.FriendMemberId.HasValue)
            {
                throw new OrgException(1, "Invalid friend Id");
            }

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

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

                var friend = dbc.Friends.SingleOrDefault(r => r.MemberId.Equals(member.Id) && r.FriendMemberId.Equals(model.FriendMemberId.Value));

                if (friend == null) //Not in friend list
                {
                    if (!dbc.Members.Any(r => r.Id.Equals(model.FriendMemberId.Value)))
                    {
                        throw new OrgException(1, "Invalid profile");
                    }

                    dbc.Friends.Add(new OrgComm.Data.Models.Friend
                    {
                        MemberId       = member.Id,
                        FriendMemberId = model.FriendMemberId.Value,
                        Status         = (int)OrgComm.Data.Models.Friend.StatusType.Active,
                        IsFavourite    = model.IsFavourite,
                        AddedDate      = DateTime.Now,
                        UpdatedDate    = null
                    });
                }
                else
                {
                    friend.IsFavourite = model.IsFavourite;
                }

                dbc.SaveChanges();
            }
        }
예제 #7
0
        public void SetFriendStatus(int memberId, int friendMemberId, OrgComm.Data.Models.Friend.StatusType type)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                OrgComm.Data.Models.Member member = dbc.Members.FirstOrDefault(r => r.Id.Equals(memberId) && (!r.DelFlag));

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

                if (!dbc.Members.Any(r => r.Id.Equals(friendMemberId) && (!r.DelFlag)))
                {
                    throw new OrgException(1, "Invalid friend profile");
                }

                var friend = dbc.Friends.SingleOrDefault(r => r.MemberId.Equals(member.Id) && r.FriendMemberId.Equals(friendMemberId));

                if (friend == null) //Not in friend list
                {
                    dbc.Friends.Add(new OrgComm.Data.Models.Friend
                    {
                        MemberId       = member.Id,
                        FriendMemberId = friendMemberId,
                        Status         = (int)type,
                        IsFavourite    = false,
                        AddedDate      = DateTime.Now,
                        UpdatedDate    = null
                    });
                }
                else
                {
                    friend.Status      = (int)type;
                    friend.UpdatedDate = DateTime.Now;
                }

                dbc.SaveChanges();
            }
        }
예제 #8
0
        public void RemoveMember(int memberId, DeleteAccountRequestModel model)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                OrgComm.Data.Models.Member member = dbc.Members.SingleOrDefault(r => (!r.DelFlag) && r.Id.Equals(memberId));

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

                if (!member.PasswordHash.Equals(GenerateHash(member.Salt, model.Password)))
                {
                    throw new OrgException("Incorrect password");
                }

                member.DelFlag = true;

                var tokens = dbc.Tokens.Where(r => r.MemberId.Equals(memberId));
                if (tokens.Count() > 0)
                {
                    dbc.Tokens.RemoveRange(tokens);
                }

                var devices = dbc.Devices.Where(r => r.MemberId.Equals(memberId));
                if (devices.Count() > 0)
                {
                    dbc.Devices.RemoveRange(devices);
                }

                new FriendBL().RemoveFriendByMemberId(member.Id);
                new GroupBL().LeaveAllGroupsByMemberId(member.Id);
                new UploadBL().RemoveFilesByMemberId(member.Id);
                new NoteBL().RemoveNoteByMemberId(member.Id);

                dbc.SaveChanges();
            }
        }
예제 #9
0
        public MemberModel UpdateProfile(int memberId, UpdateMemberModel model)
        {
            OrgComm.Data.Models.Member member = null;

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                member = dbc.Members.SingleOrDefault(r => (!r.DelFlag) && r.Id.Equals(memberId));

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

                if (model.Photo == null)
                {
                    member.Photo = null;
                }
                else
                {
                    byte[] photo = model.Photo.Buffer;

                    using (System.IO.MemoryStream msReader = new System.IO.MemoryStream(photo))
                    {
                        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.MemberPhotoWidthMax;
                            height = AppConfigs.MemberPhotoHeightMax;

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

                if (!String.IsNullOrWhiteSpace(model.Email))
                {
                    Validator validator = new Validator();
                    string    email     = model.Email.Trim();

                    if (!validator.IsValidEmail(email))
                    {
                        throw new OrgException("Invalid e-mail");
                    }

                    if (dbc.Members.Any(r => (r.Id != memberId) && (r.Email.Equals(email))))
                    {
                        throw new OrgException("Duplicate e-mail");
                    }

                    member.Email = email;
                }

                if (!String.IsNullOrWhiteSpace(model.FirstName))
                {
                    member.FirstName = model.FirstName;
                }

                if (!String.IsNullOrWhiteSpace(model.LastName))
                {
                    member.LastName = model.LastName;
                }

                if (!String.IsNullOrWhiteSpace(model.DisplayName))
                {
                    member.DisplayName = model.DisplayName;
                }

                if (!String.IsNullOrWhiteSpace(model.Gender))
                {
                    member.Gender = model.Gender;
                }

                if (!String.IsNullOrWhiteSpace(model.Phone))
                {
                    if (dbc.Members.Any(r => (r.Id != memberId) && (r.Phone.Equals(model.Phone))))
                    {
                        throw new OrgException("Duplicate phone no.");
                    }

                    member.Phone = model.Phone;
                }

                member.UpdatedDate = DateTime.Now;

                dbc.SaveChanges();
            }

            return(new MemberModel
            {
                Id = member.Id,
                FacebookId = member.FacebookId,
                Email = member.Email,
                FirstName = member.FirstName,
                LastName = member.LastName,
                NickName = member.Nickname,
                DisplayName = member.DisplayName,
                Gender = member.Gender,
                Company = member.Company.Name,
                Department = member.Department.Name,
                Position = member.Position.Name,
                EmployeeId = member.EmployeeId,
                Phone = member.Phone,
                Photo = (member.Photo == null) ? null : MemberBL.PhotoUrlFormatString.Replace("{0}", member.Id.ToString())
            });
        }
예제 #10
0
        public MemberModel Register(RegisterRequestModel model, out string activationKey)
        {
            OrgComm.Data.Models.Member member = new OrgComm.Data.Models.Member
            {
                FacebookId     = model.FacebookId,
                MemberStatus   = (int)OrgComm.Data.Models.Member.StatusType.New,
                FirstName      = model.FirstName,
                LastName       = model.LastName,
                Nickname       = model.NickName,
                Gender         = model.Gender,
                EmployeeId     = model.EmployeeId,
                RegisteredDate = DateTime.Now,
            };

            if (!String.IsNullOrWhiteSpace(model.Email))
            {
                Validator validator = new Validator();
                string    email     = model.Email.Trim();

                if (!validator.IsValidEmail(email))
                {
                    throw new OrgException("Invalid e-mail");
                }

                member.Email = email;
            }

            if (!model.CompanyId.HasValue)
            {
                throw new OrgException("Invalid company");
            }

            if (!model.DepartmentId.HasValue)
            {
                throw new OrgException("Invalid department");
            }

            if (!model.PositionId.HasValue)
            {
                throw new OrgException("Invalid position");
            }

            if (!String.IsNullOrWhiteSpace(model.Phone))
            {
                string[] groups = model.Phone.Split(new[] { '-', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                member.Phone = String.Join("", groups);
            }

            if (model.Photo != null)
            {
                byte[] photo = model.Photo.Buffer;

                using (System.IO.MemoryStream msReader = new System.IO.MemoryStream(photo))
                {
                    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.MemberPhotoWidthMax;
                        height = AppConfigs.MemberPhotoHeightMax;

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

            member.Salt         = SecurityHelper.GenerateBase64SaltString();
            member.PasswordHash = this.GenerateHash(member.Salt, model.Password);

            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                if (!String.IsNullOrWhiteSpace(member.FacebookId) && dbc.Members.Any(r => ((!r.DelFlag) && r.FacebookId.Equals(member.FacebookId))))
                {
                    throw new OrgException("Duplicate FacebookId");
                }

                if (!string.IsNullOrWhiteSpace(model.Email))
                {
                    if (dbc.Members.Any(r => ((!r.DelFlag) && r.Email.Equals(model.Email))))
                    {
                        throw new OrgException("Duplicate e-mail");
                    }
                }

                if (!string.IsNullOrWhiteSpace(model.Phone))
                {
                    if (dbc.Members.Any(r => ((!r.DelFlag) && r.Phone.Equals(model.Phone))))
                    {
                        throw new OrgException("Duplicate phone no.");
                    }
                }

                var company = dbc.Company.FirstOrDefault(r => r.Id.Equals(model.CompanyId.Value));
                if (company == null)
                {
                    throw new OrgException("Invalid company");
                }

                member.Company = company;

                var department = dbc.Department.FirstOrDefault(r => r.Id.Equals(model.DepartmentId.Value));
                if (department == null)
                {
                    throw new OrgException("Invalid department");
                }

                member.Department = department;

                var position = dbc.Position.FirstOrDefault(r => r.Id.Equals(model.PositionId.Value));
                if (position == null)
                {
                    throw new OrgException("Invalid position");
                }

                member.Position = position;

                member.ActivationKey = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(System.Web.Security.Membership.GeneratePassword(6, 0)));

                dbc.Members.Add(member);

                dbc.SaveChanges();

                activationKey = member.ActivationKey;

                if (AppConfigs.MailSendMail)
                {
                    System.Collections.Specialized.ListDictionary listReplacement = new System.Collections.Specialized.ListDictionary();

                    listReplacement.Add("{id}", member.Id.ToString());
                    listReplacement.Add("{activationkey}", member.ActivationKey);

                    MailSender.Send(AppConfigs.MailFrom, member.Email, "Activate account", listReplacement, AppConfigs.MailTemplateActivate);
                }
            }

            return(new MemberModel
            {
                Id = member.Id,
                FacebookId = member.FacebookId,
                Email = member.Email,
                FirstName = member.FirstName,
                LastName = member.LastName,
                NickName = member.Nickname,
                DisplayName = member.DisplayName,
                Gender = member.Gender,
                Company = member.Company.Name,
                Department = member.Department.Name,
                Position = member.Position.Name,
                EmployeeId = member.EmployeeId,
                Phone = member.Phone,
                Photo = (member.Photo == null) ? null : MemberBL.PhotoUrlFormatString.Replace("{0}", member.Id.ToString())
            });
        }
예제 #11
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);
        }