public async Task Will_Insert_Template_To_Collection_Preserving_Tenant_Context()
        {
            _tenantIdProvider.Setup(x => x.TenantId).Returns(Tenant1Id).Verifiable();

            var template = new Template()
            {
                TemplateId = Guid.NewGuid()
            };
            await _repository.AddTemplate(template, CancellationToken.None);

            var filter = Builders <Template> .Filter.Eq(x => x.TemplateId, template.TemplateId);

            (await _collection.Find(filter).FirstAsync()).Should()
            .BeEquivalentTo(new Template()
            {
                TemplateId = template.TemplateId, TenantId = Tenant1Id
            });
        }
        public ActionResult Create(int jobListingId, [Bind("TemplateId,Education,WorkExperience,Skills,AllowCVUpload,OtherNotes")] JobListingTemplateViewModel jobListingTemplateViewModel)
        {
            int userIdCurrentlyLoggedIn = Int32.Parse(User.Claims.FirstOrDefault(uc => uc.Type == ClaimTypes.NameIdentifier).Value);

            if (!_jobListingsRepository.isAllowedToSetTemplate(userIdCurrentlyLoggedIn, jobListingId))
            {
                return(NotFound());
            }
            Template template = new Template
            {
                UserId          = userIdCurrentlyLoggedIn,
                JobListingId    = jobListingId,
                Education       = Convert.ToByte(jobListingTemplateViewModel.Education),
                WorkExperience  = Convert.ToByte(jobListingTemplateViewModel.WorkExperience),
                Skills          = Convert.ToByte(jobListingTemplateViewModel.Skills),
                OtherNotes      = Convert.ToByte(jobListingTemplateViewModel.OtherNotes),
                TemplateAddedAt = DateTime.Now
            };

            _templatesRepository.AddTemplate(template);
            ViewBag.SelectedNav = "Dashboard";
            return(RedirectToAction("Index", "JobListings"));
        }
        public ActionResult Create(
            [Bind(
                 "Title,Type,Position,Region,Location,Description,IsActive,CategoryId,CompanyId,WorkExperience,Education,Skills,OtherNotes")]
            AddJobListingWithTemplateViewModel addJobListingWithTemplateViewModel)
        {
            int userIdCurrentlyLoggedIn = Int32.Parse(User.Claims.FirstOrDefault(uc => uc.Type == ClaimTypes.NameIdentifier).Value);

            if (ModelState.IsValid)
            {
                JobListing jobListing = new JobListing
                {
                    Title             = addJobListingWithTemplateViewModel.Title,
                    Type              = addJobListingWithTemplateViewModel.Type,
                    Position          = addJobListingWithTemplateViewModel.Position,
                    Region            = addJobListingWithTemplateViewModel.Region,
                    Location          = addJobListingWithTemplateViewModel.Location,
                    Description       = addJobListingWithTemplateViewModel.Description,
                    IsActive          = Convert.ToByte(addJobListingWithTemplateViewModel.IsActive),
                    JobListingAddedAt = DateTime.Now,
                    UserId            = userIdCurrentlyLoggedIn,
                    CompanyId         = addJobListingWithTemplateViewModel.CompanyId,
                    CategoryId        = addJobListingWithTemplateViewModel.CategoryId
                };

                int jobListingId = _jobListingsRepository.AddJobListing(jobListing, userIdCurrentlyLoggedIn);

                if (jobListingId != 0)
                {
                    Template template = new Template
                    {
                        WorkExperience  = Convert.ToByte(addJobListingWithTemplateViewModel.WorkExperience),
                        Skills          = Convert.ToByte(addJobListingWithTemplateViewModel.Skills),
                        Education       = Convert.ToByte(addJobListingWithTemplateViewModel.Education),
                        OtherNotes      = Convert.ToByte(addJobListingWithTemplateViewModel.OtherNotes),
                        JobListingId    = jobListingId,
                        UserId          = userIdCurrentlyLoggedIn,
                        TemplateAddedAt = DateTime.Now
                    };
                    _templatesRepository.AddTemplate(template);
                }

                ViewBag.SelectedNav = "Dashboard";
                return(RedirectToAction(nameof(Index)));
            }
            List <Company>  companiesAssignedToUserLoggedIn = _companiesRepository.GetCompaniesAssignedToUser(userIdCurrentlyLoggedIn);
            List <Category> categories = _categoriesRepository.GetCategories();

            List <string> regions = new List <string> {
                "Africa", "Asia", "The Caribbean", "Central America", "Europe", "Oceania", "North America", "South America"
            };
            List <string> types = new List <string> {
                "Full Time", "Part Time", "Remote", "Voluntary or carity acts"
            };

            ViewData["Companies"]  = new SelectList(companiesAssignedToUserLoggedIn, "CompanyId", "Name");
            ViewData["Categories"] = new SelectList(categories, "CategoryId", "Name");
            ViewData["Regions"]    = new SelectList(regions, regions);
            ViewData["Types"]      = new SelectList(types, types);
            ViewBag.SelectedNav    = "Dashboard";

            return(View(addJobListingWithTemplateViewModel));
        }