Ejemplo n.º 1
0
        public IActionResult Edit(EventItem model, IFormFile titleImageFile)
        {
            if (ModelState.IsValid)
            {
                if (titleImageFile != null)
                {
                    string saveName = titleImageFile.ToSaveFileName(out bool mustSave);

                    if (mustSave && saveName.Equals(string.Empty))
                    {
                        ModelState.AddModelError("SaveImgError", $"В базе картинок существует другой файл с именем: \"{titleImageFile.FileName}\"," +
                                                 $" переименуйте исходный файл при дальнейшем редактирование  \"{model.Title}\", или нажмите \"Сохранить\" (без сохранения/изменения картинки).");
                        return(View(model));
                    }
                    model.TitleImagePath = titleImageFile.FileName;
                    if (mustSave)
                    {
                        using var stream = new FileStream(saveName, FileMode.Create);
                        titleImageFile.CopyTo(stream);
                    }
                }
                AutoSEO.Set(model);
                dataManager.EventItems.SaveItem(model);
                return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).CutController()));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
 public IActionResult Edit(TextField model)
 {
     if (ModelState.IsValid)
     {
         AutoSEO.Set(model);
         dataManager.TextFields.SaveItem(model);
         return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).CutController()));
     }
     return(View(model));
 }