コード例 #1
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult UploadPhoto(dynamic json)
        {
            dynamic model    = JsonConvert.DeserializeObject <ExpandoObject>(json.ToString());
            int     memberId = Convert.ToInt32(model.memberId);

            if (!CanEditMember(memberId))
            {
                return(BadRequest("You do not have permission to edit this member"));
            }

            if (string.IsNullOrWhiteSpace(model.image))
            {
                return(BadRequest("No image content provided"));
            }

            byte[] imageBytes = Convert.FromBase64String(model.image.Replace("data:image/jpeg;base64,", ""));

            using (MemoryStream stream = new MemoryStream(imageBytes))
            {
                Image  img      = Image.FromStream(stream);
                string filePath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format(@"~/Images/Profiles/{0}.jpg", memberId));
                img.Save(filePath);
            }

            using (bkContext context = new bkContext())
            {
                Member member = context.Members.FirstOrDefault(x => x.MemberID == memberId);
                member.ModifiedBy = LoggedInMemberId;
                member.ModifiedOn = DateTime.Now;

                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (!actionContext.ModelState.IsValid)
            {
                actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState);
            }

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                ClaimsPrincipal principal = actionContext.Request.GetRequestContext().Principal as ClaimsPrincipal;
                int             memberId  = Convert.ToInt32(principal.Claims.Where(c => c.Type == "memberId").Single().Value);

                if (memberId == -1)
                {
                    return;
                }

                using (bkContext context = new bkContext())
                {
                    if (!context.Members.Any(x => x.MemberID == memberId))
                    {
                        actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Your token has been revoked");
                    }
                }
            }
        }
コード例 #3
0
ファイル: FamilyController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult Delete(FamilyViewModel model)
        {
            if (!CanEditFamily(model.FamilyID))
            {
                return(BadRequest("You do not have rights to delete this family"));
            }

            bool logOut = false;

            using (bkContext context = new bkContext())
            {
                using (var tnx = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.bk_DeleteFamily(model.FamilyID);
                        tnx.Commit();
                    }
                    catch
                    {
                        tnx.Rollback();
                        throw;
                    }

                    //make sure logged in member is still active on the system
                    logOut = !context.Members.Any(x => x.MemberID == LoggedInMemberId);
                }
            }

            return(Ok(logOut));
        }
コード例 #4
0
ファイル: LoginController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult ResetPassword(string password, string token)
        {
            using (bkContext context = new bkContext())
            {
                Guid resetToken = new Guid();
                if (!Guid.TryParse(token, out resetToken))
                {
                    return(BadRequest("Invalid Token, please regenerate your password reset request"));
                }

                Member member = context.Members.FirstOrDefault(m => m.PasswordUID == resetToken);

                if (member == null)
                {
                    return(BadRequest("Invalid Token, please regenerate your password reset request"));
                }

                member.PasswordUID = null;
                member.Password    = password;
                member.ModifiedOn  = DateTime.Now;
                member.ModifiedBy  = member.MemberID;

                context.SaveChanges();
            }

            return(Ok(true));
        }
コード例 #5
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult DefaultFamily(int memberId)
        {
            int familyId = 0;

            using (bkContext context = new bkContext())
            {
                familyId = context.FamilyMemberAssociations.Where(x => x.MemberId == memberId && x.DefaultFamily).Select(x => x.FamilyId).FirstOrDefault();
            }

            return(Ok(familyId));
        }
