public async Task <IActionResult> Edit(int id, [Bind("Id,About,Title,Desc,Button,Photo,Upload")] MostPartner mostPartner)
        {
            if (id != mostPartner.Id)
            {
                return(NotFound());
            }

            if (mostPartner.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var oldFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", mostPartner.Photo);
                    _fileManager.Delete(oldFile);
                    var fileName = _fileManager.Upload(mostPartner.Upload);
                    mostPartner.Photo = fileName;

                    _context.Update(mostPartner);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MostPartnerExists(mostPartner.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mostPartner));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Text,Photo,Upload")] BusinesSolution businesSolution)
        {
            if (id != businesSolution.Id)
            {
                return(NotFound());
            }
            if (businesSolution.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var oldFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", businesSolution.Photo);
                    _fileManager.Delete(oldFile);
                    var fileName = _fileManager.Upload(businesSolution.Upload);
                    businesSolution.Photo = fileName;

                    _context.Update(businesSolution);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinesSolutionExists(businesSolution.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(businesSolution));
        }