示例#1
0
        public async Task <IActionResult> Create(CreateYearEventViewModel model)
        {
            YearEvent yearEvent = new YearEvent()
            {
                AgencyId      = model.AgencyId,
                Number        = await db.YearEvents.Where(y => y.AgencyId == model.AgencyId && y.DataYear == model.DataYear).CountAsync() + 1,
                EventText     = model.EventText,
                FirstQuarter  = model.FirstQuarter,
                SecondQuarter = model.SecondQuarter,
                ThirdQuarter  = model.ThirdQuarter,
                FourthQuarter = model.FourthQuarter,
                Unit          = model.Unit,
                TypeSection   = model.TypeSection,
                DataYear      = model.DataYear
            };
            Section Section = await db.Sections.FirstOrDefaultAsync(subs => subs.Id == model.SectionId);

            yearEvent.Section = Section.Name;

            SubSection subSection = await db.SubSections.FirstOrDefaultAsync(subs => subs.Id == model.SubSectionId);

            yearEvent.SubSection = subSection.Name;

            SubSection1 subSection1 = await db.SubSection1s.FirstOrDefaultAsync(subs => subs.Id == model.SubSection1Id);

            yearEvent.SubSection1 = subSection1.Name;


            db.YearEvents.Add(yearEvent);
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", "Agency", new { id = yearEvent.AgencyId, DataYearVM = yearEvent.DataYear }));
        }
示例#2
0
        public async Task <IActionResult> Create(int id)
        {
            CreateYearEventViewModel model = new CreateYearEventViewModel()
            {
                AgencyId     = id,
                Agency       = await db.Agencies.FirstOrDefaultAsync(a => a.Id == id),
                Units        = await db.Units.ToListAsync(),
                TypeSections = await db.TypeSections.ToListAsync(),
                Sections     = await db.Sections.ToListAsync(),
                SubSections  = await db.SubSections.ToListAsync(),
                SubSection1s = await db.SubSection1s.ToListAsync(),
                DataYears    = await db.DataYears.ToListAsync()
            };

            return(View(model));
        }