コード例 #6
0
ファイル: FamilyController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult Save(FamilyViewModel model)
        {
            if (!CanEditFamily(model.FamilyID))
            {
                return(BadRequest("You do not have permission to edit this family"));
            }

            using (bkContext context = new bkContext())
            {
                Family family = context.Families.Where(f => f.FamilyID == model.FamilyID).FirstOrDefault();
                if (family == null)
                {
                    return(BadRequest("Family record cannot be loaded. Please try again later"));
                }

                if (model.HeadOfFamilyID == 0)
                {
                    return(BadRequest("please provide Head Of Family"));
                }

                if (!family.FamilyMemberAssociations.Any(x => x.MemberId == model.HeadOfFamilyID))
                {
                    return(BadRequest("Supplied Head Of Family is not part of family"));
                }

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

                if (context.Families.Any(x => x.FamilyID != model.FamilyID && x.HeadOfFamilyID == model.HeadOfFamilyID))
                {
                    return(BadRequest("Selected Head Of Family is already a Head Of Family for another family. Please select other member as head of family."));
                }

                family.FamilyNative   = model.FamilyNative;
                family.Address1       = model.Address1;
                family.Address2       = model.Address2;
                family.CategoryID     = model.CategoryID;
                family.City           = model.City;
                family.District       = model.District;
                family.Country        = model.Country;
                family.NukhID         = model.NukhID;
                family.PostalCode     = model.PostalCode;
                family.State          = model.State;
                family.HeadOfFamilyID = model.HeadOfFamilyID;
                family.ModifiedOn     = DateTime.Now;
                family.ModifiedBy     = LoggedInMemberId;

                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #7
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult Search(MemberSearchModel model)
        {
            string firstName      = string.IsNullOrWhiteSpace(model.FirstName) ? null : model.FirstName.Trim();
            string lastName       = string.IsNullOrWhiteSpace(model.LastName) ? null : model.LastName.Trim();
            int?   categoryId     = model.CategoryID.HasValue && model.CategoryID.Value > 0 ? model.CategoryID : null;
            int?   nukhId         = model.NukhID.HasValue && model.NukhID.Value > 0 ? model.NukhID : null;
            string city           = string.IsNullOrWhiteSpace(model.City) ? null : model.City.Trim();
            string district       = string.IsNullOrWhiteSpace(model.District) ? null : model.District.Trim();
            string state          = string.IsNullOrWhiteSpace(model.State) ? null : model.State.Trim();
            string emailAddress   = string.IsNullOrWhiteSpace(model.Email) ? null : model.Email.Trim();
            string phoneNumber    = string.IsNullOrWhiteSpace(model.PhoneNumber) ? null : model.PhoneNumber.Trim();
            string sortOrder      = string.IsNullOrWhiteSpace(model.SortOrder) ? null : model.SortOrder.Trim();
            int?   currentPage    = model.CurrentPage.HasValue && model.CurrentPage.Value > 0 ? model.CurrentPage : null;
            int?   pageSize       = model.PageSize.HasValue && model.PageSize.Value > 0 ? model.PageSize : null;
            int?   memberId       = model.MemberId > 0 ? model.MemberId : (int?)null;
            bool   includeOnlyHOF = model.IncludeOnlyHOF;

            MemberSearchResultModel mvm = new MemberSearchResultModel();

            using (bkContext context = new bkContext())
            {
                ObjectParameter oParameter = new ObjectParameter("TotalRecords", typeof(int));

                List <bk_MemberSearch_Result> results = context.bk_MemberSearch(firstName, lastName, categoryId, nukhId, city, district, state, emailAddress, phoneNumber, pageSize, currentPage, includeOnlyHOF, sortOrder, memberId, null, oParameter).ToList();

                mvm.TotalRecords = (int)oParameter.Value;

                foreach (var result in results)
                {
                    var item = new MemberSearchResultItemModel();

                    item.Name     = $"{result.FirstName} {result.LastName}";
                    item.Address1 = $"{result.Address1}, {result.Address2}".TrimEnd(' ').TrimEnd(',').TrimStart(',');
                    item.Address2 = $"{result.City}, {result.District}, {result.State}, {result.Country}".TrimEnd(' ').TrimEnd(',').TrimStart(',').Replace(", , ", ", ");
                    item.MemberId = result.MemberID;
                    item.FamilyId = result.FamilyID;
                    item.Gender   = result.Gender;
                    item.Alive    = result.Alive;
                    item.DOB      = result.DOB;
                    item.DOD      = result.DOD;
                    item.PhotoUrl = MemberWrapper.ProfilePhoto(result.MemberID, result.Gender, result.ModifiedOn);

                    mvm.Results.Add(item);
                }
            }

            return(Ok(mvm));
        }
コード例 #8
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult Lookup(int memberId)
        {
            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"));
                }

                MemberViewModel vm = new MemberViewModel();

                vm.FirstName = member.FirstName;
                vm.LastName  = member.LastName;
                vm.Gender    = member.Gender;

                return(Ok(vm));
            }
        }
