예제 #1
0
        /// <summary>
        /// Create a New PlanCycle and attach it to the given plan year.
        /// </summary>
        /// <param name="cycle">with Name and Description</param>
        /// <param name="rtpYearId">ID of plan year</param>
        /// <returns>ID of created Plan Cycle</returns>
        public int CreateRtpPlanCycle(DRCOG.Domain.ViewModels.RTP.PlanCycle cycle, int rtpYearId)
        {
            using (var db = new Models.TRIPSEntities())
            {
                // there can be only one cycle in this plan year with a status of New
                var stId = db.StatusTypes.First(st => st.StatusType1 == "Cycle Status").StatusTypeID;
                var newId = db.Status.First(s => s.StatusTypeID == stId && s.Status1 == "New").StatusID;

                // see if there is already a new plan cycle for this RTP Year
                var previousNew = db.TimePeriodCycles.FirstOrDefault(tpc => tpc.TimePeriodId == rtpYearId && tpc.Cycle.statusId == newId);
                if (previousNew != null)
                {
                    throw new Exception("There is already a New Plan Cycle");
                }

                byte listOrder = 0;
                int? priorCycleId = null;

                // if this is not the first cycle in the time period, attach it to the end
                // of the two lists - ListOrder and priorCycleId
                var planCycles = db.TimePeriodCycles.Where(tpc => tpc.TimePeriodId == rtpYearId);
                if (planCycles.Count() > 0)
                {
                    // find last cycle in this time period. "last" means highest ListOrder.
                    var lo = planCycles.Max(tpc => tpc.ListOrder);
                    var prior = planCycles.First(tpc => tpc.ListOrder == lo);
                    priorCycleId = prior.CycleId;
                    listOrder = lo ?? 0;
                }

                // find largest ListOrder in these cycles and add 1
                ++listOrder;

                var mcycle = new Models.Cycle()
                {
                    cycle1 = cycle.Name,
                    Description = cycle.Description,
                    statusId = newId,
                    priorCycleId = priorCycleId
                };
                db.Cycles.AddObject(mcycle);

                var mtpc = new Models.TimePeriodCycle()
                {
                    Cycle = mcycle,
                    TimePeriodId = (short)rtpYearId,
                    ListOrder = listOrder
                };
                db.TimePeriodCycles.AddObject(mtpc);

                db.SaveChanges();

                return mcycle.id;
            }
        }
예제 #2
0
 public void Put(DRCOG.Domain.Models.RTP.RtpStatusModel model)
 {
     try
     {
         RtpRepository.UpdateRtpStatus(model);
     }
     catch (Exception ex)
     {
         Logger.WarnException("Could not update TIP Status", ex);
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = ex.Message });
     }
 }
예제 #3
0
 public JsonResult UpdateStatus(DRCOG.Domain.Models.TipStatusModel model)
 {
     //Send update to repo
     try
     {
         TripsRepository.UpdateTipStatus(model);
     }
     catch (Exception ex)
     {
         Logger.WarnException("Could not update TIP Status", ex);
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = ex.Message });
     }
     return new JsonResult() { message = "Changes successfully saved." };
 }
        public void Put(DRCOG.Domain.ViewModels.Survey.InfoViewModel viewModel)
        {
            // not in the form where we expect it
            viewModel.Project.SponsorId = viewModel.ProjectSponsorsModel.PrimarySponsor.OrganizationId.Value;
            viewModel.Project.TimePeriod = viewModel.Current.Name;

            //Send update to repo
            try
            {
                SurveyRepository.UpdateProjectInfo(viewModel.Project);
            }
            catch (Exception ex)
            {
                Logger.WarnException("Could not update Survey Info", ex);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = ex.Message });
            }
        }
 public int GetYearId(string year, DRCOG.Domain.Enums.TimePeriodType timePeriodType)
 {
     int result = 0;
     if (!String.IsNullOrEmpty(year))
     {
         SqlCommand cmd = new SqlCommand("Lookup_GetTimePeriodID");
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@TIMEPERIOD", year);
         cmd.Parameters.AddWithValue("@TimePeriodTypeId", (int)timePeriodType);
         using (IDataReader rdr = this.ExecuteReader(cmd))
         {
             if (rdr.Read()) result = rdr["ID"] != DBNull.Value ? int.Parse(rdr["ID"].ToString()) : 0;
             else result = 0;
         }
     }
     return result;
 }
예제 #6
0
        protected void LoadSession(DRCOG.Domain.Enums.ApplicationState applicationState = DRCOG.Domain.Enums.ApplicationState.Default)
        {
            ApplicationState appstate = this.GetSession();
            if (appstate == null)
            {
                appstate = GetNewSession();
            }
            appstate.SetStateType(applicationState);

            SaveSession(appstate);
        }
예제 #7
0
 public JsonResult SetSurveyDates(DRCOG.Domain.Models.Survey.Survey model)
 {
     try
     {
         _surveyRepository.SetSurveyDates(model);
     }
     catch (Exception ex)
     {
         return Json(new
         {
             message = "Changes could not be stored. An error has been logged."
             ,
             error = "true"
             ,
             exceptionMessage = ex.Message
         });
     }
     return Json(new
     {
         message = "Survey successfully updated."
         ,
         error = "false"
     });
 }
