public virtual ActionResult Edit(int id)
        {
            var category = _categoryService.GetCategory(id);

            var model = new EditCategoryViewModel { Category = category };
            return View(model);
        }
        public virtual ActionResult Edit(EditCategoryViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Category.Name))
            {
                ModelState.AddModelError("Category.Name", "Name is required");
            }

            if (model.Category.ReOrder < 1)
            {
                ModelState.AddModelError("Category.ReOrder", "ReOrder Number must be bigger than 0");
            }

            if (ModelState.IsValid)
            {
                var result = _categoryService.Save(model.Category);

                if (result > 0)
                    return RedirectToAction(MVC.Admin.Category.Index());
            }

            return View("Edit", model);
        }
 public IActionResult AddCategory(EditCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         Category category;
         if (model.Id != null)
         {
             category      = categoryRepository.Categories.FirstOrDefault(x => x.Id == model.Id);
             category.Name = model.Name;
         }
         else
         {
             category = new Category
             {
                 Name = model.Name
             };
         }
         categoryRepository.SaveCategory(category);
         TempData["SuccessMessage"] = "Zapisano kategorię";
         return(RedirectToAction("Categories"));
     }
     return(View(model));
 }
Beispiel #4
0
        public ActionResult EditCategory(Guid id)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                var category          = _categoryService.Get(id);
                var categoryViewModel = new EditCategoryViewModel
                {
                    Name           = category.Name,
                    Description    = category.Description,
                    IsLocked       = category.IsLocked,
                    SortOrder      = category.SortOrder,
                    Id             = category.Id,
                    DateCreated    = category.DateCreated,
                    NiceUrl        = category.NiceUrl,
                    ParentCategory = category.ParentCategory == null ? Guid.Empty : category.ParentCategory.Id,
                    AllCategories  = _categoryService.GetAll()
                                     .Where(x => x.Id != category.Id)
                                     .ToList(),
                };

                return(View(categoryViewModel));
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(EditCategoryViewModel editCategory)
        {
            var files = HttpContext.Request.Form.Files;

            if (ModelState.IsValid)
            {
                var categoryToUpdate = new CategoryDto {
                    CategoryId = editCategory.Category.CategoryId
                };
                using (var ms = new MemoryStream())
                {
                    await editCategory.FormFile.CopyToAsync(ms);

                    categoryToUpdate.Picture = ms.GetBuffer();
                }


                var newCategory = await _categoryData.UpdateImageAsync(categoryToUpdate);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
        public async Task <IActionResult> EditCategoryAsync(int id)
        {
            var category = await _categoryRepository.GetCategoryByIdAsync(id);

            int _categoryId = id;

            if (category == null)
            {
                ViewBag.ErrorMessage = $"User with category id ={id} cannot be found";
                return(View("NotFound"));
            }

            IEnumerable <RentalAsset> unitItems = _rentalAssetRepository.rentalAssets.Where(p => p.CategoryId == _categoryId);

            var model = new EditCategoryViewModel
            {
                Id           = category.CategoryId,
                CategoryName = category.CategoryName,
                Description  = category.Description,
                ItemList     = unitItems
            };

            return(View(model));
        }
Beispiel #7
0
        public void EditCategory_InvalidData_RejectChanges()
        {
            Mock <ICategoryRepository> mock = new Mock <ICategoryRepository>();

            WebUI.Areas.Admin.Controllers.ManageController controller =
                new WebUI.Areas.Admin.Controllers.ManageController(null, mock.Object, null, null, null);

            Category c1 = new Category
            {
                Name = "test"
            };
            EditCategoryViewModel viewModel = new EditCategoryViewModel
            {
                Category = c1
            };

            controller.ModelState.AddModelError("error", "error");

            ActionResult result = controller.EditCategory(viewModel);

            mock.Verify(m => m.SaveCategory(It.IsAny <Category>()), Times.Never);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #8
0
        public void EditCategory_ValidData_SaveChanges()
        {
            Mock <ICategoryRepository> mock = new Mock <ICategoryRepository>();

            mock.Setup(m => m.SaveCategory(It.IsAny <Category>())).Returns(true);

            WebUI.Areas.Admin.Controllers.ManageController controller =
                new WebUI.Areas.Admin.Controllers.ManageController(null, mock.Object, null, null, null);

            Category c1 = new Category
            {
                Name = "test"
            };
            EditCategoryViewModel viewModel = new EditCategoryViewModel
            {
                Category = c1
            };

            ActionResult result = controller.EditCategory(viewModel);

            mock.Verify(m => m.SaveCategory(viewModel.Category));

            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #9
0
        // GET: Categories/Edit/5
        public async Task <IActionResult> Edit(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var category = await GetCategory(id.Value);

            if (category == null)
            {
                return(NotFound());
            }

            var categoryViewModel = new EditCategoryViewModel
            {
                Id           = category.Id,
                Name         = category.Name,
                Limit        = category.Limit,
                CategoryType = category.CategoryType,
            };

            return(View(categoryViewModel));
        }
Beispiel #10
0
        public ActionResult Edit(int id)
        {
            ApplicationDbContext _context = new ApplicationDbContext();
            // var Category = _context.Categories.SingleOrDefault(x => x.Id.Equals(id));

            //var Category = _context.Categories.SqlQuery("Select * from Categories where Id=@P0", id).SingleOrDefault();


            var Category = _context.Categories.SqlQuery("Select * from Categories where Id={0}", id).SingleOrDefault();


            if (Category == null)
            {
                return(HttpNotFound());
            }

            EditCategoryViewModel model = new EditCategoryViewModel();

            model.Id       = Category.Id;
            model.Name     = Category.Name;
            model.IsActive = Category.IsActive;

            return(View(model));
        }
        public IActionResult Edit(EditCategoryViewModel editModel)
        {
            if (ModelState.IsValid)
            {
                Category category = new Category
                {
                    CategoryId   = editModel.CategoryId,
                    CategoryName = editModel.CategoryName,
                    Description  = editModel.Description
                };

                using (var memoryStream = new MemoryStream())
                {
                    editModel.Picture.CopyTo(memoryStream);
                    category.Picture = memoryStream.ToArray();
                }

                this.categoriesRepository.Update(category);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
Beispiel #12
0
        public IActionResult EditCategory(int id)
        {
            Category category = categoryService.FindCategoryById(id);

            if (category == null)
            {
                TempData["res"] = "faild";
                return(RedirectToAction(nameof(CategoryList)));
            }
            EditCategoryViewModel Cat = new EditCategoryViewModel
            {
                Id           = category.CategoryId,
                Descrption   = category.Descrption,
                Title        = category.CatName,
                CurrentImage = category.ImgCat
            };

            ViewBag.ParentList = categoryService.GetSubCategory(id);    //حاوی پرنت هایی است که قبلا داشته

            ViewBag.CategoryList = categoryService.GetCategoryForAdd(); //جدول کتگوری است برای نمایش دادن در سلکت برای انتخاب کتگوری توسط کاربرid ,titleحاوی فیلد های


            return(View(Cat));
        }
Beispiel #13
0
 public virtual ActionResult Edit(EditCategoryViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         ModelState.AddModelError("", "آخرین بارت باشه.");
         return(View(viewModel));
     }
     try
     {
         ServiceFactory.Create <ICategoryService>()
         .Save(new Category
         {
             Id      = viewModel.Id,
             Title   = viewModel.Title,
             Version = viewModel.Version
         });
     }
     catch (DbUpdateConcurrencyException)
     {
         ModelState.AddModelError("", "گروه مورد نظر توسط کاربر دیگری در شبکه، تغییر یافته است. برای ادامه صفحه را رفرش کنید.");
         return(View(viewModel));
     }
     return(RedirectToAction("List"));
 }
        public ActionResult Update(EditCategoryViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                using (var data = new BD_NETLINKEntities1())
                {
                    var oCat = data.Categoria.Find(model.id);
                    oCat.nombre            = model.categoria;
                    data.Entry(oCat).State = System.Data.Entity.EntityState.Modified;
                    data.SaveChanges();
                }
                Session["update"] = "success";
                return(View());
            }
            catch {
                Session["update"] = "failed";
                return(View());
            }
        }
        // GET: Categories/Edit/5
        public async Task <ActionResult> Edit(Guid id)
        {
            var category = new EditCategoryViewModel();

            try
            {
                var result = await _categoryService.FindById(id);

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(category));
                }
                category.Id          = result.Data.Id;
                category.Name        = result.Data.Name;
                category.Description = result.Data.Description;
                return(View(category));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(category));
            }
        }
Beispiel #16
0
 public virtual ActionResult Add()
 {
     var category = new EditCategoryViewModel { Category = new Category() };
     return View("Edit", category);
 }
Beispiel #17
0
        public async Task <IActionResult> Edit(EditCategoryViewModel viewModel)
        {
            await this.categoriesService.EditAsync(viewModel.Id, viewModel.Name);

            return(this.RedirectToAction("Index"));
        }
Beispiel #18
0
        public IActionResult Edit(int categoryId)
        {
            EditCategoryViewModel model = _categoryWebService.GetCategoryById(categoryId);

            return(View($"{CategoriesViewFolder}/Edit.cshtml", model));
        }
        public EditCategoryPage(EditCategoryViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;
        }
Beispiel #20
0
 public ActionResult Edit(EditCategoryViewModel ecvm)
 {
     this.cs.UpdateCategory(ecvm);
     return(RedirectToAction("Index", "Category", new { area = "Admin" }));
 }
Beispiel #21
0
        public async Task <IActionResult> EditDrinkType(EditCategoryViewModel drinkType)
        {
            await this.drinkTypeService.EditDrinkTypeAsync(drinkType, this.webHostEnvironment.WebRootPath);

            return(this.RedirectToAction("Index", "Menu"));
        }
 public IActionResult EditCategory(EditCategoryViewModel data)
 {
     _categoryRepository.Update(data);
     return(Ok());
 }
Beispiel #23
0
 public EditCategory(GoodCategory category)
 {
     InitializeComponent();
     _model         = new EditCategoryViewModel(category, new System.Net.Http.HttpClient(), this);
     BindingContext = _model;
 }
        public ActionResult EditCategory(EditCategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                this.TempData["NotificationError"] = "Something is wrong, please try again later";
                return this.View(model);
            }

            this.categories.UpdateCategory(model.Id, model.Name);
            this.TempData["Notification"] = "You successfully update category";

            return this.RedirectToAction("Index");
        }