コード例 #9
0
        protected bool CanEditFamily(int familyId)
        {
            if (LoggedInMemberId == 0)
            {
                return(false);
            }

            if (LoggedInMemberId == -1)
            {
                return(true);
            }

            using (bkContext context = new bkContext())
            {
                Family family = context.Families.Where(x => x.FamilyID == familyId).FirstOrDefault();

                return(CanEditFamily(family));
            }
        }
コード例 #10
0
        protected bool CanEditFamily(Family family)
        {
            if (LoggedInMemberId == 0)
            {
                return(false);
            }

            if (LoggedInMemberId == -1)
            {
                return(true);
            }

            using (bkContext context = new bkContext())
            {
                bool canEdit = family.FamilyMemberAssociations.Any(x => x.MemberId == LoggedInMemberId) || family.CreatedBy == LoggedInMemberId;

                return(canEdit);
            }
        }
コード例 #11
0
ファイル: LoginController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult SendResetPasswordEmail(string emailAddress)
        {
            using (bkContext context = new bkContext())
            {
                if (!context.Members.Any(m => m.EmailAddress == emailAddress))
                {
                    return(BadRequest("Email address is not registered"));
                }

                Member member = context.Members.FirstOrDefault(m => m.EmailAddress == emailAddress);
                if (member == null)
                {
                    return(BadRequest("Your account information cannot be loaded. Please contact Administrator for help"));
                }

                member.PasswordUID = Guid.NewGuid();
                context.SaveChanges();

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

                html = html.Replace("{{name}}", $"{member.FirstName} {member.LastName}");
                html = html.Replace("{{action_url}}", $"{BaseUrl}/resetpassword/{member.PasswordUID.Value.ToString()} ");

                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 - Password Reset";

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

            return(Ok(true));
        }
コード例 #12
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult ProfilePhoto()
        {
            string   url = "";
            DateTime?modifiedOn;
            bool     gender;

            using (bkContext context = new bkContext())
            {
                Member member = context.Members.FirstOrDefault(x => x.MemberID == LoggedInMemberId);
                if (member != null)
                {
                    gender     = member.Gender;
                    modifiedOn = member.ModifiedOn;

                    url = MemberWrapper.ProfilePhoto(LoggedInMemberId, gender, modifiedOn);
                }
            }

            return(Ok(url));
        }
コード例 #13
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            Member member  = null;
            bool   isAdmin = false;

            using (bkContext _context = new bkContext())
            {
                member = _context.Members.FirstOrDefault(m => m.EmailAddress == context.UserName);

                if (member != null)
                {
                    if (!member.Password.Equals(context.Password, StringComparison.Ordinal))
                    {
                        member = null;
                    }
                }

                if (member == null && context.UserName == "*****@*****.**" && context.Password.Equals("L4ndm4rk^%9", StringComparison.Ordinal))
                {
                    isAdmin = true;
                }

                if (member == null && !isAdmin)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }

                if (!isAdmin)
                {
                    member.LastLoginOn = DateTime.Now;
                    await _context.SaveChangesAsync();
                }
            }

            var identity = GetIdentity(member, isAdmin);
            var ticket   = new AuthenticationTicket(identity, null);

            context.Validated(ticket);
        }
コード例 #14
0
        protected bool CanEditMember(int memberId)
        {
            if (LoggedInMemberId == 0)
            {
                return(false);
            }

            if (LoggedInMemberId == -1)
            {
                return(true);
            }

            using (bkContext context = new bkContext())
            {
                bool       iCreatedMember = context.Members.Any(x => x.MemberID == memberId && x.CreatedBy == LoggedInMemberId);
                List <int> fma1           = context.FamilyMemberAssociations.Where(x => x.MemberId == memberId && x.Approved).Select(x => x.FamilyId).ToList();
                List <int> fma2           = context.FamilyMemberAssociations.Where(x => x.MemberId == LoggedInMemberId && x.Approved).Select(x => x.FamilyId).ToList();

                return(fma1.Intersect(fma2).Any() || iCreatedMember);
            }
        }
コード例 #15
0
        public IHttpActionResult Delete(int memberId)
        {
            using (bkContext context = new bkContext())
            {
                if (!CanEditMember(memberId))
                {
                    return(BadRequest("You do not have permission to delete this record"));
                }

                Matrimonial mat = context.Matrimonials.FirstOrDefault(x => x.MemberID == memberId);
                if (mat == null)
                {
                    return(BadRequest("Matrimony profile cannot be loaded"));
                }

                context.Matrimonials.Remove(mat);
                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #16
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        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());
        }
コード例 #17
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult Delete(int familyId, int memberId)
        {
            if (!CanEditFamily(familyId))
            {
                return(BadRequest("You do not have permission to edit this member"));
            }

            bool logOut = false;

            using (bkContext context = new bkContext())
            {
                using (var tnx = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (context.Families.Any(x => x.FamilyID == familyId && x.HeadOfFamilyID == memberId))
                        {
                            return(BadRequest("Head Of Family cannot be deleted"));
                        }

                        context.bk_DeleteMember(familyId, memberId);
                        tnx.Commit();
                    }
                    catch
                    {
                        tnx.Rollback();
                        throw;
                    }

                    //if we are deleting logged in member from family log out him if he is entirely deleted from system
                    if (memberId == LoggedInMemberId)
                    {
                        logOut = !context.Members.Any(x => x.MemberID == LoggedInMemberId);
                    }
                }
            }

            return(Ok(logOut));
        }
コード例 #18
0
        public IHttpActionResult Get(int memberId)
        {
            using (bkContext context = new bkContext())
            {
                Matrimonial mat    = context.Matrimonials.FirstOrDefault(x => x.MemberID == memberId);
                Member      member = context.Members.FirstOrDefault(x => x.MemberID == memberId);
                if (mat == null)
                {
                    return(BadRequest("Matrimony profile cannot be loaded"));
                }

                MatrimonyViewModel model = new MatrimonyViewModel();

                model.Alcohol          = mat.Alcohol;
                model.BirthTime        = mat.BirthTime;
                model.BodyTypeId       = mat.BodyTypeID;
                model.ComplexionTypeId = mat.ComplexionTypeID;
                model.Disability       = mat.Disability;
                model.Height           = mat.Height;
                model.Language         = mat.Language;
                model.Mangal           = mat.Mangal;
                model.MaritalStatusId  = mat.MaritalStatusID;
                model.MaternalNukhId   = mat.MaternalNukhID;
                model.MemberId         = mat.MemberID;
                model.MonthlyIncome    = mat.MonthlyIncome;
                model.OwnHome          = mat.OwnHome;
                model.ProfileText      = mat.ProfileText;
                model.Smoke            = mat.Smoke;
                model.Tobacco          = mat.Tobacco;
                model.Vegetarian       = mat.Vegetarian;
                model.Weight           = mat.Weight;
                model.Photo1Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 1, mat.ModifiedOn);
                model.Photo2Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 2, mat.ModifiedOn);
                model.Photo3Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 3, mat.ModifiedOn);

                return(Ok(model));
            }
        }
コード例 #19
0
ファイル: FamilyController.cs プロジェクト: vijaydairyf/bk
        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));
            }
        }
コード例 #20
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult MarkDefaultFamily(int familyId, int memberId)
        {
            using (bkContext context = new bkContext())
            {
                if (!CanEditMember(familyId, memberId))
                {
                    return(BadRequest("You do not have permission to edit this member"));
                }

                List <FamilyMemberAssociation> fmAssociations = context.FamilyMemberAssociations.Where(m => m.MemberId == memberId).ToList();

                if (context.Families.Any(x => x.FamilyID != familyId && x.HeadOfFamilyID == memberId))
                {
                    return(BadRequest("This member is Head Of Family in another family and cannot be marked default here"));
                }

                foreach (var item in fmAssociations)
                {
                    if (item.FamilyId == familyId)
                    {
                        item.DefaultFamily = true;
                        item.ModifiedBy    = LoggedInMemberId;
                        item.ModifiedOn    = DateTime.Now;
                    }
                    else if (item.DefaultFamily)
                    {
                        item.DefaultFamily = false;
                        item.ModifiedBy    = LoggedInMemberId;
                        item.ModifiedOn    = DateTime.Now;
                    }
                }

                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #21
0
        public IHttpActionResult DeletePhoto(int photoNumber, int memberId)
        {
            if (!CanEditMember(memberId))
            {
                return(BadRequest("You do not have permission to edit this member"));
            }

            if (photoNumber < 1 || photoNumber > 3)
            {
                return(BadRequest("Invalid photo number"));
            }

            string filePath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format(@"~/Images/Matrimonials/{0}_{1}.jpg", memberId, photoNumber));

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            string response = string.Empty;

            using (bkContext context = new bkContext())
            {
                Matrimonial mat = context.Matrimonials.FirstOrDefault(x => x.MemberID == memberId);
                if (mat != null)
                {
                    mat.ModifiedBy = LoggedInMemberId;
                    mat.ModifiedOn = DateTime.Now;

                    context.SaveChanges();
                }

                response = MemberWrapper.MatrimonyPhoto(memberId, mat.Member.Gender, photoNumber, mat.ModifiedOn);
            }

            return(Ok(response));
        }
コード例 #22
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        public IHttpActionResult ChangePassword(ChangePasswordViewModel model)
        {
            using (bkContext context = new bkContext())
            {
                Member member = context.Members.Where(x => x.MemberID == LoggedInMemberId).FirstOrDefault();
                if (member == null)
                {
                    return(BadRequest("Your record cannot be loaded. Please try again or contact Administrator for help"));
                }

                if (member.Password != model.CurrentPassword)
                {
                    return(BadRequest("Your current password is invalid. Please try again"));
                }

                member.Password   = model.NewPassword;
                member.ModifiedBy = member.MemberID;
                member.ModifiedOn = DateTime.Now;

                context.SaveChanges();
            }

            return(Ok(true));
        }
コード例 #23
0
ファイル: LoginController.cs プロジェクト: vijaydairyf/bk
        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());
        }
コード例 #24
0
ファイル: AuditJob.cs プロジェクト: vijaydairyf/bk
        private void GenerateAudit()
        {
            List <bk_AuditReport_Result> result = null;

            using (bkContext context = new bkContext())
            {
                result = context.bk_AuditReport().ToList();
            }

            if (result == null)
            {
                return;
            }

            var auditTypes = Enum.GetValues(typeof(AuditTypes));

            string baseString   = @"<tr><td>{0}</td><td>{1}</td></tr>";
            string templatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/HtmlTemplates/audit.html");
            string html         = File.ReadAllText(templatePath);

            StringBuilder builder = new StringBuilder();

            foreach (int auditType in auditTypes)
            {
                builder.Clear();

                var tResult = result.Where(x => x.AuditType == auditType).ToList();

                if (tResult != null && tResult.Count > 0)
                {
                    foreach (var item in tResult)
                    {
                        string member = string.Empty;
                        string family = string.Empty;

                        if (!item.FamilyId.HasValue)
                        {
                            item.FamilyId = 0;
                        }

                        if (item.FamilyId.HasValue && item.FamilyId.Value > 0)
                        {
                            family = string.Format("<a href='http://brahmkshatriya.net.in/family/{0}'>{1}</a>", item.FamilyId.Value, item.FamilyName);
                        }

                        if (item.MemberId.HasValue && item.MemberId.Value > 0)
                        {
                            member = string.Format("<a href='http://brahmkshatriya.net.in/member/{0}/{1}'>{2}</a>", item.FamilyId.Value, item.MemberId.Value, item.MemberName);
                        }

                        builder.AppendLine(string.Format(baseString, family, member));
                    }
                }

                string placeholder = "{{" + string.Format("audit_{0}", auditType) + "}}";
                string textResult  = builder.ToString();
                if (string.IsNullOrWhiteSpace(textResult))
                {
                    textResult = "No discrepancy found on this audit.";
                }

                html = html.Replace(placeholder, textResult);
            }
        }
