예제 #1
0
 private FINANCIAL_HOURS CreateNewFinancialHours(int assessmentId, AdminSaveData save)
 {
     return(new FINANCIAL_HOURS()
     {
         Assessment_Id = assessmentId,
         Component = save.Component,
         ReviewType = save.ReviewType,
         Hours = save.Hours,
         OtherSpecifyValue = save.OtherSpecifyValue
     });
 }
예제 #2
0
        /// <summary>
        /// Saves the number of hours and maybe the OtherSpecifyValue to the FINANCIAL_HOURS database.
        /// </summary>
        /// <param name="assessmentId"></param>
        /// <param name="save"></param>
        /// <returns></returns>
        public AdminSaveResponse SaveData(int assessmentId, AdminSaveData save)
        {
            using (var db = new CSET_Context())
            {
                FINANCIAL_HOURS fh = null;

                var items = db.FINANCIAL_HOURS.Where(x => x.Assessment_Id == assessmentId && x.Component == save.Component).ToList();

                if (items.Count == 0)
                {
                    // No answers saved yet.  Build both records.
                    fh            = CreateNewFinancialHours(assessmentId, save);
                    fh.ReviewType = "Documentation";
                    db.FINANCIAL_HOURS.Add(fh);

                    fh            = CreateNewFinancialHours(assessmentId, save);
                    fh.ReviewType = "Interview Process";
                    db.FINANCIAL_HOURS.Add(fh);

                    db.SaveChanges();
                }
                else
                {
                    foreach (FINANCIAL_HOURS item in items)
                    {
                        if (item.ReviewType == save.ReviewType || string.IsNullOrEmpty(save.ReviewType))
                        {
                            if (item.ReviewType == save.ReviewType)
                            {
                                item.Hours = save.Hours;
                            }

                            item.OtherSpecifyValue = save.OtherSpecifyValue;

                            db.SaveChanges();
                        }
                    }
                }


                // Get totals for AdminSaveResponse
                AdminSaveResponse resp = new AdminSaveResponse
                {
                    DocumentationTotal = 0,
                    InterviewTotal     = 0,
                    GrandTotal         = 0,
                    ReviewedTotal      = 0
                };
                AdminTabData d = GetTabData(assessmentId);
                foreach (var t in d.ReviewTotals)
                {
                    switch (t.ReviewType.ToLower())
                    {
                    case "documentation":
                        resp.DocumentationTotal += (double)t.Total;
                        break;

                    case "interview process":
                        resp.InterviewTotal += (double)t.Total;
                        break;
                    }
                }
                ;
                resp.GrandTotal = (double)d.GrandTotal;
                //resp.ReviewedTotal = ???;

                return(resp);
            }
        }