Пример #1
0
        public async Task <IActionResult> Edit(EditYearEventViewModel model)
        {
            YearEvent yearEvent = await db.YearEvents.FirstOrDefaultAsync(ye => ye.Id == model.Id);

            yearEvent.EventText     = model.EventText;
            yearEvent.FirstQuarter  = model.FirstQuarter;
            yearEvent.SecondQuarter = model.SecondQuarter;
            yearEvent.ThirdQuarter  = model.ThirdQuarter;
            yearEvent.FourthQuarter = model.FourthQuarter;
            yearEvent.Unit          = model.Unit;
            yearEvent.TypeSection   = model.TypeSection;
            Section section = await db.Sections.FirstOrDefaultAsync(sec => sec.Id == model.SectionId);

            yearEvent.Section = section.Name;
            SubSection subSection = await db.SubSections.FirstOrDefaultAsync(sub => sub.Id == model.SubSectionId);

            yearEvent.SubSection = subSection.Name;
            SubSection1 subSection1 = await db.SubSection1s.FirstOrDefaultAsync(sub1 => sub1.Id == model.SubSection1Id);

            yearEvent.SubSection1 = subSection1.Name;
            yearEvent.DataYear    = model.DataYear;
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", "Agency", new { id = yearEvent.AgencyId, DataYearVM = yearEvent.DataYear }));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id)
        {
            YearEvent yearEvent = await db.YearEvents.FirstOrDefaultAsync(ye => ye.Id == id);

            if (yearEvent == null)
            {
                return(NotFound());
            }
            else
            {
                EditYearEventViewModel model = new EditYearEventViewModel
                {
                    Id            = yearEvent.Id,
                    Agency        = await db.Agencies.FirstOrDefaultAsync(ag => ag.Id == yearEvent.AgencyId),
                    AgencyId      = yearEvent.AgencyId,
                    Number        = yearEvent.Number,
                    EventText     = yearEvent.EventText,
                    FirstQuarter  = yearEvent.FirstQuarter,
                    SecondQuarter = yearEvent.SecondQuarter,
                    ThirdQuarter  = yearEvent.ThirdQuarter,
                    FourthQuarter = yearEvent.FourthQuarter,
                    Unit          = yearEvent.Unit,
                    Units         = await db.Units.ToListAsync(),
                    TypeSection   = yearEvent.TypeSection,
                    TypeSections  = await db.TypeSections.ToListAsync(),
                    Sections      = await db.Sections.ToListAsync(),
                    SubSections   = await db.SubSections.ToListAsync(),
                    SubSection    = yearEvent.SubSection,
                    SubSection1s  = await db.SubSection1s.ToListAsync(),
                    SubSection1   = yearEvent.SubSection1,
                    DataYear      = yearEvent.DataYear,
                    DataYears     = await db.DataYears.ToListAsync()
                };
                if (yearEvent.Section == null)
                {
                    yearEvent.Section = "ИСО";
                }
                Section section = await db.Sections.FirstOrDefaultAsync(sec => sec.Name == yearEvent.Section);

                model.SectionId = section.Id;
                SubSection subSection = await db.SubSections.FirstOrDefaultAsync(sub => sub.Name == yearEvent.SubSection);

                model.SubSectionId = subSection.Id;
                SubSection1 subSection1 = await db.SubSection1s.FirstOrDefaultAsync(sub1 => sub1.Name == yearEvent.SubSection1);

                model.SubSection1Id = subSection1.Id;
                return(View(model));
            }
        }