/// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(ContributorTypes contributortypes, System.Data.DataSet data)
        {
            // Do nothing if we have nothing
            if (data == null || data.Tables.Count == 0 || data.Tables[0].Rows.Count == 0)
            {
                return;
            }


            // Create a local variable for the new instance.
            ContributorType newobj = null;

            // Create a local variable for the data row instance.
            System.Data.DataRow dr = null;


            // Iterate through the table rows
            for (int i = 0; i < data.Tables[0].Rows.Count; i++)
            {
                // Get a reference to the data row
                dr = data.Tables[0].Rows[i];
                // Create a new object instance
                newobj = System.Activator.CreateInstance(contributortypes.ContainsType[0]) as ContributorType;
                // Let the instance set its own members
                newobj.SetMembers(ref dr);
                // Add the new object to the collection instance
                contributortypes.Add(newobj);
            }
        }
        /// <summary>
        /// Fill method for populating an entire collection of ContributorTypes
        /// </summary>
        public virtual void Fill(ContributorTypes contributorTypes)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(ContributorType.GetConnectionString());


            try
            {
                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectContributorTypes");


                    // Send the collection and data to the object factory
                    CreateObjectsFromData(contributorTypes, datareader);


                    // close the connection
                    cnn.Close();
                }


                // nullify the connection
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Ejemplo n.º 3
0
        private void ExtractDataFromAuthorObject(Author author, ContributorType contributorType, Item authorItem, Item publisherGroupOwner)
        {
            this.populateAuthorItemData(author, authorItem, contributorType, publisherGroupOwner);

            //publish author item
            SitecorePublishHelper sp = new SitecorePublishHelper();

            sp.PublishItem(authorItem, false);
        }