コード例 #25
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        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());
        }
コード例 #26
0
        public IHttpActionResult GetMatrimony(int memberId)
        {
            using (bkContext context = new bkContext())
            {
                Matrimonial mat = context.Matrimonials.FirstOrDefault(x => x.MemberID == memberId);
                if (mat == null)
                {
                    return(BadRequest("Matrimony profile cannot be loaded"));
                }

                Member member = context.Members.FirstOrDefault(x => x.MemberID == memberId);
                if (member == null)
                {
                    return(BadRequest("Matrimony profile cannot be loaded"));
                }

                MatrimonyViewOnlyModel model = new MatrimonyViewOnlyModel();

                model.MatrimonyModel.Alcohol          = mat.Alcohol;
                model.MatrimonyModel.BirthTime        = mat.BirthTime;
                model.MatrimonyModel.BodyTypeId       = mat.BodyTypeID;
                model.MatrimonyModel.ComplexionTypeId = mat.ComplexionTypeID;
                model.MatrimonyModel.Disability       = mat.Disability;
                model.MatrimonyModel.Height           = mat.Height;
                model.MatrimonyModel.Language         = mat.Language;
                model.MatrimonyModel.Mangal           = mat.Mangal;
                model.MatrimonyModel.MaritalStatusId  = mat.MaritalStatusID;
                model.MatrimonyModel.MaternalNukhId   = mat.MaternalNukhID;
                model.MatrimonyModel.MemberId         = mat.MemberID;
                model.MatrimonyModel.MonthlyIncome    = mat.MonthlyIncome;
                model.MatrimonyModel.OwnHome          = mat.OwnHome;
                model.MatrimonyModel.ProfileText      = mat.ProfileText;
                model.MatrimonyModel.Smoke            = mat.Smoke;
                model.MatrimonyModel.Tobacco          = mat.Tobacco;
                model.MatrimonyModel.Vegetarian       = mat.Vegetarian;
                model.MatrimonyModel.Weight           = mat.Weight;
                model.MatrimonyModel.Photo1Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 1, mat.ModifiedOn);
                model.MatrimonyModel.Photo2Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 2, mat.ModifiedOn);
                model.MatrimonyModel.Photo3Url        = MemberWrapper.MatrimonyPhoto(mat.MemberID, mat.Member.Gender, 3, mat.ModifiedOn);

                model.MemberModel.MemberID        = member.MemberID;
                model.MemberModel.FirstName       = member.FirstName;
                model.MemberModel.LastName        = member.LastName;
                model.MemberModel.NickName        = member.NickName;
                model.MemberModel.Email           = member.EmailAddress;
                model.MemberModel.PhoneNumber     = member.Phone;
                model.MemberModel.Gender          = member.Gender;
                model.MemberModel.DOB             = member.DOB;
                model.MemberModel.BirthPlace      = member.BirthPlace;
                model.MemberModel.Alive           = member.Alive;
                model.MemberModel.DOD             = member.DOD;
                model.MemberModel.DeathPlace      = member.DeathPlace;
                model.MemberModel.EducationLevel  = member.EducationLevel;
                model.MemberModel.EducationField  = member.EducationField;
                model.MemberModel.OccupationId    = member.OccupationID;
                model.MemberModel.CompanyName     = member.CompanyName;
                model.MemberModel.JobTitle        = member.JobTitle;
                model.MemberModel.InstagramHandle = member.InstagramHandle;
                model.MemberModel.FacebookHandle  = member.FacebookHandle;
                model.MemberModel.TwitterHandle   = member.TwitterHandle;
                model.MemberModel.MaritalStatusId = member.MaritalStatusID;
                model.MemberModel.PhotoUrl        = MemberWrapper.ProfilePhoto(member.MemberID, member.Gender, member.ModifiedOn);
                model.MemberModel.FamilyId        = member.FamilyMemberAssociations.Where(x => x.DefaultFamily).Select(x => x.FamilyId).FirstOrDefault();

                model.MemberModel.ModifiedOn = mat.ModifiedOn.HasValue ? mat.ModifiedOn : mat.CreatedOn;
                if (member.ModifiedOn > model.MemberModel.ModifiedOn)
                {
                    model.MemberModel.ModifiedOn = member.ModifiedOn;
                }

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

                return(Ok(model));
            }
        }
