Asp.net ошибка core3: не все пути кода возвращают значение
I have two tables with similar data for body insurance and third party car insurance ... I have used enum in the model to separate the insurances and I want to do the creation operation for it .... There are two modes for each insurance. One case when that car does not have insurance yet and the second case when we want to extend it. I wrote this code to create the form, but it encounters the following error I also get an error on the name of the Create function.error = not all code paths return a value. Please advise
Что я уже пробовал:
public async Task<IActionResult> Create(int id, int type) { InsuranceViewModel model; ViewBag.Type = type; var companies = await _context.InsuranceCompany .Where(e => e.IsActice) .ToListAsync(); ViewData["CompanyList"] = new SelectList(companies, "Id", "CompanyName"); if ((InsuranceType)type == InsuranceType.Body) { var bodyInsurance = await _context.BodyInsurance .Include(e => e.InsuranceCompany) .FirstOrDefaultAsync(e => e.Id == id); if (bodyInsurance == null) { model = new InsuranceViewModel { CompanyId = bodyInsurance.InsuranceCompanyId, CompanyName = bodyInsurance.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Body, IssueDate = new DateTime(bodyInsurance.IssueDate).Ticks, ExpireDate = new DateTime(bodyInsurance.ExpireDate).Ticks, VehicleInformationId = id }; } else { var lastBody = await _context.BodyInsurance.Include(e => e.InsuranceCompany) .Where(e => e.VehicleInformationId == id) .OrderBy(e => e.ExpireDate) .LastAsync(); model = new InsuranceViewModel { ExpireDate = new DateTime(lastBody.ExpireDate).AddYears(1).AddDays(1).Ticks, CompanyId = lastBody.InsuranceCompanyId, CompanyName = lastBody.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Body, IssueDate = new DateTime(lastBody.ExpireDate).AddDays(1).Ticks, VehicleInformationId = id }; } } else { if ((InsuranceType)type == InsuranceType.Thirdpart) { var thirdParty = await _context.ThirdPartyInsurance .Include(e => e.InsuranceCompany) .FirstOrDefaultAsync(e => e.Id == id); if (thirdParty == null) { model = new InsuranceViewModel { CompanyId = thirdParty.InsuranceCompanyId, CompanyName = thirdParty.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Body, IssueDate = new DateTime(thirdParty.IssueDate).Ticks, ExpireDate = new DateTime(thirdParty.ExpireDate).Ticks, VehicleInformationId = id }; } else { var lastThirdParty = await _context.ThirdPartyInsurance.Include(e => e.InsuranceCompany) .Where(e => e.VehicleInformationId == id) .OrderBy(e => e.ExpireDate) .LastAsync(); model = new InsuranceViewModel { ExpireDate = new DateTime(lastThirdParty.ExpireDate).AddYears(1).AddDays(1).Ticks, CompanyId = lastThirdParty.InsuranceCompanyId, CompanyName = lastThirdParty.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Body, IssueDate = new DateTime(lastThirdParty.ExpireDate).AddDays(1).Ticks, VehicleInformationId = id }; } } return View(model); }