public async Task <ActionResult> EditSubCategory(Guid id, EditSubCategoryViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(request.Id))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var subCategoryEditRequest = new UpdateSubCategoryRequest {
                    Id = request.Id, Name = request.Name, Description = request.Description, CategoryId = request.CategoryId
                };
                var result = await _subCategoryService.Update(id, subCategoryEditRequest);

                if (!result.Success)
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }

                Alert($"Sub Category Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
        public async Task <ActionResult> EditSubcategory(Guid id)
        {
            var subCategory = new EditSubCategoryViewModel();

            try
            {
                var result = await _subCategoryService.FindByIdInclusive(id, x => x.Include(p => p.Category));

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(subCategory));
                }
                subCategory.Id           = result.Data.Id;
                subCategory.Name         = result.Data.Name;
                subCategory.Description  = result.Data.Description;
                subCategory.CategoryId   = result.Data.Category.Id;
                subCategory.CategoryName = result.Data.Category.Name;
                return(View(subCategory));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(subCategory));
            }
        }
Esempio n. 3
0
        public IActionResult Edit(string id)
        {
            SubCategory subCategory        = _db.SubCategories.FirstOrDefault(c => c.Id == id);
            EditSubCategoryViewModel model = new EditSubCategoryViewModel {
                Id = id, Name = subCategory.Name, Category = subCategory.Category
            };

            return(View(model));
        }
        public void AddSubCategory(EditSubCategoryViewModel model)
        {
            using (var context = new HardwareShopContext())
            {
                var subCategory = Mapper.Map <SubCategory>(model);

                context.SubCategories.Add(subCategory);
                context.SaveChanges();
            }
        }
        public ActionResult Edit(EditSubCategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.Categories = this.categoryService.GetAllCategories();
                return(this.View(model));
            }

            this.subCategoryService.EditSubCategory(model);
            return(this.RedirectToAction("List", "Category"));
        }
        public void EditSubCategory(EditSubCategoryViewModel model)
        {
            using (var context = new HardwareShopContext())
            {
                var subCategory = this.GetSubCategoryById(model.SubCategoryId, context);
                subCategory.CategoryId = model.CategoryId;
                subCategory.Name       = model.Name;

                context.Entry(subCategory).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(EditSubCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                SubCategory subCategory = _db.SubCategories.FirstOrDefault(c => c.Id == model.Id);
                if (model.Name != subCategory.Name)
                {
                    subCategory.EditedTime = DateTime.Now;
                }
                subCategory.Name             = model.Name;
                _db.Entry(subCategory).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }