Esempio n. 1
0
        //ADD
        public static bool AddCommunity(communities comm)
        {
            Context.communities.Add(comm);
            try
            {
                Context.SaveChanges();
            }
            catch (DbUpdateException dbEx)
            {
                return false;
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult item in ex.EntityValidationErrors)
                {
                    // Get entry

                    DbEntityEntry entry = item.Entry;
                    string entityTypeName = entry.Entity.GetType().Name;

                    // Display or log error messages

                    foreach (DbValidationError subItem in item.ValidationErrors)
                    {
                        string message = string.Format("Error '{0}' occurred in {1} at {2}",
                                 subItem.ErrorMessage, entityTypeName, subItem.PropertyName);
                        Console.WriteLine(message);
                    }
                    // Rollback changes

                    switch (entry.State)
                    {
                        case EntityState.Added:
                            entry.State = EntityState.Detached;
                            break;
                        case EntityState.Modified:
                            entry.CurrentValues.SetValues(entry.OriginalValues);
                            entry.State = EntityState.Unchanged;
                            break;
                        case EntityState.Deleted:
                            entry.State = EntityState.Unchanged;
                            break;
                    }
                }

                return false;
            }
            Context.Entry(comm).Reload();
            return true;
        }
Esempio n. 2
0
 public static List<events> GetEventsByCommunity(communities comm)
 {
     return comm.events.ToList();
 }
Esempio n. 3
0
        public static List<events> FilterEvents(DateTime? sT, DateTime? eT, communities c, associations a, categories cat, subcategories subCat, string word)
        {
            List<events> resultList = GetAllEvents();

            if (sT != null)
            {
                resultList = resultList.Where(e => e.StartDate >= sT).ToList();
            }

            if (eT != null)
            {
                resultList = resultList.Where(e => e.EndDate <= eT).ToList();
            }

            if (c != null)
            {

                var preResultList = new List<events>();

                preResultList.AddRange(resultList.Where(e => e.communities.Contains(c)).ToList());

                List<events> list = resultList;
                foreach (var ev in c.associations.SelectMany(asso => list.Where(e => e.associations.Contains(asso)).Where(ev => !preResultList.Contains(ev))))
                {
                    preResultList.Add(ev);
                }

                resultList = preResultList;
            }

            if (a != null)
            {
                resultList = resultList.Where(e => e.associations.Contains(a)).ToList();
            }

            if (cat != null)
            {
                List<events> eventsInAsso = new List<events>();
                foreach (var asso in cat.associations)
                {
                        eventsInAsso.AddRange(resultList.Where(e => e.associations.Contains(asso)));
                }

                resultList = eventsInAsso;

            }

            if (subCat != null)
            {
                resultList = resultList.Where(e => e.subcategories.Contains(subCat)).ToList();
            }

            if (!String.IsNullOrWhiteSpace(word))
            {
                resultList = GetEventsFromListBySearchWord(resultList, word);
            }

            return resultList;
        }
 //private List<communities> FilterDropDownCommItems(associations a)
 //{
 //}
 private List<associations> FilterDropDownAssoItems(communities c)
 {
     PopulateDropDownAsso(AssociationDB.GetAllAssociationsInCommunity(c));
     return AssociationDB.GetAllAssociationsInCommunity(c).ToList();
 }
        // Still in use vvv (optimize/merge)
        public List<events> RenderEventList(communities comm)
        {
            List<events> eventList = new List<events>();
            if (comm != null)
            {
                eventList = EventDB.GetEventsByCommunity(comm).Where(e => !e.IsDeleted).ToList();

                GridViewEventList.DataSource = eventList.OrderBy(e => e.StartDate);
                GridViewEventList.DataBind();

                return eventList;
            }
                return RenderEventList();
        }
 public communities GetCommunityFromQueryStringsAndSelectInDropDown()
 {
     communities comm = new communities();
     //Hämtar WebPageId från URL.
     var stId = Request.QueryString["Id"];
     int id;
     //Om Id värdet som tas från URLn är i giltigt format hämtas WebPage objektet och visas på sidan.
     if (!string.IsNullOrWhiteSpace(stId) && int.TryParse(stId, out id))
     {
         webpages webPage = WebPageDB.GetWebPageById(id);
         if (webPage != null)
         {
             if (webPage.CommunityId != null)
             {
                 comm = CommunityDB.GetCommunityById(webPage.CommunityId.GetValueOrDefault());
                 if (comm != null)
                 {
                     DropDownListComm.SelectedIndex =
                         DropDownListComm.Items.IndexOf(
                             DropDownListComm.Items.FindByValue(
                                 comm.Id.ToString()));
                 }
                 else
                 {
                     DropDownListComm.SelectedIndex = DropDownListComm.Items.IndexOf(
                         DropDownListComm.Items.FindByValue(""));
                 }
             }
         }
     }
     return comm;
 }
 public static bool HasUserPermissionForCommunityWithRole(users u, communities c, string r)
 {
     return GetAllCommunityPermissionsByCommunity(c).Any(cP => cP.users.Id == u.Id && cP.Role.Equals(r));
 }
 public static bool HasUserPermissionForCommunity(users u, communities c)
 {
     return GetAllCommunityPermissionsByCommunity(c).Any(cP => cP.users.Id == u.Id);
 }
 public static List<community_permissions> GetAllCommunityPermissionsByCommunity(communities comm)
 {
     return GetAllNotDeletedCommunityPermissions().Where(p => p.communities_Id.Equals(comm.Id)).ToList();
 }
