// [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Write" })]
        public IActionResult Index()
        {
            RelationshipViewModel model = new RelationshipViewModel();

            InitAccessModel(model);
            return(View(model));
        }
Ejemplo n.º 2
0
        public void RelationshipEditModel_commit_notifies()
        {
            // ARRANGE

            var entity1   = new EntityViewModel(new Entity());
            var entity2   = new EntityViewModel(new Entity());
            var model     = new Relationship("r", new Entity(), new Entity(), new Tag());
            var viewModel = new RelationshipViewModel(model, new EntityViewModel(model.From), new EntityViewModel(model.To));

            var editModel = new RelationshipEditModel(viewModel, delegate { }, delegate { });

            // ACT

            EditModelCommitted result = null;
            var committedNotification = new Action <EditModelCommitted>(n => result = n);

            Messenger.Default.Register <EditModelCommitted>(this, committedNotification);

            editModel.CommitCommand.Execute(null);

            // ASSERT

            Assert.NotNull(result);
            Assert.Equal(typeof(RelationshipViewModel), result.ViewModel.GetType());
            Assert.Equal(viewModel, result.TryGetViewModel <RelationshipViewModel>().Item2);
        }
        public ActionResult Index(string relationshipValue)
        {
            var userId = User.Identity.GetUserId();

            if (_context.Relationships.Where(x => x.UserProfileId == userId).Count() < 16)
            {
                var relationship = new Relationship
                {
                    RelationshipId    = _context.Relationships.Count() + 1,
                    RelationshipValue = relationshipValue,
                    UserProfileId     = userId
                };
                _context.Relationships.Add(relationship);
                _context.SaveChanges();

                ModelState.Clear();
                var relationships           = _context.Relationships.Where(x => x.UserProfileId == userId);
                RelationshipViewModel model = new RelationshipViewModel(relationships);
                return(PartialView("_RelationshipTable", model));
            }

            else
            {
                ModelState.Clear();
                var relationships           = _context.Relationships.Where(x => x.UserProfileId == userId);
                RelationshipViewModel model = new RelationshipViewModel(relationships);
                return(PartialView("_RelationshipTable", model));
            }
        }
Ejemplo n.º 4
0
        public PartialViewResult FriendList()
        {
            string userID = User.Identity.GetUserId();
            List <RelationshipViewModel> friends = RelationshipViewModel.GetRelationshipList(userID, RelationshipStatus.Friends);

            return(PartialView("_FriendList", friends));
        }
        public ActionResult RelationshipEdit(RelationshipViewModel model)
        {
            var userId        = User.Identity.GetUserId();
            var relationships = _context.Relationships.AsNoTracking().Where(x => x.UserProfileId == userId).ToList();

            if (model.Relationships == null)
            {
                return(RedirectToAction("Index", "relationship"));
            }

            else
            {
                relationships = model.Relationships;
                foreach (var relationship in relationships)
                {
                    _context.Entry(relationship).State = EntityState.Modified;
                }

                _context.SaveChanges();
                ModelState.Clear();

                model.Relationships = relationships.ToList();
                return(View(model));
            }
        }