コード例 #27
0
        public IHttpActionResult Search(MatrimonySearchModel model)
        {
            int?     categoryId      = model.CategoryID.HasValue && model.CategoryID.Value > 0 ? model.CategoryID : null;
            int?     nukhId          = model.NukhID.HasValue && model.NukhID.Value > 0 ? model.NukhID : null;
            string   city            = string.IsNullOrWhiteSpace(model.City) ? null : model.City.Trim();
            string   district        = string.IsNullOrWhiteSpace(model.District) ? null : model.District.Trim();
            string   state           = string.IsNullOrWhiteSpace(model.State) ? null : model.State.Trim();
            string   country         = string.IsNullOrWhiteSpace(model.Country) ? null : model.Country.Trim();
            bool?    gender          = model.Gender;
            int?     occupationId    = model.OccupationId.HasValue && model.OccupationId.Value > 0 ? model.OccupationId : null;
            int?     maritalStatusId = model.MaritalStatusId.HasValue && model.MaritalStatusId.Value > 0 ? model.MaritalStatusId : null;
            int?     minAge          = model.MinimumAge.HasValue && model.MinimumAge.Value > 0 ? model.MinimumAge : null;
            int?     maxAge          = model.MaximumAge.HasValue && model.MaximumAge.Value > 0 ? model.MaximumAge : null;
            int?     currentPage     = model.CurrentPage.HasValue && model.CurrentPage.Value > 0 ? model.CurrentPage : null;
            int?     pageSize        = model.PageSize.HasValue && model.PageSize.Value > 0 ? model.PageSize : null;
            string   sortOrder       = string.IsNullOrWhiteSpace(model.SortOrder) ? null : model.SortOrder.Trim();
            DateTime?minDOB          = null;
            DateTime?maxDOB          = null;

            if (minAge.HasValue)
            {
                maxDOB = DateTime.Today.AddYears(minAge.Value * -1);
            }

            if (maxAge.HasValue)
            {
                minDOB = DateTime.Today.AddYears(maxAge.Value * -1);
            }

            MemberSearchResultModel mvm = new MemberSearchResultModel();

            using (bkContext context = new bkContext())
            {
                ObjectParameter oParameter = new ObjectParameter("TotalRecords", typeof(int));

                List <bk_MatrimonySearch_Result> results = context.bk_MatrimonySearch(categoryId, nukhId, city, district, state, country, gender, occupationId, maritalStatusId, minDOB, maxDOB, pageSize, currentPage, sortOrder, oParameter).ToList();

                mvm.TotalRecords = (int)oParameter.Value;

                foreach (var result in results)
                {
                    var item = new MemberSearchResultItemModel();

                    item.Name          = $"{result.FirstName} {result.LastName}";
                    item.Address1      = $"{result.Address1}, {result.Address2}".TrimEnd(' ').TrimEnd(',').TrimStart(',');
                    item.Address2      = $"{result.City}, {result.District}, {result.State}, {result.Country}".TrimEnd(' ').TrimEnd(',').TrimStart(',').Replace(", , ", ", ");
                    item.MemberId      = result.MemberID;
                    item.FamilyId      = result.FamilyID;
                    item.Gender        = result.Gender;
                    item.DOB           = result.DOB;
                    item.OccupationId  = result.OccupationID > 0 ? result.OccupationID : (int?)null;
                    item.MonthlyIncome = result.MonthlyIncome > 0 ? result.MonthlyIncome : (int?)null;

                    if (!string.IsNullOrWhiteSpace(result.EducationField) && !string.IsNullOrWhiteSpace(result.EducationLevel))
                    {
                        item.Education = $"{result.EducationLevel} - {result.EducationField}";
                    }
                    else if (!string.IsNullOrWhiteSpace(result.EducationLevel))
                    {
                        item.Education = $"{result.EducationLevel}";
                    }
                    else if (!string.IsNullOrWhiteSpace(result.EducationField))
                    {
                        item.Education = $"{result.EducationField}";
                    }

                    item.PhotoUrl  = MemberWrapper.ProfilePhoto(result.MemberID, result.Gender, result.ModifiedOn);
                    item.Photo1Url = MemberWrapper.MatrimonyPhoto(result.MemberID, result.Gender, 1, result.ModifiedOn);
                    item.Photo2Url = MemberWrapper.MatrimonyPhoto(result.MemberID, result.Gender, 2, result.ModifiedOn);
                    item.Photo3Url = MemberWrapper.MatrimonyPhoto(result.MemberID, result.Gender, 3, result.ModifiedOn);

                    mvm.Results.Add(item);
                }
            }

            return(Ok(mvm));
        }
