Esempio n. 1
0
        public virtual ActionResult RelationshipsEdit(UserEditRelationshipsViewModel model)
        {
            if (ModelState.IsValid)
            {
                FamilyRepository repos = new FamilyRepository();
                // save the new relationship
                //Relationship relationship = new Relationship();
                //relationship.SourceUser = Target;
                //relationship.RelatedUser = db.Users.Find(model.NewRelatedUserId);
                //relationship.RelatedUserIsSourceUsers = model.NewRelationshipType;
                //repos.UpdateRelationship(db, relationship);

                foreach (var item in model.FamilyRelationshipsNew)
                {
                    Relationship relationship = new Relationship();
                    relationship.SourceUser  = Target;
                    relationship.RelatedUser = db.Users.Find(item.RelatedUserId);
                    if (item.Relationship == UserEditRelationshipsViewModel.RelationshipTypeViewModel.NotImmediateFamilyMember)
                    {
                        repos.RemoveRelationship(db, relationship);
                    }
                    else
                    {
                        relationship.RelatedUserIsSourceUsers = ((RelationshipType)item.Relationship).Reciprocal();
                        repos.UpdateRelationship(db, relationship);
                    }
                }

                return(RedirectToAction(MVC.User.Details().WithId(Target)));
            }

            return(View(model));
        }