示例#1
0
        public IHttpActionResult Decline(int memberId, int familyId)
        {
            using (bkContext context = new bkContext())
            {
                if (!CanEditMember(memberId))
                {
                    return(BadRequest("You do not have rights to approve this member"));
                }

                FamilyMemberAssociation fmAssociation = context.FamilyMemberAssociations.FirstOrDefault(x => x.MemberId == memberId && x.FamilyId == familyId && !x.Approved);
                if (fmAssociation == null)
                {
                    return(BadRequest("No pending approval found"));
                }

                context.FamilyMemberAssociations.Remove(fmAssociation);

                context.SaveChanges();
            }

            return(Ok());
        }
示例#2
0
        public IHttpActionResult GetLookup(int memberId)
        {
            using (bkContext context = new bkContext())
            {
                var result = (from f in context.Families
                              join fma in context.FamilyMemberAssociations.Where(x => x.MemberId == memberId) on f.FamilyID equals fma.FamilyId
                              join m in context.Members on f.HeadOfFamilyID equals m.MemberID
                              select new
                {
                    f.FamilyID,
                    m.FirstName,
                    m.LastName,
                }).Distinct().ToList();

                int defaultFamilyId = 0;
                FamilyMemberAssociation defaultAssociation = context.FamilyMemberAssociations.Where(x => x.MemberId == memberId && x.DefaultFamily).FirstOrDefault();
                if (defaultAssociation != null)
                {
                    defaultFamilyId = defaultAssociation.FamilyId;
                }

                List <FamilyLookupViewModel> response = new List <FamilyLookupViewModel>();

                foreach (var item in result)
                {
                    var temp = new FamilyLookupViewModel();

                    temp.FamilyID      = item.FamilyID;
                    temp.HeadOfFamily  = $"{item.FirstName} {item.LastName}";
                    temp.DefaultFamily = item.FamilyID == defaultFamilyId;

                    response.Add(temp);
                }

                return(Ok(response));
            }
        }
示例#3
0
        public IHttpActionResult Register(RegisterViewModel register)
        {
            if (!VerifyCaptcha(register.CaptchaResponse))
            {
                return(BadRequest("Please refresh page and try again"));
            }

            using (bkContext context = new bkContext())
            {
                if (context.Members.Any(f => f.EmailAddress == register.EmailAddress.Trim()))
                {
                    return(BadRequest("Email address already registered. Please use forgot password on login page to recover your account"));
                }

                if (context.Members.Any(f => f.Phone == register.PhoneNumber.Trim()))
                {
                    return(BadRequest("Phone number already registered. Please contact Administrator for help"));
                }

                Member member = new Member();
                member.FirstName       = register.FirstName;
                member.LastName        = register.LastName;
                member.DOB             = register.DateOfBirth;
                member.EmailAddress    = register.EmailAddress.Trim();
                member.Phone           = register.PhoneNumber;
                member.Gender          = register.Gender;
                member.MaritalStatusID = 2; //MARRIED

                string tPassword = System.Web.Security.Membership.GeneratePassword(8, 0);
                tPassword       = Regex.Replace(tPassword, @"[^a-zA-Z0-9]", m => "9");
                member.Password = tPassword;

                member.Alive     = true;
                member.Active    = true;
                member.CreatedOn = DateTime.Now;

                Family family = new Family();
                family.Address1   = register.Address1;
                family.Address2   = register.Address2;
                family.City       = register.City;
                family.District   = register.District;
                family.State      = register.State;
                family.PostalCode = register.PostalCode;
                family.Country    = register.Country;
                family.CategoryID = register.CategoryId;
                family.NukhID     = register.NukhId;
                family.Member     = member;
                family.CreatedOn  = DateTime.Now;

                FamilyMemberAssociation fmAssociation = new FamilyMemberAssociation();
                fmAssociation.Member        = member;
                fmAssociation.Family        = family;
                fmAssociation.Approved      = true;
                fmAssociation.DefaultFamily = true;
                fmAssociation.CreatedOn     = DateTime.Now;

                context.Families.Add(family);
                context.Members.Add(member);
                context.FamilyMemberAssociations.Add(fmAssociation);

                context.SaveChanges();

                string templatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/HtmlTemplates/welcome.html");
                string html         = File.ReadAllText(templatePath);

                html = html.Replace("{{name}}", $"{member.FirstName} {member.LastName}");
                html = html.Replace("{{action_url}}", $"{BaseUrl}/login/ ");
                html = html.Replace("{{username}}", member.EmailAddress);
                html = html.Replace("{{password}}", member.Password);

                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    using (SmtpClient sClient = new SmtpClient())
                    {
                        using (MailMessage mailMessage = new MailMessage("*****@*****.**", member.EmailAddress))
                        {
                            mailMessage.Body       = html;
                            mailMessage.IsBodyHtml = true;
                            mailMessage.Subject    = "Brahmkshatriya Online Portal - Welcome Letter";

                            sClient.Send(mailMessage);
                        }
                    }
                });
            }

            return(Ok());
        }
