public IActionResult Index(FormSubmissionViewModel fsViewModel) { if (UserExists(fsViewModel.User)) { ViewData["errorString"] = "See kasutaja on juba andmeid sisestanud."; return(View()); } IEnumerable <ValidationResult> errors = fsViewModel.Validate(new ValidationContext(fsViewModel)); if (errors.Count() == 0) { _context.Add(fsViewModel.User); _context.SaveChanges(); List <WebSiteInfo> wsInfos = fsViewModel.WebSiteInfos.Where(wsi => Validator.TryValidateObject(wsi, new ValidationContext(wsi), new List <ValidationResult>())).ToList(); wsInfos.ForEach(wsi => { wsi.User = fsViewModel.User; _context.Add(wsi); }); _context.SaveChanges(); TempData["successMessage"] = "Saitide lisamine õnnestus"; return(RedirectToAction("Index", "DisplaySites")); } ViewData["errorString"] = errors.Aggregate((err1, err2) => new ValidationResult(err1 + " " + err2)).ErrorMessage; return(View()); }
public async Task <ActionResult> Submit(FormSubmissionViewModel model) { var vm = await GetFormSubmissionViewModel(model.SelectedSectors); vm.SelectedSectors = model.SelectedSectors; vm.Name = model.Name; vm.AgreeToTerms = model.AgreeToTerms; if (ModelState.IsValid) { var createRequest = new SubmissionCreateOrUpdateRequest { SessionId = GetCurrentSessionId, FormSubmissionViewModel = vm }; var response = await _submissionService.CreateOrUpdateSubmission(createRequest); if (response.Success) { TempData[Constants.Constants.FlashMessage] = new FlashMessage { Message = StringResources.FormSavedSuccessMessage, MessageType = MessageType.Success }; } else { TempData[Constants.Constants.FlashMessage] = new FlashMessage { Message = StringResources.FormSavedErrorMessage, MessageType = MessageType.Danger }; } return(RedirectToAction(Constants.Constants.HomeIndexAction, Constants.Constants.HomeController)); } TempData[Constants.Constants.FormSubmissionViewModel] = vm; return(RedirectToAction(Constants.Constants.HomeIndexAction, Constants.Constants.HomeController)); }
public IViewComponentResult Invoke(FormSubmissionViewModel fsvm) { return(View(fsvm)); }
public ActionResult Submit(FormSubmissionViewModel viewModel) { if (!ModelState.IsValid) { Response.StatusCode = 400; Response.TrySkipIisCustomErrors = true; return(Json(ModelState.AllErrors())); } var isEmail = viewModel.info.optout_email == null; var isPhone = viewModel.info.optout_phone == null; var isPost = viewModel.info.optout_post == null; var customer = new Customer { AddressLine1 = viewModel.info.address_1, AddressLine2 = viewModel.info.address_2, AddressLine3 = viewModel.info.address_3, Town = viewModel.info.town, AddressPostcode = viewModel.info.postcode, Dealer = viewModel.info.dealer, Email = viewModel.info.email, FirstName = viewModel.info.name, LastName = viewModel.info.surname, Title = viewModel.info.title, TelephoneMobile = viewModel.info.tel_mobile, TelephoneHome = viewModel.info.tel_home, TelephoneWork = viewModel.info.tel_work, AddressType = viewModel.info.address_type, IsEmail = isEmail, IsPhone = isPhone, IsPost = isPost, UserId = viewModel.info.userid, Selections = new Selections { Capacity = string.Join(",", viewModel.input.seats), Luggage = viewModel.input.luggage, PriceRange = viewModel.input.price.ToString(), Performance = viewModel.input.speed, Use = viewModel.input.lifestyle, Economy = viewModel.input.mpg.ToString(), Options = new Options { AWD = viewModel.input.options.awd.ToString(), DT = viewModel.input.options.dt.ToString(), HP = viewModel.input.options.hp.ToString(), TP = viewModel.input.options.tp.ToString() } } }; var json = JsonConvert.SerializeObject(viewModel); Log.Info("Data: " + json); var carModel = viewModel.car; var command = new SendCustomerDataCommand(customer, carModel, Server.MapPath(Common.Config.EmailHTMLTemplate), Server.MapPath(Common.Config.EmailTextTemplate)); var dataSent = command.Execute(); if (!dataSent) { throw new HttpException((Int32)HttpStatusCode.InternalServerError, "An error occured sending data"); } Response.StatusCode = 201; Response.StatusDescription = "success"; return(Json("success")); }