public IActionResult EditCategory(int id) { ViewData["Title"] = _settings.ApplicationTitle + "Администрирование: Добавление/Редактирование категории"; ViewData["HeaderTitle"] = _settings.HeaderTitle; ViewData["FooterTitle"] = _settings.FooterTitle; ViewBag.ActiveSubMenu = "Категории"; if (id != 0) { return(View(_repositoryCategory.GetCategoryById(id))); } else { return(View(new Category())); } }
public IActionResult EditArticle(CreateEditArticleViewModel model) { if (ModelState.IsValid) { //ТЕКУЩИЙ ПОЛЬЗОВАТЕЛЬ var currentUser = _repositoryUser.GetCurrentUser(User.Identity.Name); //ПОЛУЧАЕМ КОМПАНИЮ РОДИТЕЛЯ ОПРЕДЕЛЯЕМУЮ ТЕКУЩИМ ПОЛЬЗОВАТЕЛЕМ Company company = new Company(); if (currentUser != null) { company = _repositoryCompany.GetUserCompany(currentUser); } else { return(RedirectToAction("Articles")); } //ФОРМИРУЕМ СПИСОК ИЗОБРАЖЕНИЙ List <RelGoodImage> relImages = new List <RelGoodImage>(); //если строка id изображений непуста тогда формируем список if (model.goodImagesIds != null) { string[] strImgids = model.goodImagesIds.Trim().Substring(0, model.goodImagesIds.Length - 1).Split('_'); foreach (var strImageId in strImgids) { if (strImageId.Length == 0) { continue; //это случай когдау товара нет изображений, но в массив все равно попадает распарсеная пустая строка } relImages.Add(new RelGoodImage { GoodId = model.Id, ImageId = Convert.ToInt32(strImageId) }); } } //формирование разделителей //model.Description = model.Description.Replace("\r\n", "[newstr]"); _repositoryArticle.SaveArticle(new Article { Id = model.Id, Title = model.Title, EnTitle = model.EnTitle, Description = model.Description, Link = model.Link, HashTags = model.HashTags, CategoryId = Convert.ToInt32(model.CategoryId), CategoryType = _repositoryCategory.GetCategoryById(Convert.ToInt32(model.CategoryId)).CategoryType, Images = relImages, UpdateTime = DateTime.Now, metaDescription = model.metaDescription, metaKeyWords = model.metaKeyWords }, company); if (model.deletedImagesIds != null) { int[] ids = GetIntIds.ConvertIdsToInt(model.deletedImagesIds).ToArray(); _repositoryImage.DeleteImages(ids); } } return(RedirectToAction("Articles")); }
public Category GetCategoryById(int id) { var result = iRepositoryCategory.GetCategoryById(id); return(mapCategories.MapTo(result)); }