public static CathedraReportViewModel ConvertToViewModel(CathedraReport report) { var viewModel = new CathedraReportViewModel() { ID = report.ID, Protocol = report.Protocol, Date = report.Date, AchivementSchool = report.AchivementSchool, AllDescriptionBudgetTheme = report.AllDescriptionBudgetTheme, AllDescriptionHospDohovirTheme = report.AllDescriptionHospDohovirTheme, AllDescriptionThemeInWorkTime = report.AllDescriptionThemeInWorkTime, ApplicationAndPatentsOnInventionBudgetTheme = report.ApplicationAndPatentsOnInventionBudgetTheme, ApplicationAndPatentsOnInventionHospDohovirTheme = report.ApplicationAndPatentsOnInventionHospDohovirTheme, ApplicationAndPatentsOnInventionThemeInWorkTime = report.ApplicationAndPatentsOnInventionThemeInWorkTime, ApplicationOnInvention = report.ApplicationOnInvention, BudgetThemeId = report.BudgetTheme?.ID, ConferencesInUniversity = report.ConferencesInUniversity, CooperationWithAcadamyOfScience = report.CooperationWithAcadamyOfScience, CooperationWithForeignScientificInstitution = report.CooperationWithForeignScientificInstitution, CVBudgetTheme = report.CVBudgetTheme, CVHospDohovirTheme = report.CVHospDohovirTheme, CVThemeInWorkTime = report.CVThemeInWorkTime, DefenseOfCoworkers = report.DefenseOfCoworkers, DefenseOfDoctorantsAndAspirants = report.DefenseOfDoctorantsAndAspirants, DefensesOfCoworkersBudgetTheme = report.DefensesOfCoworkersBudgetTheme, DefensesOfCoworkersHospDohovirTheme = report.DefensesOfCoworkersHospDohovirTheme, DefensesOfCoworkersThemeInWorkTime = report.DefensesOfCoworkersThemeInWorkTime, DefenseWithSpecialPeople = report.DefenseWithSpecialPeople, HospDohovirThemeId = report.HospDohovirTheme?.ID, Materials = report.Materials, OtherBudgetTheme = report.OtherBudgetTheme, OtherFormsOfScientificWork = report.OtherFormsOfScientificWork, OtherHospDohovirTheme = report.OtherHospDohovirTheme, OtherThemeInWorkTime = report.OtherThemeInWorkTime, Patents = report.Patents, PropositionForNewForms = report.PropositionForNewForms, StudentsWorks = report.StudentsWorks, ThemeInWorkTimeId = report.ThemeInWorkTime?.ID }; viewModel.PrintedPublicationBudgetTheme = report.PrintedPublicationBudgetTheme.Select(x => new PublicationOption() { Id = x.ID, Checked = false, Name = x.Name }).ToList(); viewModel.PrintedPublicationHospDohovirTheme = report.PrintedPublicationHospDohovirTheme.Select(x => new PublicationOption() { Id = x.ID, Checked = false, Name = x.Name }).ToList(); viewModel.PrintedPublicationThemeInWorkTime = report.PrintedPublicationThemeInWorkTime.Select(x => new PublicationOption() { Id = x.ID, Checked = false, Name = x.Name }).ToList(); return(viewModel); }
public static CathedraReport ConvertToEntity(CathedraReportViewModel reportViewModel) { var report = new CathedraReport() { Protocol = reportViewModel.Protocol, Date = reportViewModel.Date, AchivementSchool = reportViewModel.AchivementSchool, AllDescriptionBudgetTheme = reportViewModel.AllDescriptionBudgetTheme, AllDescriptionHospDohovirTheme = reportViewModel.AllDescriptionHospDohovirTheme, AllDescriptionThemeInWorkTime = reportViewModel.AllDescriptionThemeInWorkTime, ApplicationAndPatentsOnInventionBudgetTheme = reportViewModel.ApplicationAndPatentsOnInventionBudgetTheme, ApplicationAndPatentsOnInventionHospDohovirTheme = reportViewModel.ApplicationAndPatentsOnInventionHospDohovirTheme, ApplicationAndPatentsOnInventionThemeInWorkTime = reportViewModel.ApplicationAndPatentsOnInventionThemeInWorkTime, ApplicationOnInvention = reportViewModel.ApplicationOnInvention, ConferencesInUniversity = reportViewModel.ConferencesInUniversity, CooperationWithAcadamyOfScience = reportViewModel.CooperationWithAcadamyOfScience, CooperationWithForeignScientificInstitution = reportViewModel.CooperationWithForeignScientificInstitution, CVBudgetTheme = reportViewModel.CVBudgetTheme, CVHospDohovirTheme = reportViewModel.CVHospDohovirTheme, CVThemeInWorkTime = reportViewModel.CVThemeInWorkTime, DefenseOfCoworkers = reportViewModel.DefenseOfCoworkers, DefenseOfDoctorantsAndAspirants = reportViewModel.DefenseOfDoctorantsAndAspirants, DefensesOfCoworkersBudgetTheme = reportViewModel.DefensesOfCoworkersBudgetTheme, DefensesOfCoworkersHospDohovirTheme = reportViewModel.DefensesOfCoworkersHospDohovirTheme, DefensesOfCoworkersThemeInWorkTime = reportViewModel.DefensesOfCoworkersThemeInWorkTime, DefenseWithSpecialPeople = reportViewModel.DefenseWithSpecialPeople, Materials = reportViewModel.Materials, OtherBudgetTheme = reportViewModel.OtherBudgetTheme, OtherFormsOfScientificWork = reportViewModel.OtherFormsOfScientificWork, OtherHospDohovirTheme = reportViewModel.OtherHospDohovirTheme, OtherThemeInWorkTime = reportViewModel.OtherThemeInWorkTime, Patents = reportViewModel.Patents, PropositionForNewForms = reportViewModel.PropositionForNewForms, StudentsWorks = reportViewModel.StudentsWorks, }; return(report); }
private void CreateOrUpdateReport(CathedraReportViewModel reportViewModel, int stepIndex) { var allPublications = db.Publication.ToList(); if (reportViewModel.ID == null && !db.Reports.Any(x => x.ID == reportViewModel.ID)) { var reportToCreate = ReportConverter.ConvertToEntity(reportViewModel); reportToCreate.User = db.Users.Find(User.Identity.GetUserId()); reportToCreate.BudgetTheme = db.ThemeOfScientificWork.Where(x => x.ID == reportViewModel.BudgetThemeId).FirstOrDefault(); if (reportViewModel.PrintedPublicationBudgetTheme != null) { reportToCreate.PrintedPublicationBudgetTheme = allPublications .Where(x => reportViewModel.PrintedPublicationBudgetTheme.Any(y => y.Id == x.ID && y.Checked)).ToList(); } db.CathedraReport.Add(reportToCreate); db.SaveChanges(); } else { var report = db.CathedraReport.Find(reportViewModel.ID); switch (stepIndex) { case 0: report.BudgetTheme = db.ThemeOfScientificWork.Where(x => x.ID == reportViewModel.BudgetThemeId).FirstOrDefault(); if (reportViewModel.PrintedPublicationBudgetTheme != null) { report.PrintedPublicationBudgetTheme = allPublications .Where(x => reportViewModel.PrintedPublicationBudgetTheme.Any(y => y.Id == x.ID && y.Checked)).ToList(); } report.AllDescriptionBudgetTheme = reportViewModel.AllDescriptionBudgetTheme; report.CVBudgetTheme = reportViewModel.CVBudgetTheme; report.ApplicationAndPatentsOnInventionBudgetTheme = reportViewModel.ApplicationAndPatentsOnInventionBudgetTheme; report.OtherBudgetTheme = reportViewModel.OtherBudgetTheme; report.DefensesOfCoworkersBudgetTheme = reportViewModel.DefensesOfCoworkersBudgetTheme; break; case 1: report.ThemeInWorkTime = db.ThemeOfScientificWork.Where(x => x.ID == reportViewModel.ThemeInWorkTimeId).FirstOrDefault(); if (reportViewModel.PrintedPublicationThemeInWorkTime != null) { report.PrintedPublicationThemeInWorkTime = allPublications .Where(x => reportViewModel.PrintedPublicationThemeInWorkTime.Any(y => y.Id == x.ID && y.Checked)).ToList(); } report.AllDescriptionThemeInWorkTime = reportViewModel.AllDescriptionThemeInWorkTime; report.CVThemeInWorkTime = reportViewModel.CVThemeInWorkTime; report.ApplicationAndPatentsOnInventionThemeInWorkTime = reportViewModel.ApplicationAndPatentsOnInventionThemeInWorkTime; report.OtherThemeInWorkTime = reportViewModel.OtherThemeInWorkTime; report.DefensesOfCoworkersThemeInWorkTime = reportViewModel.DefensesOfCoworkersThemeInWorkTime; break; case 2: report.HospDohovirTheme = db.ThemeOfScientificWork.Where(x => x.ID == reportViewModel.HospDohovirThemeId).FirstOrDefault(); if (reportViewModel.PrintedPublicationHospDohovirTheme != null) { report.PrintedPublicationHospDohovirTheme = allPublications .Where(x => reportViewModel.PrintedPublicationHospDohovirTheme.Any(y => y.Id == x.ID && y.Checked)).ToList(); } report.AllDescriptionHospDohovirTheme = reportViewModel.AllDescriptionHospDohovirTheme; report.CVHospDohovirTheme = reportViewModel.CVHospDohovirTheme; report.ApplicationAndPatentsOnInventionHospDohovirTheme = reportViewModel.ApplicationAndPatentsOnInventionHospDohovirTheme; report.OtherHospDohovirTheme = reportViewModel.OtherHospDohovirTheme; report.DefensesOfCoworkersHospDohovirTheme = reportViewModel.DefensesOfCoworkersHospDohovirTheme; break; case 3: report.AchivementSchool = reportViewModel.AchivementSchool; report.OtherFormsOfScientificWork = reportViewModel.OtherFormsOfScientificWork; report.CooperationWithAcadamyOfScience = reportViewModel.CooperationWithAcadamyOfScience; report.CooperationWithForeignScientificInstitution = reportViewModel.CooperationWithForeignScientificInstitution; report.StudentsWorks = reportViewModel.StudentsWorks; report.ConferencesInUniversity = reportViewModel.ConferencesInUniversity; report.ApplicationOnInvention = reportViewModel.ApplicationOnInvention; report.Patents = reportViewModel.Patents; report.Materials = reportViewModel.Materials; report.PropositionForNewForms = reportViewModel.PropositionForNewForms; break; case 4: report.Date = reportViewModel.Date; report.Protocol = reportViewModel.Protocol; break; default: return; } db.SaveChanges(); } }
public ActionResult Update(CathedraReportViewModel reportViewModel, int?stepIndex, int?oldIndex) { CreateOrUpdateReport(reportViewModel, oldIndex ?? 0); return(RedirectToAction("Index", new { stepIndex = stepIndex, reportId = reportViewModel.ID })); }