Exemple #1
0
        public async Task <IActionResult> Create(CreateTextVewModel createTextVm)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                if (createTextVm.Photo != null)
                {
                    uniqueFileName = GetUniqueFileName(createTextVm.Photo.FileName);
                    var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
                    var filePath = Path.Combine(uploads, uniqueFileName);
                    createTextVm.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                var newText = new Text()
                {
                    Title       = createTextVm.Title,
                    Paragraph1  = createTextVm.Paragraph1,
                    Paragraph2  = createTextVm.Paragraph2,
                    Paragraph3  = createTextVm.Paragraph3,
                    Paragraph4  = createTextVm.Paragraph4,
                    Paragraph5  = createTextVm.Paragraph5,
                    Paragraph6  = createTextVm.Paragraph6,
                    Paragraph7  = createTextVm.Paragraph7,
                    Paragraph8  = createTextVm.Paragraph8,
                    Paragraph9  = createTextVm.Paragraph9,
                    Paragraph10 = createTextVm.Paragraph10,
                    Photo       = uniqueFileName,
                    TextType    = createTextVm.TextType,
                    DateAdded   = DateTime.Now.ToString("dd.MM.yyyy")
                };
                _context.Texts.Add(newText);
                await _context.SaveChangesAsync();

                return(RedirectToAction("IndexAdmin", "Texts"));
            }
            return(View(createTextVm));
        }
Exemple #2
0
        public IActionResult Create()
        {
            var textVm = new CreateTextVewModel();

            return(View(textVm));
        }