Пример #1
0
        public static int Create(WidgetContainer m_Container)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "INSERT INTO CMS_WidgetContainers(name) VALUES(@name)";
            SqlCommand insertContainer = new SqlCommand(queryString, conn);
            insertContainer.Parameters.AddWithValue("name", m_Container.Name);
            insertContainer.ExecuteNonQuery();

            queryString = "SELECT IDENT_CURRENT('CMS_WidgetContainers')";
            SqlCommand getPageId = new SqlCommand(queryString, conn);
            int m_ContainerId = (int)(decimal)getPageId.ExecuteScalar();

            conn.Close();

            foreach (int widget in m_Container.MyWidgets)
            {
                conn.Open();

                int sortOrder = getSortOrder(m_ContainerId);

                queryString = "INSERT INTO CMS_ContainerToWidgets(containerId, widgetId, sortOrder) VALUES(@containerId, @widgetId, @sortOrder)";
                SqlCommand insertInfo = new SqlCommand(queryString, conn);
                insertInfo.Parameters.AddWithValue("containerId", m_ContainerId);
                insertInfo.Parameters.AddWithValue("widgetId", widget);
                insertInfo.Parameters.AddWithValue("sortOrder", sortOrder);

                insertInfo.ExecuteNonQuery();

                conn.Close();
            }

            return m_ContainerId;
        }
 public ActionResult ContainerAdd(WidgetContainer m_Container)
 {
     if (ModelState.IsValid)
     {
         int containerId = WidgetContainerRepository.Create(m_Container);
         return RedirectToAction("Index", "WidgetContainer");
     }
     else
     {
         ViewBag.Widgets = WidgetContainerRepository.getWidgets();
         return View("ContainerAdd", m_Container);
     }
 }
        public ActionResult ContainerAdd()
        {
            WidgetContainer m_Container = new WidgetContainer();
            ViewBag.Templates = Utility.GetTemplates();
            ViewBag.Widgets = WidgetContainerRepository.getWidgets();

            if (ViewBag.Widgets == null)
            {
                ViewBag.Widgets = new List<HTMLWidget>();
            }

            return View("ContainerAdd", m_Container);
        }
 public ActionResult ContainerEdit(WidgetContainer m_Container)
 {
     if (ModelState.IsValid)
     {
         WidgetContainerRepository.Update(m_Container);
         return RedirectToAction("Index", "WidgetContainer");
     }
     else
     {
         if (m_Container.MyWidgets == null)
         {
             m_Container.MyWidgets = new List<int>();
         }
         ViewBag.Widgets = WidgetContainerRepository.getWidgets();
         return View("ContainerEdit", m_Container);
     }
 }
Пример #5
0
        public ActionResult ContainerAdd(WidgetContainer m_Container)
        {
            var TemplateId = ModelState["TemplateId"];
            TemplateId.Errors.Clear();

            if (ModelState.IsValid)
            {
                int containerId = WidgetContainerRepository.Create(m_Container);
                return RedirectToAction("Index", "WidgetContainer");
            }
            else
            {
                ViewBag.Templates = Utility.GetTemplates();
                ViewBag.Widgets = WidgetContainerRepository.getWidgets();
                return View("ContainerAdd", m_Container);
            }
        }
 public void Update(WidgetContainer m_Container)
 {
     DBWidgetContainer.Update(m_Container);
 }
 public int Create(WidgetContainer m_Container)
 {
     int containerId = DBWidgetContainer.Create(m_Container);
     return containerId;
 }
Пример #8
0
        public static void Update(WidgetContainer m_Container)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "UPDATE CMS_WidgetContainers SET name = @name WHERE id = @id";
            SqlCommand updateContainer = new SqlCommand(queryString, conn);
            updateContainer.Parameters.AddWithValue("name", m_Container.Name);
            updateContainer.Parameters.AddWithValue("id", m_Container.Id);
            updateContainer.ExecuteNonQuery();

            queryString = "DELETE FROM CMS_ContainerToWidgets WHERE containerId = @containerId";
            SqlCommand deleteBridge = new SqlCommand(queryString, conn);
            deleteBridge.Parameters.AddWithValue("containerId", m_Container.Id);
            deleteBridge.ExecuteNonQuery();

            conn.Close();

            foreach (int widget in m_Container.MyWidgets)
            {
                conn.Open();

                int sortOrder = getSortOrder(m_Container.Id);

                queryString = "INSERT INTO CMS_ContainerToWidgets(containerId, widgetId, sortOrder) VALUES(@containerId, @widgetId, @sortOrder)";
                SqlCommand insertInfo = new SqlCommand(queryString, conn);
                insertInfo.Parameters.AddWithValue("containerId", m_Container.Id);
                insertInfo.Parameters.AddWithValue("widgetId", widget);
                insertInfo.Parameters.AddWithValue("sortOrder", sortOrder);

                insertInfo.ExecuteNonQuery();

                conn.Close();
            }
        }
Пример #9
0
        public static WidgetContainer RetrieveOneByTemplateId(int id)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_WidgetContainers WHERE templateId = @id AND pageWorkFlowState != 4";
            SqlCommand getContainer = new SqlCommand(queryString, conn);
            getContainer.Parameters.AddWithValue("id", id);
            SqlDataReader containerReader = getContainer.ExecuteReader();

            WidgetContainer m_Container = new WidgetContainer();

            if (containerReader.Read())
            {
                m_Container.Id = containerReader.GetInt32(0);
                m_Container.Name = containerReader.GetString(1);

                SqlConnection conn2 = DB.DbConnect();
                conn2.Open();

                queryString = "select w.id, w.name, w.content, ctw.sortOrder from CMS_ContainerToWidgets ctw, CMS_HTMLWidget w WHERE ctw.widgetId = w.id AND ctw.containerId = @id AND w.pageWorkFlowState != 4 ORDER BY ctw.sortOrder ASC";
                SqlCommand getWidgets = new SqlCommand(queryString, conn2);
                getWidgets.Parameters.AddWithValue("id", m_Container.Id);
                SqlDataReader widgetReader = getWidgets.ExecuteReader();

                m_Container.Widgets = new List<HTMLWidget>();
                m_Container.MyWidgets = new List<int>();

                while (widgetReader.Read())
                {
                    HTMLWidget m_Widget = new HTMLWidget();

                    m_Widget.Id = widgetReader.GetInt32(0);
                    m_Widget.Name = widgetReader.GetString(1);
                    m_Widget.Content = widgetReader.GetString(2);
                    m_Widget.SortOrder = widgetReader.GetInt32(3);

                    m_Container.MyWidgets.Add(widgetReader.GetInt32(0));
                    m_Container.Widgets.Add(m_Widget);
                }

                conn2.Close();
            }

            conn.Close();

            return m_Container;
        }
Пример #10
0
        public static List<WidgetContainer> RetrieveAll()
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_WidgetContainers WHERE pageWorkFlowState != 4";
            SqlCommand getContainer = new SqlCommand(queryString, conn);
            SqlDataReader containerReader = getContainer.ExecuteReader();

            List<WidgetContainer> m_Containers = new List<WidgetContainer>();

            while (containerReader.Read())
            {
                WidgetContainer m_Container = new WidgetContainer();
                m_Container.Id = containerReader.GetInt32(0);
                m_Container.Name = containerReader.GetString(1);
                m_Containers.Add(m_Container);

                SqlConnection conn2 = DB.DbConnect();
                conn2.Open();

                queryString = "select w.id, w.name, w.content, ctw.sortOrder from CMS_ContainerToWidgets ctw, CMS_HTMLWidget w WHERE ctw.widgetId = w.id AND ctw.containerId = 1 AND w.pageWorkFlowState != 4 ORDER BY ctw.sortOrder ASC";
                SqlCommand getWidgets = new SqlCommand(queryString, conn2);
                SqlDataReader widgetReader = getWidgets.ExecuteReader();

                m_Container.Widgets = new List<HTMLWidget>();
                m_Container.MyWidgets = new List<int>();

                while (widgetReader.Read())
                {
                    HTMLWidget m_Widget = new HTMLWidget();

                    m_Widget.Id = widgetReader.GetInt32(0);
                    m_Widget.Name = widgetReader.GetString(1);
                    m_Widget.Content = widgetReader.GetString(2);
                    m_Widget.SortOrder = widgetReader.GetInt32(3);

                    m_Container.MyWidgets.Add(widgetReader.GetInt32(0));
                    m_Container.Widgets.Add(m_Widget);
                }

                conn2.Close();
            }

            conn.Close();

            return m_Containers;
        }