コード例 #28
0
        public IHttpActionResult Save(MatrimonyViewModel model)
        {
            using (bkContext context = new bkContext())
            {
                if (!CanEditMember(model.MemberId))
                {
                    return(BadRequest("You do not have permission to update this record"));
                }

                Matrimonial mat    = context.Matrimonials.FirstOrDefault(x => x.MemberID == model.MemberId);
                Member      member = context.Members.FirstOrDefault(x => x.MemberID == model.MemberId);

                if (member == null)
                {
                    return(BadRequest("Member record cannot be loaded. Please try again later"));
                }

                if (!member.Alive)
                {
                    return(BadRequest("You cannot create a matrimony profile unless a member is alive"));
                }

                if (member.MaritalStatusID == 2)
                {
                    return(BadRequest("You cannot create a matrimony profile because person's marital status is set to Married"));
                }

                if (!member.DOB.HasValue)
                {
                    return(BadRequest("You cannot create a matrimony profile because person's Date Of Birth is missing"));
                }

                if (member.Gender && MemberWrapper.Age(member.DOB.Value) < 21)
                {
                    return(BadRequest("You cannot create a matrimony profile because person's age is less than 21"));
                }

                if (!member.Gender && MemberWrapper.Age(member.DOB.Value) < 18)
                {
                    return(BadRequest("You cannot create a matrimony profile because person's age is less than 18"));
                }

                if (mat != null)
                {
                    mat.ModifiedBy = LoggedInMemberId;
                    mat.ModifiedOn = DateTime.Now;
                }
                else
                {
                    mat           = new Matrimonial();
                    mat.CreatedBy = LoggedInMemberId;
                    mat.CreatedOn = DateTime.Now;
                    mat.MemberID  = model.MemberId;
                    context.Matrimonials.Add(mat);
                }

                mat.Alcohol          = model.Alcohol;
                mat.BirthTime        = model.BirthTime;
                mat.BodyTypeID       = model.BodyTypeId;
                mat.ComplexionTypeID = model.ComplexionTypeId;
                mat.Disability       = model.Disability;
                mat.Height           = model.Height;
                mat.Language         = model.Language;
                mat.Mangal           = model.Mangal;
                mat.MaritalStatusID  = model.MaritalStatusId;
                mat.MaternalNukhID   = model.MaternalNukhId;
                mat.MonthlyIncome    = model.MonthlyIncome;
                mat.OwnHome          = model.OwnHome;
                mat.ProfileText      = model.ProfileText;
                mat.Smoke            = model.Smoke;
                mat.Tobacco          = model.Tobacco;
                mat.Vegetarian       = model.Vegetarian;
                mat.Weight           = model.Weight;

                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #29
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        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());
        }
コード例 #30
0
ファイル: MemberController.cs プロジェクト: vijaydairyf/bk
        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));
            }
        }