public async Task <ActionResult> Delete(Guid id, CategoryDetailsViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Bad Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (id == null)
            {
                Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var result = await _categoryService.Delete(id);

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
                Alert($"Category Deleted Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
        // GET: Categories/Details/5
        public async Task <ActionResult> Details(Guid id)
        {
            var categories = new CategoryDetailsViewModel();

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

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(categories));
                }
                categories.Code            = result.Data.Code;
                categories.Id              = result.Data.Id;
                categories.Name            = result.Data.Name;
                categories.Description     = result.Data.Description;
                categories.DateCreated     = result.Data.CreatedAt;
                categories.DateLastUpdated = result.Data.LastUpdated;
                return(View(categories));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(categories));
            }
        }
        public IActionResult DetailsById(CategoryDetailsViewModel viewModel)
        {
            viewModel.Name = this.categoriesService.GetNameById(viewModel.Id);

            if (viewModel.Name == null)
            {
                return(this.NotFound());
            }

            viewModel.Freelancers = this.usersService.GetAll <FreelancerViewModel>()
                                    .Where(f => f.Categories.Any(c => c == viewModel.Name));

            if (viewModel.Order == GlobalConstants.AlphabeticalOrder)
            {
                viewModel.Freelancers = viewModel.Freelancers.OrderBy(f => f.UserName).ToList();
            }

            if (viewModel.Order == GlobalConstants.RatingOrder)
            {
                viewModel.Freelancers = viewModel.Freelancers.OrderByDescending(f => f.Stars).ToList();
            }

            viewModel.Freelancers.Select(f =>
            {
                f.Categories  = f.Categories.Take(3);
                f.EncryptedId = this.protector.Protect(f.Id);
                return(f);
            }).ToList();

            viewModel.Projects = this.projectsService.GetAll <ProjectViewModel>()
                                 .Where(p => p.CategoriesId.Any(id => id == viewModel.Id));

            return(this.View(viewModel));
        }
Beispiel #4
0
        public ActionResult Details(Guid?categoryId)
        {
            if (categoryId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Category category = _categoryService.GetCategoryById(categoryId);

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

            CategoryDetailsViewModel model = new CategoryDetailsViewModel()
            {
                CategoryId   = category.CategoryId,
                CategoryName = category.Name
            };

            category.Subcategories.ForEach(s => model.Subcategories.Add(new SubcategoryInCategoryViewModel()
            {
                SubcategoryId   = s.SubcategoryId,
                SubcategoryName = s.Name
            }));
            return(View(model));
        }
        //public string CategoryNames { get; set; }

        public static LocationDetailsViewModel GetLocationDetailsViewModel(ApplicationDbContext context, int locationId)
        {
            LocationDetailsViewModel locationDetailsViewModel = new LocationDetailsViewModel();

            Models.Location location = context.Locations
                                       .Include(l => l.LocationCategories)
                                       .FirstOrDefault(l => l.Id == locationId);


            List <Models.Review> reviews = context.Reviews
                                           .Where(r => r.LocationID == locationId)
                                           .ToList();

            var selectedCategories = context.LocationCategories
                                     .Where(locationCategory => locationCategory.LocationId == locationId)
                                     .ToList();

            List <Category> categories = context.Categories
                                         .ToList();

            selectedCategories.ForEach(selectedCategory =>
                                       selectedCategory.Category = categories.Single(category =>
                                                                                     category.Id == selectedCategory.CategoryId
                                                                                     )
                                       );



            //IList<Models.LocationCategory> categories = location.LocationCategories;

            IList <ReviewDetailsViewModel> reviewDetailsViewModels = new List <ReviewDetailsViewModel>();

            foreach (Models.Review review in reviews)
            {
                ReviewDetailsViewModel reviewDetailsViewModel = new ReviewDetailsViewModel();
                reviewDetailsViewModel.Rating  = review.Rating;
                reviewDetailsViewModel.Comment = review.Comment;
                reviewDetailsViewModels.Add(reviewDetailsViewModel);
            }



            List <CategoryDetailsViewModel> categoryDetailsViewModels = new List <CategoryDetailsViewModel>();

            foreach (Models.LocationCategory selectedCategory in selectedCategories)
            {
                CategoryDetailsViewModel categoryDetailsViewModel = new CategoryDetailsViewModel();
                categoryDetailsViewModel.Name = selectedCategory.Category.CategoryName;
                categoryDetailsViewModels.Add(categoryDetailsViewModel);
            }

            return(new LocationDetailsViewModel()
            {
                Name = location.Name,
                Description = location.Description,
                Id = location.Id,
                ReviewDetailsViewModels = reviewDetailsViewModels.ToList(),
                CategoryDetailsViewModels = categoryDetailsViewModels.ToList()
            });
        }
        public CategoriesDetailsPage(IPageService pageService, IRepository repository, CategoryDto category)
        {
            InitializeComponent();

            this.pageService = pageService;
            this.repository  = repository;
            detailsVM        = new CategoryDetailsViewModel(pageService, repository, category);
        }
        public ActionResult <IEnumerable <CategoryDetailsViewModel> > Index(ISearchCategoryModel search)
        {
            var vm = this.manager.SearchProductCategory(search)
                     .Select(CategoryDetailsViewModel.FromEntity(search.Language ?? base.AppSettings.DefaultLanguage))
                     .ToArray();

            return(vm);
        }
        public ActionResult <CategoryDetailsViewModel> Details(int id, TranslationLanguage?language = null)
        {
            var vm = this.manager.GetQueryById(id)
                     .Select(CategoryDetailsViewModel.FromEntity(language ?? base.AppSettings.DefaultLanguage))
                     .FirstOrDefault();

            return(vm);
        }
Beispiel #9
0
        public ActionResult Details(int Id)
        {
            CategoryDetailsViewModel model = new CategoryDetailsViewModel();

            model.category = CategoryService.Instance.CategoryById(Id);

            return(PartialView(model));
        }
Beispiel #10
0
        public async Task <IActionResult> Details(string categoryAlias, int page = 1, int size = 10)
        {
            var pageDto     = new PageDto(page, size);
            var categoryDto = await _categoryService.GetAsync(categoryAlias);

            var threadDtoList = await _threadService.PagedListAsync(categoryDto.Id, pageDto);

            var isCurrentUserCategoryModerator = await _categoryToModeratorService
                                                 .IsUserCategoryModeratorAsync(categoryDto.Id, User);

            if ((categoryDto.IsDeleted) && (!isCurrentUserCategoryModerator))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound, $"Category {categoryDto.Alias} not found.");
            }

            var threadDetailsViewModels = _mapper.Map <IList <ThreadDetailsViewModel> >(threadDtoList.CurrentPageItems);

            foreach (var threadDetailsViewModel in threadDetailsViewModels)
            {
                var postsDtoListReversed = await _postService
                                           .PagedListAsync(
                    post => (!post.IsDeleted) && (post.Thread.Id == threadDetailsViewModel.Id),
                    post => post.Created,
                    true,
                    new PageDto(1, 3));

                var postCount             = postsDtoListReversed.TotalItemsCount;
                var lastPostsDtoList      = postsDtoListReversed.CurrentPageItems.OrderBy(post => post.Created).ToList();
                var postDetailsViewModels = _mapper.Map <IList <PostDetailsViewModel> >(lastPostsDtoList);
                foreach (var latestPostDetailsViewModel in postDetailsViewModels)
                {
                    latestPostDetailsViewModel.ThreadShowThreadLocalUserHash = threadDetailsViewModel.ShowThreadLocalUserHash;
                    latestPostDetailsViewModel.CategoryAlias = categoryDto.Alias;
                    latestPostDetailsViewModel.CategoryId    = categoryDto.Id;
                }

                threadDetailsViewModel.Posts         = postDetailsViewModels;
                threadDetailsViewModel.CategoryAlias = categoryDto.Alias;
                threadDetailsViewModel.CategoryName  = categoryDto.Name;
                threadDetailsViewModel.PostCount     = postCount;
            }

            var categoryViewModel        = _mapper.Map <CategoryViewModel>(categoryDto);
            var categoryDetailsViewModel = new CategoryDetailsViewModel
            {
                Category = categoryViewModel,
                Threads  = new BasePagedList <ThreadDetailsViewModel>
                {
                    TotalItemsCount  = threadDtoList.TotalItemsCount,
                    CurrentPage      = pageDto,
                    CurrentPageItems = threadDetailsViewModels,
                },
            };

            return(View(categoryDetailsViewModel));
        }
        public ActionResult Details(int ID)
        {
            CategoryDetailsViewModel model = new CategoryDetailsViewModel();

            model.Category = categoriesService.GetCategoryByID(ID);

            model.PageTitle       = "Auction Details:" + model.Category.Name;
            model.PageDescription = model.Category.Description.Substring(0, 10);
            return(View(model));
        }
        public IActionResult Delete(CategoryDetailsViewModel model)
        {
            bool success = this.categoryService.Remove(model.Id);

            if (!success)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            return(this.RedirectToAction("All", "Categories"));
        }
        public ActionResult Details(int id)
        {
            var model = new CategoryDetailsViewModel();

            model.Category = CategoriesService.Instance.GetCategory(id);

            model.PageTitle       = model.Category.Name;
            model.PageDescription = model.Category.Description != null ? (model.Category.Description.Length > 10 ? model.Category.Description.Substring(0, 10) : model.Category.Description) : "Category details.";

            return(View(model));
        }
Beispiel #14
0
 public static CategoryEntity ToBllCategoryEntity(this CategoryDetailsViewModel viewModel)
 {
     return(new CategoryEntity()
     {
         CategoryName = viewModel.CategoryName,
         Id = viewModel.Id,
         IsConfirmed = viewModel.IsConfirmed,
         SectionRefId = viewModel.SectionRefId,
         CreationDate = viewModel.CreationDate,
         IsBlocked = viewModel.IsBlocked
     });
 }
Beispiel #15
0
        public IActionResult BrowseCatalogue()
        {
            // Call our CategoryDetailsService
            // THAT gives us a list of category details
            CategoryDetailsService categoryDetailsService = new CategoryDetailsService(_configuration);
            List <CategoryDetails> listCategories         = categoryDetailsService.ListCategories();
            // then we make a Model based on that list
            CategoryDetailsViewModel categoryDetailsModel = new CategoryDetailsViewModel(listCategories);

            // finally return the view using that model.
            return(View(categoryDetailsModel));
        }
Beispiel #16
0
        public int AddCategory(CategoryDetailsViewModel categoryDetails)
        {
            string sqlQuery = "INSERT INTO Category_Details(Category_Name) VALUES (@pCategoryName);";

            //connect to db
            using (var connection = new   MySqlConnection(_configuration.GetConnectionString("LibraryDatabase")))
            {
                var affectedRows = connection.Execute(sqlQuery, new { pCategoryName = categoryDetails._Category.Category_Name });

                return(affectedRows);
            }
        }
        public async Task <ActionResult> Details(int id)
        {
            var category = await categoryService.GetCategoryAsync(id, context);

            var products = await categoryService.GetProductsInCategory(id, context);

            var viewModel = new CategoryDetailsViewModel {
                Category = category, Products = products
            };

            return(View(viewModel));
        }
Beispiel #18
0
        public IActionResult Details()
        {
            IEnumerable <Hamper>   hampers = _hamperDataService.GetAll();
            IEnumerable <Category> cat     = _categoryDataService.GetAll();

            CategoryDetailsViewModel vm = new CategoryDetailsViewModel
            {
                Hampers    = hampers,
                Categories = cat
            };

            return(View(vm));
        }
Beispiel #19
0
        public IActionResult CategoryDetails(string categoryName)
        {
            var category    = Db.Single <Category>(x => x.UrlName == categoryName);
            var photoEvent  = Db.LoadSelect <PhotoEvent>(x => x.CategoryId == category.Id);
            var schoolYears = photoEvent.Select(x => x.SchoolYear).Distinct().ToList();

            var vm = new CategoryDetailsViewModel
            {
                Category    = category,
                SchoolYears = schoolYears
            };

            return(View(vm));
        }
Beispiel #20
0
        public async Task <IActionResult> Details(int id)
        {
            var model = new CategoryDetailsViewModel
            {
                Category = await this.categories.ByIdAsync(id),
                Topics   = await this.topics.ByCategoryIdAsync(id)
            };

            if (model.Category == null || model.Topics == null)
            {
                return(NotFound());
            }

            return(View(model));
        }
Beispiel #21
0
        public void ReturnViewWithEmptyModel_WhenParameterIsNull()
        {
            // Arrange
            var categoryServiceMock = new Mock <ICategoryService>();

            var categoryViewModel = new CategoryDetailsViewModel();

            categoryServiceMock.Setup(m => m.GetById(null)).Returns((Category)null);

            CategoryController categoryController = new CategoryController(categoryServiceMock.Object);

            // Act & Assert
            categoryController
            .WithCallTo(c => c.CategoryDetails(null))
            .ShouldRenderView("CategoryNotFound");
        }
        public IActionResult Details(int id)
        {
            Category                 cat        = _categoryService.GetSingle(c => c.CategoryId == id);
            IEnumerable <Hamper>     hamperList = _hamperService.Query(p => p.CategoryId == id);
            CategoryDetailsViewModel vm         = new CategoryDetailsViewModel
            {
                Total      = hamperList.Count(),
                Details    = cat.Details,
                Name       = cat.Name,
                Hampers    = hamperList.ToList(),
                CategoryId = cat.CategoryId
            };

            //pass to view
            return(View(vm));
        }
Beispiel #23
0
        public async Task <IActionResult> Details(int id)
        {
            var catEntity = await _categoryService.GetCategoryById(id);

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

            var model = new CategoryDetailsViewModel
            {
                Category = _mapper.Map <CategoryDetailsBindingModel>(catEntity)
            };

            return(View(model));
        }
        public IActionResult CategoryDetails(Guid id)
        {
            var category = _database.Categories.Find(id);

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

            var viewModel = new CategoryDetailsViewModel
            {
                Category = category,
                Tests    = _database.CategoryTests.Where(t => t.CategoryID == id)
            };

            return(View(viewModel));
        }
Beispiel #25
0
        public void ReturnViewWithModelWithCorrectProperties_WhenThereIsAModelWithThePassedId()
        {
            // Arrange
            var categoryServiceMock = new Mock <ICategoryService>();

            var category = new Category()
            {
                Id   = 5,
                Name = "Рокли",
            };

            Product product = new Product()
            {
                Id          = 5,
                Name        = "Рокля на цветя",
                ModelNumber = "123",
                Quantity    = 5,
                Category    = category,
                PictureUrl  = "www.go.home",
                Price       = 55.20m,
                Brand       = new Brand()
                {
                    Id   = 1,
                    Name = "Levis"
                }
            };

            category.Products.Add(product);

            var categoryViewModel = new CategoryDetailsViewModel(category);

            categoryServiceMock.Setup(m => m.GetById(category.Id)).Returns(category);

            CategoryController categoryController = new CategoryController(categoryServiceMock.Object);

            // Act & Assert
            categoryController
            .WithCallTo(c => c.CategoryDetails(category.Id))
            .ShouldRenderDefaultView()
            .WithModel <CategoryDetailsViewModel>(viewModel =>
            {
                Assert.AreEqual(category.Id, viewModel.Id);
                Assert.AreEqual(category.Name, viewModel.Name);
                Assert.AreEqual(category.Products.Count, viewModel.Products.Count());
            });
        }
        public IActionResult CategoryDetailsAsync(string categoryId, string categoryTitle, string subjectId)
        {
            var lessons = this.subjectService.GetLessons()
                          .Where(lesson => lesson.CategoryId == categoryId)
                          .ToList();

            var lessonsDto = this.mapper.Map <List <LessonsViewModel> >(lessons);

            // If User is Student adding score in view
            if (this.User.IsInRole("Student"))
            {
                foreach (var lesson in lessonsDto)
                {
                    // Gets student ID
                    var studentId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

                    var studentScores = this.scoreService
                                        .GetScoreStudents()
                                        .Where(ss => ss.StudentId == studentId)
                                        .ToList();

                    var score = studentScores
                                .FirstOrDefault(s => s.Score.LessonId == lesson.LessonId);

                    // Set Score if there is any
                    if (score != null)
                    {
                        lesson.Score = score.Score.ScorePoints;
                    }
                    else
                    {
                        lesson.Score = 0;
                    }
                }
            }

            // Create model for the view
            var model = new CategoryDetailsViewModel
            {
                CategoryTitle = categoryTitle,
                Lessons       = lessonsDto,
                SubjectId     = subjectId,
            };

            return(this.View(model));
        }
        // GET: Categories
        public ActionResult CategoryDetails(int?id)
        {
            Category category = this.categoryService.GetById(id);

            if (category == null)
            {
                ViewBag.Message = $" Категория с ID {id} не е намеренa.";

                return(View("CategoryNotFound"));
            }
            else
            {
                CategoryDetailsViewModel categoryDetails = new CategoryDetailsViewModel(category);

                return(View(categoryDetails));
            }
        }
Beispiel #28
0
        public IActionResult Edit(int id)
        {
            var category = this.categoryService.GetById(id);

            if (category.Name == null)
            {
                return(this.BadRequest());
            }

            var viewModel = new CategoryDetailsViewModel()
            {
                Name        = category.Name,
                Description = category.Description
            };

            return(this.View(viewModel));
        }
Beispiel #29
0
        public async Task CheckIfGetCategoryViewModelByIdAsyncWorksCorrectly()
        {
            this.SeedDatabase();

            var expectedModel = new CategoryDetailsViewModel
            {
                Id = this.firstCategory.Id,
                Name = this.firstCategory.Name,
                Description = this.firstCategory.Description,
            };

            var viewModel = await this.categoriesService.GetViewModelByIdAsync<CategoryDetailsViewModel>(this.firstCategory.Id);

            var expectedObj = JsonConvert.SerializeObject(expectedModel);
            var actualResultObj = JsonConvert.SerializeObject(viewModel);

            Assert.Equal(expectedObj, actualResultObj);
        }
Beispiel #30
0
        public static CategoryDetailsViewModel ToCategoryDetailsViewModel(this CategoryEntity entity)
        {
            var viewModel = new CategoryDetailsViewModel()
            {
                CreationDate = entity.CreationDate,
                CategoryName = entity.CategoryName,
                IsBlocked    = entity.IsBlocked,
                Id           = entity.Id,
                IsConfirmed  = entity.IsConfirmed,
                SectionRefId = entity.SectionRefId,
            };

            //foreach (var category in entity.Categories)
            //{
            //    viewModel.Categories.Add(category.CategoryName);
            //}
            return(viewModel);
        }