private async Task<Negotiator> HandlePost(dynamic parameters) { var viewModel = new DefaultViewModel(); if (HandledOutOfTime(viewModel)) { return View["NotAllowed.html", viewModel]; } var data = Utils.CreateCandidateDataFromRequest(this.Request); if (!ValidateData(data, viewModel)) { return View["DefaultForm.html", viewModel]; } try { await _dataLayer.SaveCandidateDataAsync(data); } catch (Exception ex) { viewModel.ErrorMessages.Add("Error during saving the data"); return View["DefaultForm.html", viewModel]; } viewModel.Messages.Add("Provided data has been saved. Thank you."); return View["DefaultForm.html", viewModel]; }
private bool HandledOutOfTime(DefaultViewModel viewModel) { if (IsOutOfTime()) { viewModel.Messages.Add(string.Format("The website is closed between {0} and {1}", _parameters.OpenTime.Value.ToShortTimeString(), _parameters.CloseTime.Value.ToShortTimeString())); return true; } return false; }
private Negotiator HandleGet() { var viewModel = new DefaultViewModel(); if (HandledOutOfTime(viewModel)) { return View["NotAllowed.html", viewModel]; } return View["DefaultForm.html", viewModel]; }
private bool ValidateData(CandidateModel candidate, DefaultViewModel model) { if (string.IsNullOrWhiteSpace(candidate.FirstName) || string.IsNullOrWhiteSpace(candidate.LastName) || string.IsNullOrWhiteSpace(candidate.Address) || candidate.Skills.Count == 0) { model.ErrorMessages.Add("Every field is mandatory"); return false; } return true; }