Provides a data summary class for creating and saving relationship details.
Ejemplo n.º 1
0
        /// <summary>
        /// Adds the page to the database.
        /// </summary>
        /// <param name="model">The summary details for the page.</param>
        /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns>
        /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public RelViewModel AddRel(RelViewModel model)
        {
            try
            {
                string currentUser = _context.CurrentUsername;

                Relationship rel = new Relationship();
                rel.id = model.id;
                rel.username = currentUser;
                rel.orgID = Repository.GetOrgByUser(currentUser).Id;
                rel.pageId = model.pageID;
                rel.relTypeId = model.relTypeID;
                rel.relText = model.reltext;

                Relationship newrel = Repository.AddNewRel(rel, rel.relTypeId, currentUser, rel.orgID, rel.pageId, rel.relText);

                return model;
            }
            catch (DatabaseException e)
            {
                throw new DatabaseException(e, "An error occurred while adding relationship '{0}' to the database", model.id);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds all relationships related to the page.
        /// </summary>
        /// <param name="id">The pageid to search for.</param>
        /// <returns>A <see cref="IEnumerable{PageViewModel}"/> of pages tagged with the provided tag.</returns>
        /// <exception cref="DatabaseException">An database error occurred while getting the list.</exception>
        public IEnumerable<RelViewModel> GetRelByPage(int pageid)
        {
            try
            {

                IEnumerable<Relationship> relsList = Repository.GetRelByPage(pageid).ToList();
                List<RelViewModel> rels = new List<RelViewModel>();

                foreach (Relationship rel in relsList)
                {


                    RelViewModel relModel = new RelViewModel(rel);
                    int index = rels.IndexOf(relModel);

                    rels.Add(relModel);
   
                }

                return rels;
            }
            catch (DatabaseException ex)
            {
                throw new DatabaseException(ex, "An error occurred finding the tag '{0}' in the database", pageid);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the provided relationship.
        /// </summary>
        /// <param name="model">The summary.</param>
        /// <exception cref="DatabaseException">An databaseerror occurred while updating.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public void UpdateRel(RelViewModel model)
        {
            try
            {
                string currentUser = _context.CurrentUsername;

                Relationship rel = Repository.GetRelById(model.id);
                rel.id = model.id;
                rel.username = currentUser;
                rel.orgID = model.orgID;
                rel.pageId = model.pageID;
                rel.relTypeId = model.relTypeID;
                rel.relText = model.reltext;
                rel.relDateTime = DateTime.Now;

                Repository.SaveOrUpdateRel(rel);

            }
            catch (DatabaseException ex)
            {
                throw new DatabaseException(ex, "An error occurred updating the relationship with id '{0}' in the database", model.id);
            }
        }        
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves the page by its id.
        /// </summary>
        /// <param name="id">The id of the page</param>
        /// <returns>A <see cref="PageViewModel"/> for the page.</returns>
        /// <exception cref="DatabaseException">An databaseerror occurred while getting the page.</exception>
        public RelViewModel GetRelById(int id, bool loadContent = false)
        {
            try
            {
                RelViewModel relModel = new RelViewModel();

                Relationship rel = Repository.GetRelById(id);

                relModel = new RelViewModel(rel);

                return relModel;

            }
            catch (DatabaseException ex)
            {
                throw new DatabaseException(ex, "An error occurred getting the page with id '{0}' from the database", id);
            }
        }
Ejemplo n.º 5
0
        public ActionResult New(RelViewModel model)
		{
			if (!ModelState.IsValid)
                return View("Relationship", "Relationship", model);

			model = _relService.AddRel(model);

            return RedirectToAction("Index", "Wiki", new { id = model.pageID });
		}
Ejemplo n.º 6
0
        public ActionResult New(string pageID)		{
                      
            RelViewModel model = new RelViewModel();
            model.pageID = Convert.ToInt32(pageID);

            if (Request.IsAjaxRequest())
            {
                return PartialView("Relationship", model);
            }
            else
            {
                return View("Relationship", model);
            }
		}