Ejemplo n.º 4
0
        public virtual void AddContributor(Person contributor, ContributorType contributorType)
        {
            if (_contributors.Any(x => x.ContributorId == contributor.Id))
            {
                return;
            }

            _contributors.Add(new Contributor(contributor, contributorType));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Import Authors' data into sitecore and create new items
        /// </summary>
        /// <param name="authos">Authors obejcts generated from XML</param>
        public void ImportAuthorsItemsToSitecore(ContributorType contributorType, ref Book book, ref List <string> ExistingAuthors, Item publisherGroupOwner)
        {
            List <Author> contributors = new List <Author>();

            contributors = contributorType == ContributorType.Author ? book.Authors : book.Illustrators;
            for (int i = 0; i < contributors.Count; i++)
            {
                if (!ExistingAuthors.Contains(contributors[i].DisplayName.Replace(" ", "-")))
                {
                    ExistingAuthors.Add(contributors[i].DisplayName.Replace(" ", "-"));
                    ID id = this.CreateAuthorItemInSitecore(contributors[i], contributorType, publisherGroupOwner);
                    if (!ID.IsNullOrEmpty(id))
                    {
                        contributors[i].SitecoreID = id.ToString();
                    }
                }
                else
                {
                    Item authorItem = masterDb.GetItem(authorFolderItemId).Axes.GetDescendants().FirstOrDefault(c => c.Name == contributors[i].DisplayName.Replace(" ", "-"));
                    BooksImportLog.Info(string.Format("Updating existing author [{0}] with item ID: {1}", contributors[i].DisplayName, authorItem != null ? authorItem.ID.ToString() : ""));

                    this.ExtractDataFromAuthorObject(contributors[i], contributorType, authorItem, publisherGroupOwner);
                    ID id = authorItem.ID;
                    contributors[i].SitecoreID = id.ToString();
                    if (!authorItem.Fields["ContributorType"].Value.Contains(contributorType.ToString()))
                    {
                        authorItem.Editing.BeginEdit();
                        try
                        {
                            authorItem.Fields["ContributorType"].Value += string.Format(",{0}", contributorType.ToString());
                        }
                        catch (Exception ex)
                        {
                            BooksImportLog.Error("There is an error when trying to populate data for author " + contributors[i].DisplayName + "into item" + authorItem.ID.ToString(), ex);
                        }
                        finally
                        {
                            authorItem.Editing.EndEdit();

                            BooksImportLog.Info(string.Format("Populated data for author [{0}] with item ID: {1}", contributors[i].DisplayName, authorItem != null ? authorItem.ID.ToString() : ""));
                        }
                    }
                }
                Thread.Sleep(100);
            }
            if (contributorType == ContributorType.Author)
            {
                book.Authors = contributors;
            }
            else
            {
                book.Illustrators = contributors;
            }
        }
Ejemplo n.º 6
0
        public BsJsonResult New(ContributorNewModel model, ContributorType tabId)
        {
            var status = BsResponseStatus.Success;
            var row    = string.Empty;
            var msg    = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    var rowModel = repo.Create(model);

                    var groupEditorModel = new GroupEditorModel
                    {
                        Developers = new BsEditorTabModel <ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                        {
                            Grid = new BsGridModel <ContributorRowModel>
                            {
                                Items = new List <ContributorRowModel>
                                {
                                    rowModel
                                }
                            }
                        }
                    };

                    var viewModel = new GroupEditorViewModel()
                    {
                        Editor = groupEditorModel
                    };

                    row = this.BsRenderPartialView("_Editors", viewModel);
                }
                else
                {
                    return(new BsJsonResult(
                               new Dictionary <string, object> {
                        { "Errors", ModelState.GetErrors() }
                    },
                               BsResponseStatus.ValidationError));
                }
            }
            catch (Exception ex)
            {
                msg    = Resource.ServerError;
                status = BsResponseStatus.ServerError;
            }

            return(new BsJsonResult(new
            {
                Row = row
            }, status, msg));
        }
        public void UpdateContributorType(ContributorType contributorType)
        {
            var result = _context.ContributorTypes.SingleOrDefault(x => x.ID == contributorType.ID);

            if (result != null)
            {
                result.Name        = contributorType.Name;
                result.Title       = contributorType.Title;
                result.Description = contributorType.Description;
                _context.SaveChanges();
            }
        }
        /// <summary>
        /// Deletes the object.
        /// </summary>
        public virtual void Delete(ContributorType deleteObject)
        {
            // create a new instance of the connection
            SqlConnection cnn = new SqlConnection(ContributorType.GetConnectionString());
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;


            try
            {
                // discover the parameters
                sqlparams = SqlHelperParameterCache.GetSpParameterSet(ContributorType.GetConnectionString(), "gsp_DeleteContributorType");


                // Store the parameter for the Id attribute.
                sqlparams["@id"].Value = deleteObject.Id;


                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // Execute the stored proc to perform the delete on the instance.
                    SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_DeleteContributorType", sqlparams);


                    // close the connection after usage
                    cnn.Close();
                }


                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }


            // nullify the reference
            deleteObject = null;
        }
