Ejemplo n.º 1
0
        public void Update(EditCategoryVM category)
        {
            var selectedCategory = context.Categories.Find(category.Id);

            selectedCategory.Title = category.Title;
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Display a window for creating a new File Sorting Category.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="editing">The FileCategory being edited, or null if creating a new Category.</param>
        public void EditCategoryDialog(ViewModelBase parentModel, FileCategory editing = null)
        {
            EditCategoryVM     newCategory = new EditCategoryVM(this.CategoryManager.Current, editing);
            EditCategoryWindow win         = new EditCategoryWindow();

            this.InitView(win, newCategory, parentModel);

            win.Show();
        }         //
Ejemplo n.º 3
0
        internal void UpdateCategory(int id, EditCategoryVM newModel)
        {
            var oldCategory = Category.SingleOrDefault(c => c.CategoryId == id);

            oldCategory.Title = newModel.CategoryTitle;
            oldCategory.Order = newModel.Order;

            SaveChanges();
        }
        // GET: Categories
        public async Task<IActionResult> Index()
        {
            var Categories = await _context.Categories.ToListAsync();

            var EditCategoryVM = new EditCategoryVM
            {
                Categories = Categories
            };

            return View(EditCategoryVM);
        }
Ejemplo n.º 5
0
        internal EditCategoryVM GetEditCategoryVMById(int id)
        {
            var q = Category
                    .SingleOrDefault(c => c.CategoryId == id);

            EditCategoryVM model = new EditCategoryVM
            {
                CategoryTitle = q.Title,
                Order         = q.Order,
            };

            return(model);
        }
Ejemplo n.º 6
0
        public IActionResult Edit(EditCategoryVM model)
        {
            if (ModelState.IsValid)
            {
                var entity = _categoryRepository.Get(model.Id);
                CheckIfNotNull(entity);

                entity = _mapper.Map(model, entity);
                _imageService.Upload(entity, model.File, EImageType.Category);
                _categoryRepository.Update(entity);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 7
0
        public IActionResult Edit(EditCategoryVM model)
        {
            if (ModelState.IsValid)
            {
                Category category = _context.Categories.Find(model.Id);
                if (category == null)
                {
                    return(NotFound());
                }
                category.Name = model.Name;

                if (model.Photo != null)
                {
                    if (model.ExsistingPhoto != null)
                    {
                        string filePath = Path.Combine(_hostingEnv.WebRootPath,
                                                       "img", model.ExsistingPhoto);
                        System.IO.File.Delete(filePath);
                    }

                    string uniqueFileName = null;

                    if (model.Photo != null)
                    {
                        string uploadsFolder = Path.Combine(_hostingEnv.WebRootPath, "img");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            model.Photo.CopyTo(fileStream);
                        }
                    }

                    category.ImagePath = uniqueFileName;
                }

                _context.Categories.Update(category);
                _context.SaveChanges();
                return(RedirectToAction("index"));
            }

            return(View(model));
        }
Ejemplo n.º 8
0
        public IActionResult Edit(EditCategoryVM categoryVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(categoryVM));
            }
            //veritabanında yer alan orjinal bilgiler
            var categoryInDb = _context.Categories.Find(categoryVM.Id);

            //formdan gelen verilerle veritabanında yer alan kayıt güncelleniyor
            categoryInDb.Name       = categoryVM.Name;
            categoryInDb.IsActive   = categoryVM.IsActive;
            categoryInDb.LastupUser = "******";
            categoryInDb.LastupDate = DateTime.Now;

            _context.Categories.Update(categoryInDb);
            _context.SaveChanges();

            return(RedirectToAction("List"));
        }
Ejemplo n.º 9
0
        // GET: Categories/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(View("NotFound"));
            }

            var category = await _context.Categories.FindAsync(id);

            if (category == null)
            {
                return(View("NotFound"));
            }
            EditCategoryVM editCategoryVM = new EditCategoryVM {
                Id             = category.CartegoryId,
                ExsistingPhoto = category.ImagePath,
                Name           = category.Name
            };

            return(View(editCategoryVM));
        }
Ejemplo n.º 10
0
        public IActionResult Update(EditCategoryVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var existingCategories = categoryService.GetAll();

            foreach (var existingCategory in existingCategories)
            {
                if (string.Equals(existingCategory.Title.ToLower(), model.Title.ToLower()))
                {
                    ModelState.AddModelError("", "You already have this category");
                    return(View(model));
                }
            }

            categoryService.Update(model);

            return(RedirectToAction(nameof(CategoryController.Index)));
        }
Ejemplo n.º 11
0
        public IActionResult Create(EditCategoryVM categoryVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(categoryVM));
            }

            _context.Categories.Add(new Category
            {
                Name       = categoryVM.Name,
                IsActive   = categoryVM.IsActive,
                CreateUser = "******",
                LastupUser = "******",
                CreateDate = DateTime.Now,
                LastupDate = DateTime.Now
            });
            _context.SaveChanges();

            TempData["success"] = "<b>Kategori</b> başarıyla eklendi.";

            return(RedirectToAction("List"));
        }
Ejemplo n.º 12
0
        public IActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(BadRequest("Düzenlenecek kategori numarası gönderilmedi."));
            }
            //var categoryInDb = _context.Categories.SingleOrDefault(c => c.Id == id);
            var categoryInDb = _context.Categories.Find(id);

            if (categoryInDb == null)
            {
                return(NotFound("Belirtilen kategori numarasına karşılık gelen bir kategori bulunamadı."));
            }

            var categoryVM = new EditCategoryVM
            {
                Id       = categoryInDb.Id,
                Name     = categoryInDb.Name,
                IsActive = categoryInDb.IsActive
            };

            return(View(categoryVM));
        }
Ejemplo n.º 13
0
        public IActionResult EditCategory(int id, EditCategoryVM model)
        {
            context.UpdateCategory(id, model);

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 14
0
        public IActionResult EditCategory(int id)
        {
            EditCategoryVM model = context.GetEditCategoryVMById(id);

            return(View(model));
        }