예제 #1
0
        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];
        }
예제 #2
0
 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;
 }
예제 #3
0
 private Negotiator HandleGet()
 {
     var viewModel = new DefaultViewModel();
     if (HandledOutOfTime(viewModel))
     {
         return View["NotAllowed.html", viewModel];
     }
     return View["DefaultForm.html", viewModel];
 }
예제 #4
0
        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;
        }