Beispiel #25
0
 public IActionResult Edit(EditCategoryViewModel vm)
 {
     _category.Update(vm);
     return(RedirectToAction("Index", "Categories"));
 }
Beispiel #26
0
        public ActionResult EditCategory(EditCategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var category = _categoryService.Get(categoryViewModel.Id);

                        category.Description     = categoryViewModel.Description;
                        category.IsLocked        = categoryViewModel.IsLocked;
                        category.ModeratePosts   = categoryViewModel.ModeratePosts;
                        category.ModerateTopics  = categoryViewModel.ModerateTopics;
                        category.Name            = categoryViewModel.Name;
                        category.SortOrder       = categoryViewModel.SortOrder;
                        category.PageTitle       = categoryViewModel.PageTitle;
                        category.MetaDescription = categoryViewModel.MetaDesc;

                        if (categoryViewModel.ParentCategory != null)
                        {
                            // Set the parent category
                            var parentCategory = _categoryService.Get(categoryViewModel.ParentCategory.Value);
                            category.ParentCategory = parentCategory;

                            // Append the path from the parent category
                            SortPath(category, parentCategory);
                        }
                        else
                        {
                            // Must access property (trigger lazy-loading) before we can set it to null (Entity Framework bug!!!)
                            var triggerEfLoad = category.ParentCategory;
                            category.ParentCategory = null;

                            // Also clear the path
                            category.Path = null;
                        }

                        _categoryService.UpdateSlugFromName(category);

                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Category Updated",
                            MessageType = GenericMessages.success
                        };

                        categoryViewModel = CreateEditCategoryViewModel(category);

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        LoggingService.Error(ex);
                        unitOfWork.Rollback();

                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Category Update Failed",
                            MessageType = GenericMessages.error
                        };
                    }
                }
            }

            return(View(categoryViewModel));
        }
Beispiel #27
0
        public async Task <IActionResult> EditById(EditCategoryViewModel viewModel)
        {
            await this.categoriesService.EditById(viewModel.Id, viewModel.Title);

            return(this.Content("edited"));
        }
        public ActionResult EditCategory(int id, string name)
        {
            var categoryToEdit = new EditCategoryViewModel
            {
                Id = id,
                Name = name
            };

            return this.PartialView("_EditCategoryPartial", categoryToEdit);
        }