コード例 #1
0
ファイル: HomeController.cs プロジェクト: goose-za/Playground
        public ActionResult GrantSummary(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // check if we have a GrantSummary object in the Session
            if (Session["grantSummaryData"] == null)
            {
                // we don't, so let's create a new object, populate it and throw it into the session variable
                GrantSummary model = new GrantSummary();

                model.AccountingRecordsSummary = (AccountingRecordsSummary)GetItemDetails("AccountingRecordsSummary", id, _ctx);
                model.BeneficiarySummary       = (BeneficiarySummary)GetItemDetails("BeneficiarySummary", id, _ctx);
                model.BoardSummary             = (IEnumerable <BoardSummary>)GetItemDetails("BoardSummary", id, _ctx);
                model.CapacityNeedsSummary     = (CapacityNeedsSummary)GetItemDetails("CapacityNeedsSummary", id, _ctx);
                model.ExpectedChangesSummary   = (ExpectedChangesSummary)GetItemDetails("ExpectedChangesSummary", id, _ctx);
                model.FinancialInfoSummary     = (FinancialInfoSummary)GetItemDetails("FinancialInfoSummary", id, _ctx);
                model.GrantInfoSummary         = (GrantInfoSummary)GetItemDetails("GrantInfoSummary", id, _ctx);
                model.GrantRequestInfoSummary  = (GrantRequestInfoSummary)GetItemDetails("GrantRequestInfoSummary", id, _ctx);
                model.InternalControlsSummary  = (InternalControlsSummary)GetItemDetails("InternalControlsSummary", id, _ctx);
                model.MandESummary             = (MandESummary)GetItemDetails("MandESummary", id, _ctx);
                model.ProjectSummary           = (ProjectSummary)GetItemDetails("ProjectSummary", id, _ctx);
                model.RiskAssessmentSummary    = (RiskAssessmentSummary)GetItemDetails("RiskAssessmentSummary", id, _ctx);
                model.StaffSummary             = (IEnumerable <StaffSummary>)GetItemDetails("StaffSummary", id, _ctx);

                if (model == null)
                {
                    return(HttpNotFound());
                }

                Session["grantSummaryData"] = model;

                return(View("GrantSummary", model));
            }
            else
            {
                // we have a GrantSummary object in the Session
                // so let's just get it and return the view with the data

                return(View("GrantSummary", (GrantSummary)Session["grantSummaryData"]));
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: goose-za/Playground
        public ActionResult GrantSummary(GrantSummary grantSummary)
        {
            var    identityName = Thread.CurrentPrincipal.Identity.Name;
            string errorParam   = string.Empty;

            var grantId = grantSummary.GrantInfoSummary.GrantId;

            string grantNotesJson = Request.Form["grantNotesJson"];

            _sectionNotes = JsonConvert.DeserializeObject <HashSet <SectionNote> >(grantNotesJson);

            using (var ctx = new AimsDbContext())
            {
                // define the SectionNotes data table
                DataTable sectionNotesDt = new DataTable();

                // add columns to dt
                sectionNotesDt.Columns.Add("GrantId", typeof(long));                           // [0]
                sectionNotesDt.Columns.Add("ProjectSummaryNote", typeof(string));              // [1]
                sectionNotesDt.Columns.Add("GrantRequestInfoSummaryNote", typeof(string));     // [2]
                sectionNotesDt.Columns.Add("BeneficiarySummaryNote", typeof(string));          // [3]
                sectionNotesDt.Columns.Add("ExpectedChangesSummaryNote", typeof(string));      // [4]
                sectionNotesDt.Columns.Add("CapacityNeedsSummaryNote", typeof(string));        // [5]
                sectionNotesDt.Columns.Add("RiskAssessmentSummaryNote", typeof(string));       // [6]
                sectionNotesDt.Columns.Add("MandESummaryNote", typeof(string));                // [7]
                sectionNotesDt.Columns.Add("FinancialInfoSummaryNote", typeof(string));        // [8]
                sectionNotesDt.Columns.Add("GovernanceAndHRSummaryNote", typeof(string));      // [9]
                sectionNotesDt.Columns.Add("AccountingRecordsSummaryNote", typeof(string));    // [10]
                sectionNotesDt.Columns.Add("InternalControlsSummaryNote", typeof(string));     // [11]
                sectionNotesDt.Columns.Add("InsertedDateTime", typeof(DateTime));              // [12]
                sectionNotesDt.Columns.Add("InsertedBy", typeof(string));                      // [13]
                sectionNotesDt.Columns.Add("ModifiedDateTime", typeof(DateTime));              // [14]
                sectionNotesDt.Columns.Add("ModifiedBy", typeof(string));                      // [15]

                // create new data row
                DataRow row = sectionNotesDt.NewRow();

                // populate the grant id column
                row[0] = grantId;

                // iterate over the collection of notes
                foreach (var note in _sectionNotes)
                {
                    // add section note to the related column
                    row[note.SectionId] = note.Text;
                }

                // populate audit data
                row[12] = DateTime.Now;     // InsertedDateTime
                row[13] = identityName;     // InsertedBy
                row[14] = DateTime.Now;     // ModifiedDateTime
                row[15] = identityName;     // ModifiedBy

                // add the row to the data table
                sectionNotesDt.Rows.Add(row);

                // execute the stored proc against the db
                var sql = @"InsertGrantSectionNotes @SectionNotes, @Error OUT";

                var result = ctx.Database.ExecuteSqlCommand(sql,
                                                            parameters: new[]
                {
                    new SqlParameter
                    {
                        ParameterName = "@SectionNotes",
                        SqlDbType     = SqlDbType.Structured,
                        TypeName      = "dbo.udtSectionNotes",
                        Direction     = ParameterDirection.Input,
                        Value         = sectionNotesDt
                    },
                    new SqlParameter
                    {
                        ParameterName = "@Error",
                        SqlDbType     = SqlDbType.NVarChar,
                        Direction     = ParameterDirection.Output,
                        Value         = errorParam
                    }
                });

                if (errorParam != string.Empty)
                {
                    throw new SqlExecutionException(errorParam);
                }

                // send the data back to the workflow to send back to the grantee
            }

            if (Session["grantSummaryData"] != null)
            {
                return(View("GrantSummary", (GrantSummary)Session["grantSummaryData"]));
            }

            return(View());
        }