示例#4
0
        public IHttpActionResult Get(int memberId, int familyId)
        {
            using (bkContext context = new bkContext())
            {
                Member member = context.Members.Where(x => x.MemberID == memberId).FirstOrDefault();
                if (member == null)
                {
                    return(BadRequest("Your record cannot be loaded. Please try again or contact Administrator for help"));
                }

                List <FamilyMemberAssociation> fmAssociation = context.FamilyMemberAssociations.Where(x => x.FamilyId == familyId).ToList();

                MemberViewModel vm = new MemberViewModel();

                vm.MemberID        = member.MemberID;
                vm.FirstName       = member.FirstName;
                vm.LastName        = member.LastName;
                vm.NickName        = member.NickName;
                vm.Email           = member.EmailAddress;
                vm.PhoneNumber     = member.Phone;
                vm.Gender          = member.Gender;
                vm.DOB             = member.DOB;
                vm.BirthPlace      = member.BirthPlace;
                vm.Alive           = member.Alive;
                vm.DOD             = member.DOD;
                vm.DeathPlace      = member.DeathPlace;
                vm.EducationLevel  = member.EducationLevel;
                vm.EducationField  = member.EducationField;
                vm.OccupationId    = member.OccupationID;
                vm.CompanyName     = member.CompanyName;
                vm.JobTitle        = member.JobTitle;
                vm.InstagramHandle = member.InstagramHandle;
                vm.FacebookHandle  = member.FacebookHandle;
                vm.TwitterHandle   = member.TwitterHandle;
                vm.MaritalStatusId = member.MaritalStatusID;
                vm.Anniversary     = member.Anniversary;
                vm.PhotoUrl        = MemberWrapper.ProfilePhoto(member.MemberID, member.Gender, member.ModifiedOn);
                vm.ModifiedOn      = member.ModifiedOn.HasValue ? member.ModifiedOn : member.CreatedOn;
                vm.ProfileText     = member.ProfileText;

                GetMaternalFamily_Result mResult = context.GetMaternalFamily(member.MemberID).FirstOrDefault();
                if (mResult != null)
                {
                    vm.MaternalFamilyId   = mResult.MaternalFamilyID;
                    vm.MaternalFamilyName = string.Format("{0}, {1}", mResult.MaternalFamilyName, mResult.MaternalFamilyAddress);
                }

                GetPaternalFamily_Result pResult = context.GetPaternalFamily(member.MemberID, member.Gender, member.MaritalStatusID).FirstOrDefault();
                if (pResult != null)
                {
                    vm.PaternalFamilyId   = pResult.PaternalFamilyID;
                    vm.PaternalFamilyName = string.Format("{0}, {1}", pResult.PaternalFamilyName, pResult.PaternalFamilyAddress);
                }

                FamilyMemberAssociation fma = fmAssociation.FirstOrDefault(x => x.MemberId == memberId);
                if (fma != null)
                {
                    vm.RelatedMemberId = fma.RelatedId;
                    vm.RelationTypeId  = fma.RelationTypeId;
                    vm.DefaultFamily   = fma.DefaultFamily;
                }

                vm.canEdit = CanEditMember(fmAssociation, memberId);

                return(Ok(vm));
            }
        }
