Exemplo n.º 1
0
        public async Task <IActionResult> Update(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            WelcomeAbout welcomeAbout = await _db.WelcomeAbouts.FindAsync(id);

            if (welcomeAbout == null)
            {
                return(NotFound());
            }
            return(View(welcomeAbout));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update(int?id, WelcomeAbout welcomeAbout)
        {
            if (id == null)
            {
                return(NotFound());
            }
            WelcomeAbout dbwelcomeAbout = await _db.WelcomeAbouts.FindAsync(id);

            if (dbwelcomeAbout == null)
            {
                return(NotFound());
            }
            if (welcomeAbout.Photo != null)
            {
                if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                {
                    return(View());
                }

                if (!welcomeAbout.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin");
                    return(View());
                }

                if (welcomeAbout.Photo.MaxLength(200))
                {
                    ModelState.AddModelError("Photo", "Shekilin olchusu max 200kb ola biler");
                    return(View());
                }

                string path = Path.Combine("img", "about");
                Helper.DeleteImage(_env.WebRootPath, path, dbwelcomeAbout.Image);
                string fileName = await welcomeAbout.Photo.SaveImg(_env.WebRootPath, path);

                dbwelcomeAbout.Image = fileName;
            }
            dbwelcomeAbout.Description = welcomeAbout.Description;
            dbwelcomeAbout.Title       = welcomeAbout.Title;

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        public IActionResult Index()
        {
            WelcomeAbout welcomeAbout = _db.WelcomeAbouts.FirstOrDefault();

            return(View(welcomeAbout));
        }