Ejemplo n.º 6
0
        // GET: Relationship/StudentLessons
        public async Task <ActionResult> StudentLessons(string user, long id)
        {
            try
            {
                Teacher teacher = await _teacherRepositoryAsync.GetByUserAsync(user);

                List <Student> Students = await _studentRepositoryAsync.ListByUserAsync(user);

                Student student = await _studentRepositoryAsync.GetByIdAsync(id);

                List <StudentLesson> studentLessons  = student.StudentLessons;
                List <long>          assignedLessons = new List <long>();

                foreach (var lesson in studentLessons)
                {
                    assignedLessons.Add(lesson.LessonId);
                }

                RelationshipViewModel model = new RelationshipViewModel
                {
                    Teacher         = teacher,
                    Student         = student,
                    StudentLessons  = studentLessons,
                    AssignedLessons = assignedLessons
                };

                return(View(model));
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 7
0
        public PartialViewResult _SuggestedFriends()
        {
            string userID = User.Identity.GetUserId();
            List <RelationshipViewModel> suggestedFriends = RelationshipViewModel.GetNullRelationshipList(userID);

            return(PartialView("_SuggestedFriends", suggestedFriends));
        }
        public async Task <IActionResult> Update(int id, [FromBody] RelationshipViewModel rvm)
        {
            if (rvm != null)
            {
                var relationship = DbContext.Relationships.Where(i => i.Id == id).FirstOrDefault();
                if (relationship != null)
                {
                    // handle the update (on per-property basis)
                    relationship.UserId = await GetCurrentUserId();

                    relationship.Description = rvm.Description;
                    //article.Flags = ivm.Flags;
                    //article.Notes = ivm.Notes;
                    //relationship.Text = rvm.Text;
                    relationship.Title = rvm.Title;
                    //article.Type = ivm.Type;

                    // override any property that could be wise to set from server-side only
                    relationship.LastModifiedDate = DateTime.Now;

                    // persist the changes into the Database.
                    DbContext.SaveChanges();

                    // return the updated article to the client.
                    return(new JsonResult(Mapper.Map <RelationshipViewModel>(relationship), DefaultJsonSettings));
                }
            }

            // return a HTTP Status 404 (Not Found) if we couldn't find a suitable article.
            return(NotFound(new { Error = String.Format("article ID {0} has not been found", id) }));
        }
        public async Task <IActionResult> Add([FromBody] RelationshipViewModel rvm)
        {
            if (rvm != null)
            {
                // create a new article with the client-sent json data
                var relationship = Mapper.Map <Relationship>(rvm);

                // override any property that could be wise to set from server-side only
                relationship.CreatedDate          =
                    relationship.LastModifiedDate = DateTime.Now;

                relationship.UserId = await GetCurrentUserId();

                // add the new article
                DbContext.Relationships.Add(relationship);

                // persist the changes into the Database.
                DbContext.SaveChanges();

                // return the newly-created article to the client.
                return(new JsonResult(Mapper.Map <RelationshipViewModel>(relationship), DefaultJsonSettings));
            }

            // return a generic HTTP Status 500 (Not Found) if the client payload is invalid.
            return(new StatusCodeResult(500));
        }
Ejemplo n.º 10
0
        public void RelationshipViewModel_changes_Model()
        {
            // ARRANGE

            var entity1   = new EntityViewModel(new Entity());
            var entity2   = new EntityViewModel(new Entity());
            var model     = new Relationship("r", new Entity(), new Entity(), new Tag("t", new Facet("f", new FacetProperty("p"))));
            var viewModel = new RelationshipViewModel(model, model.From.ToViewModel(), model.To.ToViewModel(), model.Tags.Single().ToViewModel());

            // ACT

            viewModel.Name = "changed";
            viewModel.From = entity1;
            viewModel.To   = entity2;
            viewModel.Tags.Single().Properties.Single().Value = "changed";

            // ASSERT

            Assert.Equal("changed", viewModel.Name);
            Assert.Equal("changed", model.Name);
            Assert.Equal("changed", model.Values[model.Tags.Single().Facet.Properties.Single().Id.ToString()]);

            Assert.Equal(entity1, viewModel.From);
            Assert.Equal(entity1.Model, model.From);
            Assert.Equal(entity2, viewModel.To);
            Assert.Equal(entity2.Model, model.To);
        }
Ejemplo n.º 11
0
        public void RelationshipEditModel_delays_changes_at_ViewModel()
        {
            // ARRANGE

            var entity1   = new EntityViewModel(new Entity());
            var entity2   = new EntityViewModel(new Entity());
            var model     = new Relationship("r", new Entity(), new Entity(), new Tag());
            var viewModel = new RelationshipViewModel(model, new EntityViewModel(model.From), new EntityViewModel(model.To));
            var editModel = new RelationshipEditModel(viewModel, delegate { }, delegate { });

            // ACT

            editModel.Name = "changed";
            editModel.From = entity1;
            editModel.To   = entity2;

            // ASSERT

            Assert.Equal("changed", editModel.Name);
            Assert.Equal("r", viewModel.Name);
            Assert.Equal("r", model.Name);

            Assert.NotEqual(editModel.From.Model, viewModel.From.Model);
            Assert.NotEqual(editModel.To.Model, viewModel.To.Model);
        }
Ejemplo n.º 12
0
        public PartialViewResult FriendRequestNotification()
        {
            string userID = User.Identity.GetUserId();

            List <RelationshipViewModel> friendRequests = RelationshipViewModel.GetFriendNotifications(userID, RelationshipStatus.Pending);

            return(PartialView("_FriendRequests", friendRequests));
        }
Ejemplo n.º 13
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method disposes of resources in the view model.</summary>
 ///--------------------------------------------------------------------------------
 protected override void OnDispose()
 {
     SourceDiagramEntityViewModel = null;
     SinkDiagramEntityViewModel   = null;
     Diagram = null;
     RelationshipViewModel = null;
     base.OnDispose();
 }
Ejemplo n.º 14
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds relationships for an entity to the view model.</summary>
        ///
        /// <param name="entity">The entity to add.</param>
        ///--------------------------------------------------------------------------------
        public void AddRelationships(DiagramEntityViewModel diagramEntity)
        {
            NameObjectCollection relationshipsAdded = new NameObjectCollection();

            // add relationships this entity is the source of
            foreach (Relationship relationship in diagramEntity.EntityViewModel.Entity.RelationshipList)
            {
                bool isDeletedRelationship = false;
                foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>())
                {
                    if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID)
                    {
                        isDeletedRelationship = true;
                        break;
                    }
                }
                if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null)
                {
                    foreach (DiagramEntityViewModel loopEntity in DiagramEntities)
                    {
                        if (relationship.ReferencedEntityID == loopEntity.EntityViewModel.Entity.EntityID)
                        {
                            RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution);
                            AddRelationship(diagramEntity, loopEntity, relationshipViewModel);
                            relationshipsAdded[relationship.RelationshipID.ToString()] = true;
                        }
                    }
                }
            }

            // add relationships this entity is the sink of
            foreach (DiagramEntityViewModel loopEntity in DiagramEntities)
            {
                foreach (Relationship relationship in loopEntity.EntityViewModel.Entity.RelationshipList)
                {
                    if (relationship.ReferencedEntityID == diagramEntity.EntityViewModel.Entity.EntityID)
                    {
                        bool isDeletedRelationship = false;
                        foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>())
                        {
                            if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID)
                            {
                                isDeletedRelationship = true;
                                break;
                            }
                        }
                        if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null)
                        {
                            RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution);
                            AddRelationship(loopEntity, diagramEntity, relationshipViewModel);
                            relationshipsAdded[relationship.RelationshipID.ToString()] = true;
                        }
                    }
                }
            }

            Refresh(false);
        }