示例#5
0
        public IHttpActionResult AddToFamily(dynamic json)
        {
            dynamic model = JsonConvert.DeserializeObject <ExpandoObject>(json.ToString());

            int    familyId       = Convert.ToInt32(model.familyId);
            int    memberId       = Convert.ToInt32(model.memberId);
            string relationType   = (string)model.relationType;
            int?   relatedId      = (int?)model.relatedId;
            int?   relationTypeId = (int?)model.relationTypeId;


            if (!CanEditFamily(familyId))
            {
                return(BadRequest("You do not have permission to edit this family"));
            }

            using (bkContext context = new bkContext())
            {
                Member member = context.Members.Include(x => x.FamilyMemberAssociations).FirstOrDefault(x => x.MemberID == memberId);
                if (member == null)
                {
                    return(BadRequest("Member cannot be located. Please try again later"));
                }

                Member relatedMember = null;
                if (relatedId.HasValue)
                {
                    relatedMember = context.Members.Include(x => x.FamilyMemberAssociations).FirstOrDefault(x => x.MemberID == relatedId.Value);
                    if (relatedMember == null)
                    {
                        return(BadRequest("Related member cannot be located. Please try again later"));
                    }

                    if (!relatedMember.FamilyMemberAssociations.Any(x => x.FamilyId == familyId))
                    {
                        return(BadRequest("Related member is not part of the family"));
                    }
                }

                if (member.FamilyMemberAssociations.Any(x => x.FamilyId == familyId))
                {
                    return(BadRequest("Member is already a part of selected family"));
                }

                bool autoApproval = CanEditMember(memberId);

                FamilyMemberAssociation fmAssociation = new FamilyMemberAssociation();
                fmAssociation.Approved       = autoApproval;
                fmAssociation.CreatedBy      = LoggedInMemberId;
                fmAssociation.CreatedOn      = DateTime.Now;
                fmAssociation.FamilyId       = familyId;
                fmAssociation.MemberId       = memberId;
                fmAssociation.RelatedId      = relatedId;
                fmAssociation.RelationTypeId = relationTypeId;

                context.FamilyMemberAssociations.Add(fmAssociation);
                context.SaveChanges();

                if (!string.IsNullOrWhiteSpace(member.EmailAddress) && !autoApproval)
                {
                    string templatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/HtmlTemplates/familyAddition.html");
                    string html         = File.ReadAllText(templatePath);

                    html = html.Replace("{{name}}", $"{member.FirstName} {member.LastName}");
                    html = html.Replace("{{action_url}}", $"{BaseUrl}/login/ ");
                    html = html.Replace("{{username}}", member.EmailAddress);
                    html = html.Replace("{{password}}", member.Password);
                    html = html.Replace("{{addedBy}}", LoggedInMemberName);
                    html = html.Replace("{{addedOn}}", fmAssociation.CreatedOn.Value.ToString("dddd, dd MMMM yyyy hh:mm tt"));

                    if (relatedMember != null)
                    {
                        html = html.Replace("{{relation}}", $"{relationType} {relatedMember.FirstName} {relatedMember.LastName}");
                    }
                    else
                    {
                        html = html.Replace("{{relation}}", "Unknown relationship");
                    }

                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        using (SmtpClient sClient = new SmtpClient())
                        {
                            using (MailMessage mailMessage = new MailMessage("*****@*****.**", member.EmailAddress))
                            {
                                mailMessage.Body       = html;
                                mailMessage.IsBodyHtml = true;
                                mailMessage.Subject    = "Brahmkshatriya Online Portal - Notification";

                                sClient.Send(mailMessage);
                            }
                        }
                    });
                }
            }

            return(Ok());
        }