Esempio n. 10
0
 public static List<users> GetAllUsersByCommunity(communities c)
 {
     var usersInCommunity = new List<users>();
     foreach (
         var user in
             CommunityPermissionsDB.GetAllCommunityPermissionsByCommunity(c)
                 .Select(aP => aP.users)
                 .Where(user => !usersInCommunity.Contains(user)))
     {
         usersInCommunity.Add(user);
     }
     return usersInCommunity;
 }
Esempio n. 11
0
 public static List<associations> GetAllAssociationsInCommunity(communities com)
 {
     return GetAllNotDeletedAssociations().Where(a => a.communities.Equals(com)).ToList();
 }
Esempio n. 12
0
        // UPDATE
        public static int UpdateCommunity(communities comm)
        {
            communities commToUpdate = GetCommunityById(comm.Id);

            commToUpdate.Name = comm.Name;
            commToUpdate.Description = comm.Description;
            int affectedRows;

            try
            {
                affectedRows = Context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult item in ex.EntityValidationErrors)
                {
                    // Get entry

                    DbEntityEntry entry = item.Entry;
                    string entityTypeName = entry.Entity.GetType().Name;

                    // Display or log error messages

                    foreach (DbValidationError subItem in item.ValidationErrors)
                    {
                        string message = string.Format("Error '{0}' occurred in {1} at {2}",
                                 subItem.ErrorMessage, entityTypeName, subItem.PropertyName);
                        Console.WriteLine(message);
                    }
                    // Rollback changes

                    switch (entry.State)
                    {
                        case EntityState.Added:
                            entry.State = EntityState.Detached;
                            break;
                        case EntityState.Modified:
                            entry.CurrentValues.SetValues(entry.OriginalValues);
                            entry.State = EntityState.Unchanged;
                            break;
                        case EntityState.Deleted:
                            entry.State = EntityState.Unchanged;
                            break;
                    }
                }

                return affectedRows = 0;
            }
            Context.Entry(commToUpdate).Reload();
            return affectedRows;
        }
        // För att skapa en ny community
        protected void ButtonCreateComm_OnClick(object sender, EventArgs e)
        {
            bool isUniqueName = true;

            //Kontrollera att namnet inte redan finns
            foreach (communities commChecking in CommunityDB.GetAllCommunities())
            {
                if (commChecking.Name == TextBoxCommNameCreate.Text)
                {
                    isUniqueName = false;
                }
            };

            if (!isUniqueName)
            {
                LabelCreateComm.Text = "Community was not created. A community with the same name already exists. ";
                LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                return;
            }

                var comm = new communities
                {
                    Name = TextBoxCommNameCreate.Text,
                    LogoUrl = TextBoxCommLogoUrl.Text,
                    CreatedBy = HttpContext.Current.User.Identity.Name,
                    UpdatedBy = HttpContext.Current.User.Identity.Name
                };

                if (CommunityDB.AddCommunity(comm))
                {
                    webpages wp = new webpages
                    {
                        Title = TextBoxCommNameCreate.Text,
                        CommunityId = CommunityDB.GetCommunityByName(comm.Name).Id,
                        //Layout och style - fixa dropdownlistor senare!
                        CreatedBy = HttpContext.Current.User.Identity.Name,
                        UpdatedBy = HttpContext.Current.User.Identity.Name
                    };

                    if (WebPageDB.AddWebPage(wp))
                    {
                        components compCal = new components
                        {
                            webpages_Id = wp.Id,
                            OrderingNumber = 1,
                            controls_Id = 3 //Calendar
                        };

                        components compAbout = new components
                        {
                            webpages_Id = wp.Id,
                            OrderingNumber = 2,
                            controls_Id = 1 //About
                        };

                        if (ComponentDB.AddComponent(compCal) && ComponentDB.AddComponent(compAbout))
                        {
                            MultiViewCommDetails.ActiveViewIndex = 0;
                            MultiViewCommCreate.ActiveViewIndex = -1;
                            ShowCommunityDetails(CommunityDB.GetCommunityByName(comm.Name));
                        }
                        else
                        {
                            LabelCreateComm.Text = "Components could not be created. Please try again!";
                            LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                        }
                    }
                    else
                    {
                        LabelCreateComm.Text = "Webpage could not be created. Try again!";
                        LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                    }

                    //Välj admin för communityn som skapas
                    if (UserDB.GetUserByUsername(ddlAdminUser.SelectedValue) != null)
                    {
                        community_permissions cP = new community_permissions
                        {
                            users_Id = UserDB.GetUserByUsername(ddlAdminUser.SelectedValue).Id,
                            communities_Id = CommunityDB.GetCommunityByName(comm.Name).Id, //comm.Id
                            Role = "Administrators"
                        };
                        CommunityPermissionsDB.AddCommunityPermissions(cP);

                        if (!Roles.IsUserInRole(ddlAdminUser.SelectedValue, "Administrators"))
                        {
                            Roles.AddUserToRole(ddlAdminUser.SelectedValue, "Administrators");
                        }
                    }
                }
                else
                {
                    LabelCreateComm.Text = "Community could not be created. Try again!";
                    LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                }

            PopulateCommunityDropDownList(DropDownListCommunity);
            ListBoxAsso.Items.Clear();
            LabelCommSave.Text = string.Empty; //Use string.Empty instead of "". ALWAYS.
        }
        public void ShowCommunityDetails(communities comm)
        {
            // Visa Community Name i textboxen och i rubrik över föreningslista
            TextBoxCommName.Text = comm.Name;
            TextBoxCommDescript.Text = comm.Description ?? "";
            TextBoxCommLogoImgUrl.Text = comm.LogoUrl ?? "~/Images/Community.jpg";
            LabelAssoInComm.Text = "Associations in " + comm.Name;
            LabelAssoInComm.Style.Add(HtmlTextWriterStyle.Color, "black");

            // Visa Community logga med länk innehållande tooltip
            ImageLogoCommunity.ImageUrl = comm.LogoUrl ?? "~/Images/Community.jpg";
            HyperLinkLogoCommunity.NavigateUrl =
                "/SitePage.aspx?id=" +
                (WebPageDB.GetWebPageByCommunityId(comm.Id) != null
                    ? WebPageDB.GetWebPageByCommunityId(comm.Id).Id.ToString()
                    : "") + "&type=C";
            HyperLinkLogoCommunity.Target = "_blank";
            HyperLinkLogoCommunity.ToolTip = "This link goes to the web page of " +
                                             comm.Name + ". (^-^)v";

            // Visa Created och Created By
            LabelCreated.Text = "<b>Created: </b>" +
                                CommunityDB.GetCommunityById(comm.Id)
                                    .Created.ToShortDateString();

            LabelCreatedBy.Text = "<b>Created by: </b>" +
                                  CommunityDB.GetCommunityById(comm.Id)
                                      .CreatedBy;
        }