Ejemplo n.º 15
0
        /***************** ACTUAL POSTS ************/
        public PartialViewResult _Newsfeed()
        {
            string        userID      = User.Identity.GetUserId();
            List <string> friendsList = RelationshipViewModel.GetFriendsID(userID);

            friendsList.Add(userID);
            List <NewsFeedViewModel> postList = NewsFeedViewModel.GetNewsFeed(friendsList);

            return(PartialView("_Newsfeed", postList));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Invoked from the class constructor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="routedEventArgs"></param>
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            RelationshipViewModel vm = ((RelationshipViewModel)this.DataContext);

            this.teFName.Validate           += Te_Validate;
            this.teLName.Validate           += Te_Validate;
            this.cbRelationToOwner.Validate += editform_Validate;

            this.teFName.Focus();
        }
        /// <summary>
        /// Get the Data based on ID and return to the model to update view.
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        // [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Write" })]
        public IActionResult Update(int ID)
        {
            RelationshipViewModel model = new RelationshipViewModel();

            model.Relationship = _relationshipService.GetData(ID);

            if (model != null)
            {
                return(View("Index", model));
            }
            else
            {
                return(View("SummaryView", model));
            }
        }
        public GetRelationshipResponse GetContactRelationship(int contactRelationMapID, int accountID)
        {
            GetRelationshipResponse response  = new GetRelationshipResponse();
            RelationshipViewModel   viewModel = new RelationshipViewModel();
            var dropdowns = cachingService.GetDropdownValues(accountID);

            ContactRelationship         relationship     = contactRelationshipRepository.FindBy(contactRelationMapID);
            IList <ContactRelationship> relationshipList = new List <ContactRelationship>();

            relationshipList.Add(relationship);
            viewModel.Relationshipentry    = Mapper.Map <IEnumerable <ContactRelationship>, IEnumerable <RelationshipEntry> >(relationshipList).ToList();
            viewModel.RelationshipTypes    = dropdowns.Where(s => s.DropdownID == (short)DropdownFieldTypes.RelationshipType).Select(s => s.DropdownValuesList).ToList().FirstOrDefault().Where(d => d.IsActive);
            response.RelationshipViewModel = viewModel;
            return(response);
        }
        public ActionResult RelationshipEdit()
        {
            var userId        = User.Identity.GetUserId();
            var userProfile   = _context.UserProfiles.FirstOrDefault(x => x.Id == userId);
            var relationships = _context.Relationships.Where(x => x.UserProfileId == userId);

            if (userProfile != null)
            {
                RelationshipViewModel model = new RelationshipViewModel(relationships);
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Manage", "Profile"));
            }
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Index(RelationshipViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var relationship = await _personService.GetRelationship(model.Name1, model.Name2);

                    model.Relationship = relationship;
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            return(View(model));
        }
        private IEnumerable <RelationshipViewModel> GroupRelationshipsByDescription(IEnumerable <CatalogRelationshipInformation> productRelationshipInfoList)
        {
            var relationshipGroups = new Dictionary <string, RelationshipViewModel>(StringComparer.OrdinalIgnoreCase);

            if (productRelationshipInfoList != null)
            {
                foreach (var relationshipInfo in productRelationshipInfoList)
                {
                    var relationshipDescription = string.IsNullOrWhiteSpace(relationshipInfo.RelationshipDescription) ? GetRelationshipName(relationshipInfo.RelationshipName) : relationshipInfo.RelationshipDescription;
                    RelationshipViewModel relationshipModel;
                    if (!relationshipGroups.TryGetValue(relationshipDescription, out relationshipModel))
                    {
                        relationshipModel = new RelationshipViewModel
                        {
                            Name        = relationshipInfo.RelationshipName,
                            Description = relationshipDescription
                        };

                        relationshipGroups[relationshipDescription] = relationshipModel;
                    }

                    var targetItemId = new ID(relationshipInfo.ToItemExternalId);
                    var targetItem   = Context.Database.GetItem(targetItemId);
                    var productModel = ProductViewModelFactory.Create(targetItem);

                    relationshipModel.ChildProducts.Add(productModel);
                }
            }

            if (relationshipGroups.Count <= 0)
            {
                return(relationshipGroups.Values);
            }

            var productViewModelList = relationshipGroups.Values.SelectMany(v => v.ChildProducts).ToArray();

            if (!productViewModelList.Any())
            {
                return(relationshipGroups.Values);
            }

            CatalogManager.GetProductBulkPrices(productViewModelList);
            InventoryManager.GetProductsStockStatusForList(productViewModelList);

            return(relationshipGroups.Values);
        }
Ejemplo n.º 22
0
        public ActionResult Edit(RelationshipViewModel model)
        {
            var relationship = db.Relationships.FirstOrDefault(h => h.ID == model.ID);

            if (relationship == null)
            {
                throw new Exception("Relationship not found.");
            }

            //Repace the Relationship with the edited Relationship
            db.Relationships.Remove(relationship);
            db.Relationships.Add(Casting.UpCast <Relationship, RelationshipViewModel>(model)); //the upcast prevents all the extra stuff from being saved

            db.Save();
            db = DotADB.Load();
            return(Index());
        }
Ejemplo n.º 23
0
        public void RelationshipViewModel_mirrors_Model()
        {
            // ARRANGE

            var model = new Relationship("r", new Entity(), new Entity(), new Tag());

            // ACT

            var result = new RelationshipViewModel(model, model.From.ToViewModel(), model.To.ToViewModel(), model.Tags.Single().ToViewModel());

            // ASSERT

            Assert.Equal("r", result.Name);
            Assert.Equal(model.From, result.From.Model);
            Assert.Equal(model.To, result.To.Model);
            Assert.Equal(model.Tags.Single(), result.Tags.Single().Tag.Model);
        }
Ejemplo n.º 24
0
        public void RelationshipEditModel_rejects_duplicate_Tags()
        {
            // ARRANGE

            var tagModel  = new Tag();
            var model     = new Relationship("r", new Entity(), new Entity(), tagModel);
            var viewModel = new RelationshipViewModel(model, new EntityViewModel(model.From), new EntityViewModel(model.To), tagModel.ToViewModel());
            var editModel = new RelationshipEditModel(viewModel, delegate { }, delegate { });

            // ACT

            var result = editModel.AssignTagCommand.CanExecute(new TagViewModel(tagModel));

            // ASSERT

            Assert.False(result);
        }
        public void DeleteEntityWithRelationshipsEditModel_shows_Entity_and_Relationship()
        {
            // ARRANGE

            var entity1      = new Entity().ToViewModel();
            var entity2      = new Entity().ToViewModel();
            var relationship = new RelationshipViewModel(new Relationship(), entity1, entity2);

            // ACT

            var result = new DeleteEntityWithRelationshipsEditModel(entity1, relationship.Yield(), delegate { }, delegate { });

            // ASSERT

            Assert.Equal(entity1, result.Entity);
            Assert.Equal(relationship, result.Relationships.Single());
        }
        public List<SelectListItem> RelationshipTypesFor(RelationshipViewModel r)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            foreach (RelationshipTypeViewModel type in Enum.GetValues(typeof(RelationshipTypeViewModel)))
            {
                SelectListItem item = new SelectListItem();
                item.Text = type.GetAttributeValue<DisplayAttribute, string>(t => t.Description);
                item.Value = type.ToString();

                if (type == r.Relationship)
                    item.Selected = true;

                list.Add(item);
            }

            return list;
        }
        public GetRelationshipResponse GetContactRelationships(int contactID)
        {
            GetRelationshipResponse response     = new GetRelationshipResponse();
            RelationshipViewModel   Relationship = new RelationshipViewModel();

            Relationship.Relationshipentry = Mapper.Map <IEnumerable <ContactRelationship>, IEnumerable <RelationshipEntry> >(contactRelationshipRepository.FindContactRelationship(contactID)).ToList();
            foreach (RelationshipEntry entry in Relationship.Relationshipentry)
            {
                if (entry.RelatedContactID == contactID)
                {
                    entry.RelationshipTypeName = "Associated Contact";
                    entry.RelatedContact       = entry.ContactName;
                    entry.RelatedContactID     = entry.ContactId;
                }
            }
            response.RelationshipViewModel = Relationship;
            return(response);
        }
