Esempio n. 1
0
        //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;
        }
Esempio n. 2
0
        // UPDATE
        public static int UpdateWebPage(webpages wp)
        {
            webpages wpToUpdate = GetWebPageById(wp.Id);

            wpToUpdate.Title = wp.Title;
            wpToUpdate.CommunityId = wp.CommunityId;
            wpToUpdate.AssociationId = wp.AssociationId;
            wpToUpdate.Layout = wp.Layout;
            wpToUpdate.Style = wp.Style;
            wpToUpdate.components = wp.components;
            wpToUpdate.UpdatedBy = wp.UpdatedBy;

            //Context.Entry(wpToUpdate).State = EntityState.Modified;

            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(wpToUpdate).Reload();
            return affectedRows;
        }
Esempio n. 3
0
 public static bool IsWebPageForCommunity(webpages wP)
 {
     return wP.CommunityId != null;
 }
Esempio n. 4
0
 public static bool IsWebPageForAssociation(webpages wP)
 {
     return wP.AssociationId != null;
 }
Esempio n. 5
0
        public static List<controls> GetAllControlsNotInWebpage(webpages wP)
        {
            var controlsNotInWebPage = GetAllControls();
            if (wP != null)
            {
               foreach (var c in wP.components.Where(c => !c.IsDeleted))
            {
                if (GetAllControls().Contains(c.controls))
                {
                    controlsNotInWebPage.Remove(c.controls);
                }
            }
            }

            return controlsNotInWebPage;
        }