示例#6
0
        public IHttpActionResult Save(MemberViewModel model)
        {
            if (!model.MemberID.HasValue)
            {
                if (!CanEditFamily(model.FamilyId.Value))
                {
                    return(BadRequest("You do not have permission to edit this family"));
                }
            }

            if (model.MemberID.HasValue)
            {
                if (!CanEditMember(model.FamilyId.Value, model.MemberID.Value))
                {
                    return(BadRequest("You do not have permission to edit this member"));
                }
            }

            bool sendWelcomeLetter = false;

            using (bkContext context = new bkContext())
            {
                Member member = null;

                if (model.MemberID.HasValue)
                {
                    member = context.Members.Where(x => x.MemberID == model.MemberID).FirstOrDefault();
                    if (member == null)
                    {
                        return(BadRequest("Member record cannot be loaded. Please try again or contact Administrator for help"));
                    }

                    //if member record has email address and login was done no change in email address allowed
                    if (!string.IsNullOrWhiteSpace(member.EmailAddress) && member.EmailAddress != model.Email && member.LastLoginOn.HasValue)
                    {
                        return(BadRequest("You cannot change email address. Please contact Administrator for help"));
                    }

                    member.ModifiedBy = LoggedInMemberId;
                    member.ModifiedOn = DateTime.Now;

                    //if email was not available and later on provided
                    sendWelcomeLetter = string.IsNullOrWhiteSpace(member.EmailAddress) && !string.IsNullOrWhiteSpace(model.Email);

                    if (!sendWelcomeLetter) //email changed and no earlier sign in attempt was made
                    {
                        sendWelcomeLetter = !string.IsNullOrWhiteSpace(model.Email) && member.EmailAddress != model.Email && !member.LastLoginOn.HasValue;
                    }
                }
                else
                {
                    member = new Member();

                    string tPassword = System.Web.Security.Membership.GeneratePassword(8, 0);
                    tPassword       = Regex.Replace(tPassword, @"[^a-zA-Z0-9]", m => "9");
                    member.Password = tPassword;

                    member.CreatedOn = DateTime.Now;
                    member.CreatedBy = LoggedInMemberId;
                    context.Members.Add(member);

                    sendWelcomeLetter = !string.IsNullOrWhiteSpace(model.Email);
                }

                member.Alive           = model.Alive;
                member.BirthPlace      = model.BirthPlace;
                member.CompanyName     = model.CompanyName;
                member.DeathPlace      = model.DeathPlace;
                member.DOB             = model.DOB;
                member.DOD             = model.DOD;
                member.EducationField  = model.EducationField;
                member.EducationLevel  = model.EducationLevel;
                member.EmailAddress    = string.IsNullOrWhiteSpace(model.Email) ? null : model.Email.Trim();
                member.FacebookHandle  = model.FacebookHandle;
                member.FirstName       = model.FirstName;
                member.Gender          = model.Gender;
                member.InstagramHandle = model.InstagramHandle;
                member.OccupationID    = model.OccupationId;
                member.JobTitle        = model.JobTitle;
                member.LastName        = model.LastName;
                member.NickName        = model.NickName;
                member.Phone           = model.PhoneNumber;
                member.TwitterHandle   = model.TwitterHandle;
                member.MaritalStatusID = model.MaritalStatusId;
                member.Anniversary     = model.Anniversary;
                member.Active          = !string.IsNullOrWhiteSpace(member.EmailAddress);
                member.ProfileText     = model.ProfileText;

                //TODO: check only if the email address has changed.
                if (!string.IsNullOrWhiteSpace(member.EmailAddress))
                {
                    if (context.Members.Any(x => x.EmailAddress == member.EmailAddress && x.MemberID != member.MemberID))
                    {
                        return(BadRequest("Email address is already registered with other member"));
                    }
                }

                FamilyMemberAssociation mAssociation = member.FamilyMemberAssociations.Where(f => f.FamilyId == model.FamilyId.Value).FirstOrDefault();
                if (mAssociation == null)
                {
                    mAssociation               = new FamilyMemberAssociation();
                    mAssociation.CreatedOn     = DateTime.Now;
                    mAssociation.CreatedBy     = LoggedInMemberId;
                    mAssociation.DefaultFamily = true;
                    mAssociation.Approved      = true;
                    mAssociation.FamilyId      = model.FamilyId.Value;
                    member.FamilyMemberAssociations.Add(mAssociation);
                }

                mAssociation.RelatedId      = model.RelatedMemberId;
                mAssociation.RelationTypeId = model.RelationTypeId;

                context.SaveChanges();

                if (sendWelcomeLetter)
                {
                    string templatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/HtmlTemplates/welcome_to_family.html");
                    string html         = File.ReadAllText(templatePath);

                    html = html.Replace("{{name}}", $"{member.FirstName} {member.LastName}");
                    html = html.Replace("{{addedby}}", LoggedInMemberFullName);
                    html = html.Replace("{{action_url}}", $"{BaseUrl}/login/ ");
                    html = html.Replace("{{username}}", member.EmailAddress);
                    html = html.Replace("{{password}}", member.Password);

                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        using (SmtpClient sClient = new SmtpClient())
                        {
                            using (MailMessage mailMessage = new MailMessage("*****@*****.**", member.EmailAddress))
                            {
                                mailMessage.Body       = html;
                                mailMessage.IsBodyHtml = true;
                                mailMessage.Subject    = "Brahmkshatriya Online Portal - Welcome Letter";

                                sClient.Send(mailMessage);
                            }
                        }
                    });
                }
            }

            return(Ok());
        }
