public IHttpActionResult PostCataloguesUser(UserCatalogViewModel userCatalogVm)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                UserCatalogRepository relUserCatalogRepo = new UserCatalogRepository(new MyRoomDbContext());
                RelUserCatalogue relUserCatalog  = UserCatalogMapper.CreateModel(userCatalogVm);
                relUserCatalogRepo.InsertUserCatalog(userCatalogVm, true);


                UserModuleRepository relUserModuleRepo = new UserModuleRepository(relUserCatalogRepo.Context);
                List<RelUserModule> userModules = UserModuleMapper.CreateModel(userCatalogVm);
                relUserModuleRepo.InsertUserModule(userModules, userCatalogVm.UserId, true);

                UserCategoryRepository relUserCategoryRepo = new UserCategoryRepository(relUserCatalogRepo.Context);
                List<RelUserCategory> userCategories = UserCategoryMapper.CreateModel(userCatalogVm);
                relUserCategoryRepo.InsertUserCategory(userCategories, userCatalogVm.UserId, true);

                return Ok("Permission Assigned");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
 public UserCategoryController(IConfiguration configuration)
 {
     repo = new UserCategoryRepository(configuration);
 }
Beispiel #3
0
        private List<CategoryCompositeViewModel> CreateSubCategories(CategoryCompositeViewModel p, bool withproducts, bool activecategory, int hotelId, string userId)
        {
            CategoryRepository categoryRepo = new CategoryRepository(this.Context);

            List<Category> categories = categoryRepo.GetByParentId(p.CategoryId);
            List<CategoryCompositeViewModel> categoriesVm = new List<CategoryCompositeViewModel>();
            categoriesVm.Add(p);
            foreach (Category c in categories)
            {
                CategoryCompositeViewModel categoryCompositeViewModel = Helper.ConvertCategoryToViewModel(c);
                if (p.Children == null)
                    p.Children = new List<ICatalogChildren>();

                if (activecategory)
                {
                    if (withproducts)
                    {
                        //   categoryCompositeViewModel.IsChecked = c.ActiveHotelCategory.Contains(new ActiveHotelCategory() { IdCategory = c.CategoryId, IdHotel = hotelId, Active = true, Category = c});
                        c.ActiveHotelCategory.ForEach(delegate(ActiveHotelCategory hotelCategory) 
                        {
                            if (hotelCategory.IdHotel == hotelId && hotelCategory.Category.IdParentCategory == p.CategoryId && hotelCategory.Active)
                            {
                                categoryCompositeViewModel.IsChecked = true;
                            }
                        });
                    }
                    else
                    {
                        UserCategoryRepository userCategoryRepo = new UserCategoryRepository(this.Context);
                        c.RelUserCategory = userCategoryRepo.GetByUserAndCategory(userId, c.CategoryId); 
                        c.RelUserCategory.ForEach(delegate(RelUserCategory userCategory)
                        {
                            if (userCategory.IdCategory == c.CategoryId && userCategory.IdUser == userId) //userCategory.IdUser == 
                            {
                                categoryCompositeViewModel.IsChecked = true;
                            }
                        });

                    }
                    categoryCompositeViewModel.ActiveCheckbox = true;
                }

                if (withproducts)
                {
                    categoryCompositeViewModel.Children = new List<ICatalogChildren>();
                    foreach (CategoryProduct cp in c.CategoryProducts)
                    {
                        Product product = productRepo.GetById(cp.IdProduct);
                            ProductCompositeViewModel productViewModel = new ProductCompositeViewModel()
                            {
                                ProductId = product.Id,
                                text = product.Name,
                                ActiveCheckbox = true
                            };

                            categoryCompositeViewModel.Children.Add(productViewModel);

                            product.ActiveHotelProduct.ForEach(delegate(ActiveHotelProduct productHotelAct)
                            {
                                if (productHotelAct.IdHotel == hotelId && cp.IdProduct == productHotelAct.IdProduct )
                                {
                                    productViewModel.IsChecked = true;
                                }
                            });

                  
                    }
                }

                p.Children.Add(categoryCompositeViewModel);
                if (categories != null)
                    CreateSubCategories(categoryCompositeViewModel, withproducts, activecategory, hotelId, userId);

            }

            return categoriesVm;
        }