Esempio n. 1
0
        //[ValidateAntiForgeryToken]
        public IActionResult AddPost(NationalityViewModel nationalityViewModel)
        {
            var nationalityList = _nationality.GetNationalities();

            ViewBag.Nationality = nationalityList;
            if (nationalityViewModel.Id == 0)
            {
                ModelState.Remove("Id");
                if (ModelState.IsValid)
                {
                    var nationality = _mapper.Map <Nationality>(nationalityViewModel);
                    _nationality.AddNationality(nationality);
                    _toastNotification.AddSuccessToastMessage("تم أضافةالجنسية بنجاح");
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nameof(Index), nationalityViewModel));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var nationality = _mapper.Map <Nationality>(nationalityViewModel);
                    _nationality.UpdateNationality(nationalityViewModel.Id, nationality);
                    _toastNotification.AddSuccessToastMessage("تم تعديل الجنسية بنجاح");
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nameof(Index), nationalityViewModel));
            }
        }