public ActionResult Delete(int id, EventCategoryMvcViewModel model) { var result = _eventCategoryService.Delete(id); if (!result.Succeeded) { ModelState.AddModelError("", $"Ошибки при удалении категории:</br>" + $"{string.Join("</br>", result.Errors)}"); return(View(model)); } return(RedirectToAction("Index")); }
private static void TransformToModel(EventCategoryDto source, EventCategoryMvcViewModel destination) { var localizations = source.EventCategoryLocalizations; if (localizations == null || localizations.Count == 0) { return; } var ruLocalization = localizations.FirstOrDefault(c => c.LanguageId == (int)CultureLanguage.RU); var enLocalization = localizations.FirstOrDefault(c => c.LanguageId == (int)CultureLanguage.EN); destination.NameRu = ruLocalization?.Name; destination.NameEn = enLocalization?.Name; }
public ActionResult Create(EventCategoryMvcViewModel model) { if (ModelState.IsValid == false) { return(View(model)); } var result = _eventCategoryService.Save(Mapper.Map <EventCategoryDto>(model)); if (!result.Succeeded) { ModelState.AddModelError("", $"Ошибки при добавлении категории:</br>" + $"{string.Join("</br>", result.Errors)}"); return(View(model)); } return(RedirectToAction("Index")); }
private static void Localize(EventCategoryDto source, EventCategoryMvcViewModel destination) { var language = LanguageHelper.GetThreadLanguage(); switch (language) { case CultureLanguage.EN: destination.LocalizedName = source.EventCategoryLocalizations .FirstOrDefault(c => c.LanguageId == 1)?.Name; break; case CultureLanguage.Undefined: case CultureLanguage.RU: case null: default: destination.LocalizedName = source.EventCategoryLocalizations .FirstOrDefault(c => c.LanguageId == 2)?.Name; break; } }
public ActionResult Edit(EventCategoryMvcViewModel model) { if (ModelState.IsValid == false) { return(View(model)); } if (model.Id == 0) { throw new HttpException((int)HttpStatusCode.InternalServerError, "Не указан идентификатор категории"); } var result = _eventCategoryService.Save(Mapper.Map <EventCategoryDto>(model)); if (!result.Succeeded) { ModelState.AddModelError("", $"Ошибки при обновлении категории:</br>" + $"{string.Join("</br>", result.Errors)}"); return(View(model)); } return(RedirectToAction("Index")); }
private static void TransformToDto(EventCategoryMvcViewModel source, EventCategoryDto destination) { var enLocalization = string.IsNullOrEmpty(source.NameEn) ? null : new EventCategoryLocalizationDto { EventCategoryId = source.Id, LanguageId = (int)CultureLanguage.EN, Name = source.NameEn }; var ruLocalization = string.IsNullOrEmpty(source.NameRu) ? null : new EventCategoryLocalizationDto { EventCategoryId = source.Id, LanguageId = (int)CultureLanguage.RU, Name = source.NameRu }; var localizations = new List <EventCategoryLocalizationDto>(); if (enLocalization != null) { localizations.Add(enLocalization); } if (ruLocalization != null) { localizations.Add(ruLocalization); } destination.EventCategoryLocalizations = (localizations.Count > 0) ? localizations : null; }