示例#7
0
        public IHttpActionResult Fork(FamilyViewModel model)
        {
            if (!CanEditFamily(model.FamilyID))
            {
                return(BadRequest("You do not have permission to manage this family"));
            }

            if (model.Members.Where(x => x.Selected).Count() == 0)
            {
                return(BadRequest("No valid members provided for fork family"));
            }

            using (bkContext context = new bkContext())
            {
                Family family = context.Families.FirstOrDefault(x => x.FamilyID == model.FamilyID);
                List <FamilyMemberAssociation> fmAssociations  = family.FamilyMemberAssociations.Where(x => x.Approved).ToList();
                List <FamilyMemberViewModel>   selectedMembers = model.Members.Where(x => x.Selected).ToList();

                foreach (var item in selectedMembers)
                {
                    if (!fmAssociations.Any(x => x.MemberId == item.MemberID))
                    {
                        return(BadRequest("Invalid members supplied for the family"));
                    }

                    if (!fmAssociations.Any(x => x.MemberId == item.RelatedToId) && model.HeadOfFamilyID != item.MemberID)
                    {
                        return(BadRequest("Please provide relations for member except for Head Of Family"));
                    }
                }

                if (!fmAssociations.Any(x => x.MemberId == model.HeadOfFamilyID) || model.HeadOfFamilyID == 0)
                {
                    return(BadRequest("Invalid Head of Family supplied for the family"));
                }

                if (context.Families.Any(x => x.HeadOfFamilyID == model.HeadOfFamilyID))
                {
                    return(BadRequest("Head Of Family for new family is already a Head Of Family for another family"));
                }

                if (!fmAssociations.Any(x => x.MemberId == model.HeadOfFamilyID && x.Approved))
                {
                    return(BadRequest("Head Of Family is not approved member of the family"));
                }

                Family newFam = new Family();
                newFam.FamilyNative   = model.FamilyNative;
                newFam.Address1       = model.Address1;
                newFam.Address2       = model.Address2;
                newFam.City           = model.City;
                newFam.District       = model.District;
                newFam.State          = model.State;
                newFam.PostalCode     = model.PostalCode;
                newFam.Country        = model.Country;
                newFam.CategoryID     = model.CategoryID;
                newFam.NukhID         = model.NukhID;
                newFam.HeadOfFamilyID = model.HeadOfFamilyID;
                newFam.CreatedBy      = LoggedInMemberId;
                newFam.CreatedOn      = DateTime.Now;

                foreach (var item in selectedMembers)
                {
                    List <FamilyMemberAssociation> associations = context.FamilyMemberAssociations.Where(x => x.MemberId == item.MemberID).ToList();
                    foreach (var m in associations)
                    {
                        if (m.Family.HeadOfFamilyID != item.MemberID)
                        {
                            m.DefaultFamily = false;
                        }
                    }

                    FamilyMemberAssociation fAssociation = new FamilyMemberAssociation();

                    fAssociation.Approved       = true;
                    fAssociation.CreatedBy      = LoggedInMemberId;
                    fAssociation.CreatedOn      = DateTime.Now;
                    fAssociation.MemberId       = item.MemberID;
                    fAssociation.RelatedId      = item.RelatedToId;
                    fAssociation.RelationTypeId = item.RelationTypeId;
                    fAssociation.DefaultFamily  = !associations.Any(x => x.DefaultFamily == true);

                    newFam.FamilyMemberAssociations.Add(fAssociation);
                }

                context.Families.Add(newFam);
                context.SaveChanges();

                return(Ok(newFam.FamilyID));
            }
        }