Ejemplo n.º 1
0
        /// <summary>
        ///Create a column  site based on a class
        /// </summary>
        /// <param name="web"></param>
        /// <param name="groupTerm"></param>
        /// <param name="genericClass"></param>
        /// <returns></returns>
        public static IList<ConfigurationColumn> CreateColumnSite(this SPWeb web, string groupTerm, Type genericClass)
        {
            var result = new List<ConfigurationColumn>();
            try
            {
                var props = genericClass.GetProperties();
                foreach (var prop in props)
                {
                    var fieldType = "Text";
                    var create = true;
                    var choice = new StringCollection();
                    var term = string.Empty;
                    var displayName = string.Empty;
                    var hidden = false;
                    var multiValue = false;
                    var required = false;                    
                    var groupTermTaxonomy = string.Empty;
                    var defaultValue = string.Empty;
                    var addPrefix = true;
                    var formula = string.Empty;
                    var formatCurrency = 0;
                    var date = TypeDate.DateTime;

                    foreach (var enmarcha in prop.GetCustomAttributes(true).Select(attribute => attribute as EnmarchaAttribute))
                    {
                        fieldType = enmarcha.Type.ToString();
                        create = enmarcha.Create;
                        term = enmarcha.Term;
                        multiValue = enmarcha.MultiValue;
                        displayName = enmarcha.DisplayName;
                        hidden = enmarcha.Hidden;
                        required = enmarcha.Required;
                        formula = enmarcha.Formula;

                        try
                        {
                            groupTermTaxonomy = enmarcha.Group;
                            addPrefix = enmarcha.AddPrefeix;
                            defaultValue = enmarcha.ValueDefault;
                            date = enmarcha.Date;
                            formatCurrency = enmarcha.FormatCurrency;

                        }

                        catch (Exception exception)
                        {

                            Logger.Error(string.Concat("ENMARCHA Error :", exception.Message));
                        }
                        result.Add(new ConfigurationColumn { Name = prop.Name, Prefix = addPrefix });
                        try
                        {
                            if (enmarcha.Choice != null)
                            {
                                choice.AddRange(enmarcha.Choice);
                            }
                        }
                        catch (Exception exception)
                        {
                            Logger.Error(string.Concat("Error :", exception.Message));
                        }
                    }

                    if (create)
                    {

                        CreateColumnSite(new ParamsCreateSite
                        {
                            Web = web,
                            Name = prop.Name,
                            FieldType = fieldType,
                            Requiered = required,
                            DefaultValue = defaultValue,
                            Choice = choice,
                            Group = groupTerm,
                            Term = term,
                            MultiValue = multiValue,
                            DisplayName = displayName,
                            Hidden = hidden,
                            GroupTerm = groupTermTaxonomy,
                            AddPrefix = addPrefix,
                            Formula = formula,
                            FormatCurrency = formatCurrency,
                            Date = date,                            
                        });
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return de user exist in group
        /// </summary>
        /// <param name="web"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public static IList<UserSP> GetUserInGroup(this SPWeb web, string groupName)
        {
            try
            {
                IList<UserSP> resultUser = null;
                var groups = web.SiteGroups;
                var groupSP = groups[groupName];
                var collecctionUser = groupSP.Users;
                if (collecctionUser.Count > 0)
                {
                    resultUser = new List<UserSP>();
                }
                foreach (SPUser user in collecctionUser)
                {
                    resultUser.Add(new UserSP
                    {
                        Key = user.ID.ToString(),
                        LoginName = user.LoginName,
                        Value = user.Name
                    });
                }

                return resultUser;
            }
            catch (Exception exception)
            {
                Logger.Error(string.Concat("Error GetUserInGroup:", exception.Message));
                return null;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Get Groups by User
 /// </summary>
 /// <param name="site"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static ICollection<UserSP> GetGroupByUser(this SPSite site, string userId)
 {
     var result = new List<UserSP>();
     var spWeb = site.RootWeb;
     var groupCollection = spWeb.EnsureUser(userId).Groups;
     result.AddRange(from SPGroup @group in groupCollection
                     select new UserSP
                     {
                         Key = @group.ID.ToString(),
                         LoginName = @group.LoginName,
                         Value = @group.Name
                     });
     return result.Any() ? result : null;
 }
Ejemplo n.º 4
0
        ///<summary>
        /// Get the User's Groups
        ///</summary>
        ///<param name="web"></param>        
        public static IList<SPGroup> GetGroupsUser(this SPWeb web)
        {
            IList<SPGroup> groupCollection = new List<SPGroup>();

            foreach (SPGroup group in web.SiteGroups)
            {
                if (group.ContainsCurrentUser)
                {
                    groupCollection.Add(group);
                }
            }
            return groupCollection;
        }
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var site = properties.Feature.Parent as SPSite;
            var web = site.RootWeb;
            ILog log = new LogManager().GetLogger(new StackTrace().GetFrame(0)); ;
            var columnSiteCollection = web.CreateColumnSite("Image Galery", typeof(ImageGallery));
            web.CreateContentType(Constants.ContentType.ImageGallery, "Enmarcha ContentType", "Elemento", columnSiteCollection);
            web.CreateList(Constants.List.ImageGallery, "Lista de la galeria de imagenes", TypeList.GenericList, true);
            var list = web.Lists.TryGetList(Constants.List.ImageGallery);
            if (list != null)
            {
                list.AddContentTypeLibrary("Image Galery");
                var repository = new SharePointRepository<ImageGallery>(web, log, Constants.List.ImageGallery, 40);
                IList<ImageGallery> collection = new List<ImageGallery>
                {
                    new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/01.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/01.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                       new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/02.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/02.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                          new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/03.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/03.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                             new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/04.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/04.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/05.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/05.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                   new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/06.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/06.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                      new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/07.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/07.jpg" },
                    OpenWindows = true,
                    Visible = true
                },   new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/08.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/08.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/09.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/09.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/10.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/10.jpg" },
                    OpenWindows = true,
                    Visible = true
                }
                                         ,
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/11.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/11.jpg" },
                    OpenWindows = true,
                    Visible = true
                }
                                         ,
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/12.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/12.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/09.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/09.jpg" },
                    OpenWindows = true,
                    Visible = true
                }

                };
                foreach (var element in collection)
                {
                    repository.Insert(element);
                }


            }
        }