public IActionResult Create(EducationCRUDViewModel model) { if (!ModelState.IsValid) { ViewBag.action = "create"; return(View("Crud", model)); } educationRepo.Create(model.Education); return(RedirectToAction("Overview")); }
public IActionResult CreateEducation([FromBody] Education education) { var lang = Request.Headers["language"].ToString(); var errorMessages = new List <string>(); try { var newEdu = new Education { Title_EN = education.Title_EN, Title_FR = !string.IsNullOrEmpty(education.Title_FR) ? education.Title_FR : education.Title_EN, Specialization_EN = education.Specialization_EN, Specialization_FR = !string.IsNullOrEmpty(education.Specialization_FR) ? education.Specialization_FR : education.Specialization_EN, Establishment_EN = education.Establishment_EN, Establishment_FR = !string.IsNullOrEmpty(education.Establishment_FR) ? education.Establishment_FR : education.Establishment_EN, Mention_EN = education.Mention_EN, Mention_FR = !string.IsNullOrEmpty(education.Mention_FR) ? education.Mention_FR : education.Mention_EN, Country_EN = education.Country_EN, Country_FR = !string.IsNullOrEmpty(education.Country_FR) ? education.Country_FR : education.Country_EN, City_EN = education.City_EN, City_FR = !string.IsNullOrEmpty(education.City_FR) ? education.City_FR : education.City_EN, YearsCount = education.YearsCount, Note = education.Note, StartDate = education.StartDate, GraduateDate = education.GraduateDate }; var createdEducation = _educationRepository.Create(newEdu); return(Ok(new { createdEducation })); } catch { errorMessages.Add(_translator.GetTranslation("ERROR", lang)); return(BadRequest(new { errors = errorMessages })); } }