public static List<subcategories> GetAllSubCategoriesByAssociations(associations[] asso) { List<subcategories> subCateList = new List<subcategories>(); foreach (associations a in asso) { foreach (var c in a.categories) { subCateList.AddRange(GetAllSubCategoryByCategory(c)); } } return subCateList; }
//Not: Har inte fått metoden att funka när jag testade den /E public static bool AddAssociationWithWebPage(associations asso, webpages wp) { Context.associations.Add(asso); WebPageDB.AddWebPage(wp); 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; } return true; }
public static bool HasUserPermissionForAssociationWithRole(users u, associations a, string r) { return GetAllAssociationPermissionsByAssociation(a).Any(associationPermission => associationPermission.users.Id == u.Id && associationPermission.Role.Equals(r)); }
public static bool HasUserPermissionForAssociation(users u, associations a) { return GetAllAssociationPermissionsByAssociation(a).Any(associationPermission => associationPermission.users.Id == u.Id); }
// This might not be working correctly! // This might not be working correctly! // This might not be working correctly! public static List<association_permissions> GetAllAssociationPermissionsByAssociation(associations asso) { return GetAllNotDeletedAssociationPermissions().Where(p => p.associations_Id.Equals(asso.Id)).ToList(); }
public static List<events> GetEventsByAssociation(associations asso) { return asso.events.ToList(); }
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; }
public static List<members> GetAllMembersByAssociation(associations asso) { return GetAllNotDeletedMembers().Where(m => m.Associations_Id.Equals(asso.Id)).ToList(); }
public static List<users> GetAllUsersByAssociation(associations a) { var usersInAssociation = new List<users>(); foreach ( var user in AssociationPermissionsDB.GetAllAssociationPermissionsByAssociation(a) .Select(aP => aP.users) .Where(user => !usersInAssociation.Contains(user))) { usersInAssociation.Add(user); } return usersInAssociation; }
// UPDATE public static int UpdateAssociation(associations assoc) { associations assoToUpdate = GetAssociationById(assoc.Id); assoToUpdate.Name = assoc.Name; assoToUpdate.Communities_Id = assoc.Communities_Id; assoToUpdate.ParentAssociationId = assoc.ParentAssociationId; assoToUpdate.Description = assoc.Description; assoToUpdate.categories = assoc.categories; assoToUpdate.association_permissions = assoc.association_permissions; 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; } } Context.Entry(assoToUpdate).Reload(); return affectedRows = 0; } return affectedRows; }
public static List<categories> GetAllCategoriesForAssociationByAssociation(associations a) { List<categories> catList = a.categories.ToList(); return catList; }