public ActionResult NewsAddEdit(BackEndNewsAddEdit backEndNewsAddEdit) { if (ModelState.IsValidOrRefresh()) { News news = new News(); int? result; bool isLoopSuccessful = true; int? lastInsertedId = null; int? currentId = backEndNewsAddEdit.NewsId; foreach (BackEndNewsLanguagesAddEdit backEndNewsLanguagesAddEdit in backEndNewsAddEdit.NewsLanguages) { if (currentId.IsNull()) { currentId = lastInsertedId; } result = news.AddEdit(currentId, backEndNewsAddEdit.NewsDate.ToDateTime(), BackEndSessions.CurrentUser.UserName, backEndNewsAddEdit.IsActive, backEndNewsAddEdit.CategoryId, backEndNewsAddEdit.MainImageFilePath, backEndNewsLanguagesAddEdit.LanguageCode, backEndNewsLanguagesAddEdit.NewsTitle, backEndNewsLanguagesAddEdit.NewsContent, out lastInsertedId); switch (result) { case 0: //success break; case 2: isLoopSuccessful = false; ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist); ViewData.IsFormVisible(false); break; default: isLoopSuccessful = false; ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError); break; } if (!isLoopSuccessful) { break; } } if (isLoopSuccessful) { if (backEndNewsAddEdit.NewsId.IsNull()) { ModelState.Clear(); backEndNewsAddEdit = new BackEndNewsAddEdit(); BackEndNewsLanguagesAddEdit backEndNewsLanguagesAddEdit; List <Language> allActiveLanguages = new Languages().GetAllLanguages(isActive: true); foreach (Language language in allActiveLanguages) { backEndNewsLanguagesAddEdit = new BackEndNewsLanguagesAddEdit(); backEndNewsLanguagesAddEdit.LanguageCode = language.LanguageCode; backEndNewsLanguagesAddEdit.LanguageName = language.LanguageName; backEndNewsAddEdit.NewsLanguages.Add(backEndNewsLanguagesAddEdit); } ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyAdded); } else { ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyEdited); } } } return(View(backEndNewsAddEdit)); }