Esempio n. 1
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());
        }