示例#1
0
        public async Task <IActionResult> Edit(int id, SettingViewModel model)
        {
            if (id != model.Setting.Id)
            {
                return(NotFound());
            }
            if (model.Setting.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(webHostEnvironment);
                    model.Setting.PhotoLogo = fileManager.Upload(model.Setting.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                foreach (var setTranslate in model.SettingTranslates)
                {
                    _context.Update(setTranslate);
                }
                try
                {
                    model.Setting.ModifiedAt = DateTime.Now;
                    _context.Update(model.Setting);
                    await _context.SaveChangesAsync();

                    TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SettingExists(model.Setting.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"] = new SelectList(_context.AdminManagers, "Id", "Email", model.Setting.AdminManagerId);
            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Name,Slug,Status,CreatedAt,Id,AdminManagerId,ModifiedAt")] Brand brand)
        {
            if (id != brand.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(brand);
                    await _context.SaveChangesAsync();

                    TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"] = new SelectList(_context.AdminManagers, "Id", "Email", brand.AdminManagerId);
            return(View(brand));
        }
        public async Task <IActionResult> Edit(int id, HomeHeaderViewModel model)
        {
            if (id != model.HomeHeader.Id)
            {
                return(NotFound());
            }
            if (model.HomeHeader.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(webHostEnvironment);
                    model.HomeHeader.Photo = fileManager.Upload(model.HomeHeader.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("HomeHeader_PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                foreach (var item in model.HomeHeaderTranslates)
                {
                    item.HomeHeaderId = id;
                    _context.HomeHeaderTranslates.Update(item);
                }
                await _context.SaveChangesAsync();

                try
                {
                    model.HomeHeader.ModifiedAt = DateTime.Now;
                    _context.Update(model.HomeHeader);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeHeaderExists(model.HomeHeader.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", model.HomeHeader.ProductId);
            return(View(model));
        }
示例#4
0
 public async Task <IActionResult> Edit(int id, ProductPhoto productPhoto)
 {
     if (id != productPhoto.Id)
     {
         return(NotFound());
     }
     if (productPhoto.PhotoUpload != null)
     {
         try
         {
             FileManager fileManager = new FileManager(_webHostEnvironment);
             productPhoto.Photo = fileManager.Upload(productPhoto.PhotoUpload);
         }
         catch (Exception e)
         {
             ModelState.AddModelError("PhotoUpload", e.Message);
         }
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(productPhoto);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ProductPhotoExists(productPhoto.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", productPhoto.ProductId);
     return(View(productPhoto));
 }
        public async Task <IActionResult> Edit(int id, ProperityViewModel model)
        {
            if (id != model.Properity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                foreach (var item in model.ProperityTranslates)
                {
                    item.ProperityId = id;
                    _context.ProperityTranslates.Update(item);
                }
                await _context.SaveChangesAsync();

                try
                {
                    model.Properity.ModifiedAt = DateTime.Now;
                    _context.Update(model.Properity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProperityExists(model.Properity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }