private async void SaveMember(object sender, EventArgs e)
        {
            var form = (Worker)BindingContext;

            form.BirthDate  = birthDate.Date;
            form.CompanyId  = companies[company.SelectedIndex].Id;
            form.PositionId = positions[position.SelectedIndex].Id;
            var fields = new List <string>();
            var errors = new List <string>();

            var errorsList = _worker.IsDataValid(form)
                             .Where(x => !string.IsNullOrWhiteSpace(x))
                             .Select(error => error.Split(new[] { ';' }, 2))
                             .Where(combined => !string.IsNullOrWhiteSpace(combined.Last()));

            foreach (var combined in errorsList)
            {
                fields.Add(combined.First());
                errors.Add(combined.Last());
            }
            if (!errors.Any())
            {
                _worker.Update(form);
                errors.Clear();
                await Navigation.PopToRootAsync();
            }
            else
            {
                for (int i = 0; errors.Count - 1 >= i; i++)
                {
                    await DisplayAlert(fields[i], errors[i], "OK");
                }
                errors.Clear();
            }
        }
 public ActionResult Update(Worker worker)
 {
     if (ModelState.IsValid)
     {
         repo.Update(worker.WorkerId, worker);
         return(RedirectToAction("GetAll"));
     }
     else
     {
         return(View(worker));
     }
 }
Example #3
0
 public Worker UpdateWorker(Worker originalWorker, WorkerRequest Worker)
 {
     this.MergeWorker(originalWorker, Worker);
     WorkerRepository.Update(originalWorker);
     return(originalWorker);
 }