Ejemplo n.º 9
0
        public BsJsonResult Search(ContributorSearchModel model, ContributorType tabId)
        {
            var settings = new BsEditorRepositorySettings <ContributorType>
            {
                Search = model,
                TabId  = tabId
            };

            var count = 0;

            var html = this.RenderTab(settings, out count);

            return(new BsJsonResult(new
            {
                Count = count,
                Html = html
            }));
        }
        /// <summary>
        /// Fills a single instance with data based on its primary key values.
        /// </summary>
        public virtual void Fill(ContributorType ct, System.Int16 id)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(ContributorType.GetConnectionString());

            try
            {
                // discover the sql parameters
                SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(ContributorType.GetConnectionString(), "gsp_SelectContributorType");


                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // set the parameters
                    sqlparams["@id"].Value = id;


                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectContributorType", sqlparams);


                    if (datareader.Read())
                    {
                        ct.SetMembers(ref datareader);
                    }


                    cnn.Close();                     // close the connection
                }


                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create a sigle author item in sitecore
        /// </summary>
        /// <param name="author">Author object generated from XML</param>
        private ID CreateAuthorItemInSitecore(Author author, ContributorType contributorType, Item publisherGroupOwner)
        {
            try
            {
                using (new SecurityDisabler())
                {
                    Item authorItem = SitecoreCreationHelper.CreateBranchItem(author.DisplayName, masterDb, authorItemTemplateId, authorFolderItemId);
                    BooksImportLog.Info(string.Format("Created new author [{0}] with item ID: {1}", author.PersonNameInverted, authorItem != null ? authorItem.ID.ToString() : ""));

                    this.ExtractDataFromAuthorObject(author, contributorType, authorItem, publisherGroupOwner);

                    return(authorItem.ID);
                }
            }
            catch (Exception ex)
            {
                BooksImportLog.Error("There is an error when trying to import author " + author.PersonNameInverted, ex);
                return(null);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// populate author data with the author object into sitecore
        /// </summary>
        /// <param name="author">Author object generated from XML</param>
        /// <param name="authorItem">Sitecore author item</param>
        private void populateAuthorItemData(Author author, Item authorItem, ContributorType contributorType, Item publisherGroupOwner)
        {
            authorItem.Editing.BeginEdit();
            try
            {
                authorItem.Fields["KeyNames"].Value           = author.KeyNames;
                authorItem.Fields["NamesBeforeKey"].Value     = author.NamesBeforeKey;
                authorItem.Fields["PersonName"].Value         = author.PersonName;
                authorItem.Fields["PersonNameInverted"].Value = author.PersonNameInverted;
                authorItem.Fields["BiographicalNote"].Value   = HtmlHelper.RemoveHtmlTags(author.BiographicalNote, new List <string> {
                    "div", "span"
                });
                if (!((Sitecore.Data.Fields.CheckboxField)authorItem.Fields["DisableOverridePublishingGroupOwner"]).Checked)
                {
                    if (publisherGroupOwner != null)
                    {
                        authorItem.Fields["PublishingGroupOwner"].Value = publisherGroupOwner.ID.ToString();
                    }
                }
                authorItem.Fields["ContributorType"].Value = contributorType.ToString();
                authorItem.Fields["CorporateName"].Value   = author.CorporateName;
                authorItem.Fields["MetaTitle"].Value       = string.Format("{0} | Hardie Grant Publishing",
                                                                           string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName);
                authorItem.Fields["MetaDescription"].Value = string.Format("{0} | {1} Hardie Grant Publishing",
                                                                           string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName,
                                                                           string.IsNullOrWhiteSpace(author.BiographicalNote) ? "" : getFormattedAuthorDescription(author.BiographicalNote) + "|");
                authorItem.Fields["MetaKeywords"].Value = string.Format("{0}, {1}, Hardie Grant Publishing",
                                                                        string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName,
                                                                        publisherGroupOwner == null ? "" : publisherGroupOwner["Name"]);
            }
            catch (Exception ex)
            {
                BooksImportLog.Error("There is an error when trying to populate data for author " + author.DisplayName + "into item" + authorItem.ID.ToString(), ex);
            }
            finally
            {
                authorItem.Editing.EndEdit();

                BooksImportLog.Info(string.Format("Updated data for author [{0}] with item ID: {1}", author.DisplayName, authorItem != null ? authorItem.ID.ToString() : ""));
            }
        }
        /// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(ContributorTypes contributortypes, System.Data.SqlClient.SqlDataReader data)
        {
            // Do nothing if we have nothing
            if (data == null)
            {
                return;
            }


            // Create a local variable for the new instance.
            ContributorType newobj = null;

            // Iterate through the data reader
            while (data.Read())
            {
                // Create a new object instance
                newobj = System.Activator.CreateInstance(contributortypes.ContainsType[0]) as ContributorType;
                // Let the instance set its own members
                newobj.SetMembers(ref data);
                // Add the new object to the collection instance
                contributortypes.Add(newobj);
            }
        }
Ejemplo n.º 14
0
 public Contributor(string id, string name, ContributorType contribution)
 {
     ContributorId = id;
     Name          = name;
     Contribution  = contribution;
 }
Ejemplo n.º 15
0
 public Contributor(Person person, ContributorType contribution)
     : this(person.Id, person.Name, contribution)
 {
 }
Ejemplo n.º 16
0
        public BsJsonResult Search(ContributorSearchModel model, ContributorType tabId)
        {
            var settings = new BsEditorRepositorySettings<ContributorType>
            {
                Search = model,
                TabId = tabId
            };

            var count = 0;

            var html = this.RenderTab(settings, out count);

            return new BsJsonResult(new
            {
                Count = count,
                Html = html
            });
        }
Ejemplo n.º 17
0
        public BsJsonResult New(ContributorNewModel model, ContributorType tabId)
        {
            var status = BsResponseStatus.Success;
            var row = string.Empty;
            var msg = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    var rowModel = repo.Create(model);

                    var groupEditorModel = new GroupEditorModel
                    {
                        Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                        {
                            Grid = new BsGridModel<ContributorRowModel>
                            {
                                Items = new List<ContributorRowModel>
                                {
                                    rowModel
                                }
                            }
                        }
                    };

                    var viewModel = new GroupEditorViewModel()
                    {
                        Editor = groupEditorModel
                    };

                    row = this.BsRenderPartialView("_Editors", viewModel);

                }
                else
                {
                    return new BsJsonResult(
                        new Dictionary<string, object> { { "Errors", ModelState.GetErrors() } },
                        BsResponseStatus.ValidationError);
                }
            }
            catch (Exception ex)
            {
                msg = Resource.ServerError;
                status = BsResponseStatus.ServerError;
            }

            return new BsJsonResult(new
            {
                Row = row
            }, status, msg);
        }
 public void CreateContributorType(ContributorType contributorType)
 {
     _context.ContributorTypes.Add(contributorType);
     _context.SaveChanges();
 }
 /// <summary>
 /// Persists the object.
 /// </summary>
 public virtual void Persist(ContributorType persistObject)
 {
     // Make a call to the overloaded method with a null transaction
     Persist(persistObject, null);
 }
        /// <summary>
        /// Persists the object.
        /// </summary>
        public virtual void Persist(ContributorType persistObject, SqlTransaction sqlTrans)
        {
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;
            // Create a local variable for the connection
            SqlConnection cnn = null;


            // Use the parameter overload or create a new instance
            if (sqlTrans == null)
            {
                cnn = new SqlConnection(ContributorType.GetConnectionString());
            }


            try
            {
                // discover the parameters
                if (persistObject.Persisted)
                {
                    sqlparams = SqlHelperParameterCache.GetSpParameterSet(ContributorType.GetConnectionString(), "gsp_UpdateContributorType");
                }
                else
                {
                    sqlparams = SqlHelperParameterCache.GetSpParameterSet(ContributorType.GetConnectionString(), "gsp_CreateContributorType");
                }


                // Store the parameter for the Name attribute.
                sqlparams["@name"].Value = persistObject.Name;
                // Store the parameter for the EnumeratedName attribute.
                sqlparams["@enumeratedName"].Value = persistObject.EnumeratedName;
                // Store the parameter for the Description attribute.
                if (!persistObject.DescriptionIsNull)
                {
                    sqlparams["@description"].Value = persistObject.Description;
                }
                // Store the parameter for the Id attribute.
                sqlparams["@id"].Value = persistObject.Id;
                if (!persistObject.Persisted)
                {
                    // store the create only (historical fixed) values
                }
                else
                {
                    // store the update only (historical changeable) values
                }


                if (sqlTrans == null)
                {
                    // Process using the isolated connection
                    using (cnn)
                    {
                        // open the connection
                        cnn.Open();


                        if (!persistObject.Persisted)
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_CreateContributorType", sqlparams);
                        }
                        else
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_UpdateContributorType", sqlparams);
                        }


                        // close the connection after usage
                        cnn.Close();
                    }


                    // nullify the connection var
                    cnn = null;
                }
                else
                {
                    // Process using the shared transaction
                    if (!persistObject.Persisted)
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_CreateContributorType", sqlparams);
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_UpdateContributorType", sqlparams);
                    }
                }
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }