Ejemplo n.º 1
0
        public async Task <ActionResult> DeleteSubCategory(Guid id, SubCategoryDetailsViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Bad Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
            if (id == null)
            {
                Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
            try
            {
                var result = await _subCategoryService.Delete(id);

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
                }
                Alert($"Sub Category Deleted 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(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> DeleteSubCategory(Guid id)
        {
            if (id == null)
            {
                Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }

            var subCategory = new SubCategoryDetailsViewModel();

            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.Code            = result.Data.Code;
                subCategory.Id              = result.Data.Id;
                subCategory.Name            = result.Data.Name;
                subCategory.Description     = result.Data.Description;
                subCategory.DateCreated     = result.Data.CreatedAt;
                subCategory.DateLastUpdated = result.Data.LastUpdated;
                subCategory.CategoryName    = result.Data.Category.Name;
                subCategory.CategoryId      = result.Data.Category.Id;
                return(View(subCategory));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(subCategory));
            }
        }