Ejemplo n.º 28
0
        public void RelationshipViewModel_removes_tag_from_Model()
        {
            // ARRANGE

            var entity1   = new EntityViewModel(new Entity());
            var entity2   = new EntityViewModel(new Entity());
            var model     = new Relationship("r", new Entity(), new Entity(), new Tag());
            var viewModel = new RelationshipViewModel(model, model.From.ToViewModel(), model.To.ToViewModel(), model.Tags.Single().ToViewModel());

            // ACT

            viewModel.Tags.Remove(viewModel.Tags.Single());

            // ASSERT

            Assert.Empty(viewModel.Tags);
            Assert.Empty(model.Tags);
        }
Ejemplo n.º 29
0
        public void RelationshipEditModel_mirrors_ViewModel()
        {
            // ARRANGE

            var model     = new Relationship("r", new Entity(), new Entity(), new Tag());
            var viewModel = new RelationshipViewModel(model, new EntityViewModel(model.From), new EntityViewModel(model.To), model.Tags.Single().ToViewModel());

            // ACT

            var result = new RelationshipEditModel(viewModel, delegate { }, delegate { });

            // ASSERT

            Assert.Equal("r", result.Name);
            Assert.Equal(viewModel.From.Model, result.From.Model);
            Assert.Equal(viewModel.To.Model, result.To.Model);
            Assert.Equal(viewModel.Tags.Single().Tag.Model, result.Tags.Single().ViewModel.Tag.Model);
        }
Ejemplo n.º 30
0
        public ActionResult Create(RelationshipViewModel model, bool returnToHeroList = false)
        {
            if (db.Relationships.Any(h => h.ID == model.ID))
            {
                throw new Exception("Relationship ID collision");
            }

            db.Relationships.Add(Casting.UpCast <Relationship, RelationshipViewModel>(model));
            db.Save();

            if (!returnToHeroList)
            {
                return(Index());
            }

            TempData["SelectedHeroID"] = model.Hero1ID;
            return(RedirectToAction("Index", "Hero", new { }));
        }
        public IActionResult AddUpdate(RelationshipViewModel model)
        {
            JsonResponse response = new JsonResponse();

            // If the model valid go to the next level
            if (ModelState.IsValid)
            {
                response = _relationshipService.AddUpdate(model.Relationship);
                return(Json(response));
            }// Else it  shows the error message.
            else
            {
                JsonResponse resp = new JsonResponse
                {
                    Message = Constants.ControllerMessage.All_Fields_Mandatory
                };
                return(Json(resp));
            }
        }