예제 #8
0
 public JsonResult GetSurveyDates(DRCOG.Domain.Models.Survey.Survey model)
 {
     try
     {
         Survey datesPartial = _surveyRepository.GetSurveyDates(model);
         model.OpeningDate = datesPartial.OpeningDate;
         model.ClosingDate = datesPartial.ClosingDate;
     }
     catch (Exception ex)
     {
         return Json(new
         {
             message = "Survey dates could not be retrieved. An error has been logged."
             ,
             error = "true"
             ,
             exceptionMessage = ex.Message
         });
     }
     return Json(new
     {
         message = "Survey dates successfully retreived."
         ,
         data = model
         ,
         error = "false"
     });
 }
예제 #9
0
 private Models.LR CompileLrs(DRCOG.Domain.Models.LRS lrs)
 {
     var xdoc = new XDocument(new XElement("item",
            new XElement("BEGINMEASU", lrs.BEGINMEASU),
            new XElement("Comments", lrs.Comments),
            new XElement("ENDMEASURE", lrs.ENDMEASURE),
            new XElement("Improvetype", lrs.Improvetype),
            new XElement("Network", lrs.Network),
            new XElement("Routename", lrs.Routename)));
     var model = new Models.LR()
     {
         ProjectSegmentId = lrs.SegmentId,
         Data = xdoc.ToString(),
         LRSSchemeId = 1 // our only schema
     };
     return model;
 }
예제 #10
0
        /// <summary>
        /// Update the TIP status.
        /// </summary>
        /// <param name="model"></param>
        public void UpdateTipStatus(DRCOG.Domain.Models.TipStatusModel model)
        {
            using (var db = new Models.TRIPSEntities())
            {
                var p = db.ProgramInstances.Single(pi => pi.TimePeriodID == model.TimePeriodId);
                var tp = db.TimePeriods.Single(t => t.TimePeriodID == model.TimePeriodId);
                var tpi = db.TIPProgramInstances.Single(pi => pi.TimePeriodID == model.TimePeriodId && pi.TIPProgramID == p.ProgramID);
                //p.ClosingDate = ?
                p.Current = model.IsCurrent;
                p.Notes = model.Notes;
                p.Pending = model.IsPending;
                p.Previous = model.IsPrevious;

                tpi.AdoptionDate = model.Adoption;
                tpi.GovernorApprovalDate = model.GovernorApproval;
                tpi.PublicHearingDate = model.PublicHearing;
                tpi.ShowDelayDate = model.ShowDelayDate;
                tpi.USDOTApprovalDate = model.USDOTApproval;
                tpi.USEPAApprovalDate = model.EPAApproval;

                var fs = new FundingIncrementSetter(db, tp);
                fs.SetFundingIncrement(model.FundingIncrement_Year_1, "Year 1");
                fs.SetFundingIncrement(model.FundingIncrement_Year_2, "Year 2");
                fs.SetFundingIncrement(model.FundingIncrement_Year_3, "Year 3");
                fs.SetFundingIncrement(model.FundingIncrement_Year_4, "Year 4");
                fs.SetFundingIncrement(model.FundingIncrement_Year_5, "Year 5");
                fs.SetFundingIncrement(model.FundingIncrement_Year_6, "Year 6");
                fs.SetFundingIncrement(model.FundingIncrement_Years_4_6, "Years 4-6");
                fs.SetFundingIncrement(model.FundingIncrement_Years_5_6, "Years 5-6");

                db.SaveChanges();
            }
        }
예제 #11
0
 public void UpdateRtpPlanCycle(DRCOG.Domain.ViewModels.RTP.PlanCycle cycle)
 {
     using (var db = new Models.TRIPSEntities())
     {
         var found = db.Cycles.FirstOrDefault(c => c.id == cycle.Id);
         if (found == null)
         {
             throw new Exception("No such RTP Plan Cycle");
         }
         found.cycle1 = cycle.Name;
         found.Description = cycle.Description;
         db.SaveChanges();
     }
 }
예제 #12
0
 /// <summary>
 /// Update the XML data in an RTP Project LRS record.
 /// </summary>
 /// <param name="lrs">data</param>
 public void RtpUpdateLrs(DRCOG.Domain.Models.LRS lrs)
 {
     var model = CompileLrs(lrs);
     using (var db = new Models.TRIPSEntities())
     {
         var record = db.LRS.First(l => l.Id == lrs.Id);
         record.Data = model.Data;
         db.SaveChanges();
     }
 }
예제 #13
0
 public int RtpCreateLrs(DRCOG.Domain.Models.LRS lrs)
 {
     var model = CompileLrs(lrs);
     using (var db = new Models.TRIPSEntities())
     {
         db.LRS.AddObject(model);
         db.SaveChanges();
         return model.Id;
     }
 }