示例#1
0
        public async Task <IActionResult> Edit([FromRoute(Name = "id")] int policyId,
                                               InsurancePolicyFormViewModel policyModel)
        {
            if (!ModelState.IsValid)
            {
                policyModel.InsuranceCompanies = await GetInsuranceCompanies();

                return(this.View(policyModel));
            }

            var editPolicy = this.mapper.Map <InsurancePolicyFormServiceModel>(policyModel);

            await this.policyService.EditPolicyAsync(policyId, editPolicy);

            TempData.AddSuccessMessage(string.Format(SuccessEditItemMessage, "policy"));

            //magic strings
            //return this.RedirectToRoute("default",
            //    new { controller = "Vehicles", action = "Index" });

            return(this.RedirectToAction <VehiclesController>(c => c.Index(1)));
        }
示例#2
0
        public async Task <IActionResult> Add(
            [FromRoute(Name = "id")] int vehicleId,
            InsurancePolicyFormViewModel policyModel)
        {
            if (!ModelState.IsValid)
            {
                policyModel.InsuranceCompanies = await GetInsuranceCompanies();

                return(this.View(policyModel));
            }

            var newPolicy = this.mapper.Map <InsurancePolicyFormServiceModel>(policyModel);

            await this.policyService.AddPolicyAsync(vehicleId, newPolicy);

            var currentVehiclePolicyAsigned =
                (await this.vehicleService.AllAsync()).Where(v => v.Id == vehicleId).FirstOrDefault();

            string policyInfo =
                string.Join(' ',
                            policyModel.TypeInsurance.ToString(),
                            "to",
                            currentVehiclePolicyAsigned.PlateNumber
                            );

            TempData.AddSuccessMessage(string.Format(SuccessAddItemMessage, policyInfo));

            //magic strings
            //return this.RedirectToRoute("default",
            //    new { controller = "Vehicles", action = "Index" });
            //var result = this.RedirectToAction<VehiclesController>(c => c.Index(1));
            //var result2 = this.RedirectToRoute("default",
            //        new { controller = "Vehicles", action = "Index" });

            return(this.RedirectToAction <VehiclesController>(c => c.Index(1)));
        }