public ActionResult CreateStaging(GeneralStagingModel model)
        {
            StagingDataAccess dataAccess = new StagingDataAccess();

            if (!dataAccess.isCreateStagingModelValid(model))
            {
                ModelState.AddModelError("TableName", "The Staging Table Name must be unique");

                List <Breadcrumb> trail = new List <Breadcrumb>();

                trail.Add(new Breadcrumb()
                {
                    LinkText = "Home", Action = "Index", Controller = "Home", isCurrent = false
                });
                trail.Add(new Breadcrumb()
                {
                    LinkText = "Staging Index", Action = "Index", Controller = "Staging", isCurrent = false
                });
                trail.Add(new Breadcrumb()
                {
                    LinkText = "Create Staging", isCurrent = true
                });

                model.Breadcrumbs = trail;

                return(View(model));
            }

            try
            {
                dataAccess.createStagingTable(model);
            }
            catch (SqlException)
            {
                ModelState.AddModelError("", "An error occured when creating the Staging Table. Please ensure that the staging table name is unique and that all columns within it are uniquely named");

                List <Breadcrumb> trail = new List <Breadcrumb>();

                trail.Add(new Breadcrumb()
                {
                    LinkText = "Home", Action = "Index", Controller = "Home", isCurrent = false
                });
                trail.Add(new Breadcrumb()
                {
                    LinkText = "Staging Index", Action = "Index", Controller = "Staging", isCurrent = false
                });
                trail.Add(new Breadcrumb()
                {
                    LinkText = "Create Staging", isCurrent = true
                });

                model.Breadcrumbs = trail;

                return(View(model));
            }

            TempData["SuccessMessage"] = String.Format("The Staging Table - {0}, was successfully created", model.TableName);
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        /// <summary>
        /// Validate that the Create Staging Table Model is valid prior to
        /// submission to the database
        /// </summary>
        /// <param name="model">The model to be validated</param>
        /// <returns>Boolean indicating valid or not</returns>
        public Boolean isCreateStagingModelValid(GeneralStagingModel model)
        {
            Geographical_NeedsEntities context = new Geographical_NeedsEntities();

            int count = context.StagingDatasets.Where(x => x.DatasetName.Equals(model.TableName)).Count();

            return(count == 0);
        }
Beispiel #3
0
        /// <summary>
        /// Method to create a Staging Table initially. This intial creation creates
        /// a record of the table in the meta data tables and then a trigger creates the
        /// actual table. Initially there are no columns associated with the table
        /// as these are added later when the data is uploaded.
        /// </summary>
        /// <param name="model">
        /// The populated model containing the name of the table to be created.
        /// </param>
        public void createStagingTable(GeneralStagingModel model)
        {
            Geographical_NeedsEntities context = new Geographical_NeedsEntities();

            StagingDataset staging = context.StagingDatasets.Create();

            staging.DatasetName = model.TableName;

            context.StagingDatasets.Add(staging);

            context.SaveChanges();

            context.Dispose();
        }
        /// <summary>
        /// Controller method that takes the user to the page to
        /// create a staging table. No parameters are needed and
        /// the controller needs no data access.
        ///
        /// Accessed via /Staging/CreateStaging
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateStaging()
        {
            GeneralStagingModel model = new GeneralStagingModel();

            List <Breadcrumb> trail = new List <Breadcrumb>();

            trail.Add(new Breadcrumb()
            {
                LinkText = "Home", Action = "Index", Controller = "Home", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Staging Index", Action = "Index", Controller = "Staging", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Create Staging", isCurrent = true
            });

            model.Breadcrumbs = trail;

            return(View(model));
        }