예제 #1
0
        public async Task <IActionResult> Edit(int?id)
        {
            var proj = _context.Projects.Where(x => x.Id == id).Include(x => x.Company);

            var checkProjectUserIdModel = new CheckProjectUserIdModel();

            foreach (var item in proj)
            {
                checkProjectUserIdModel.EntreprenuerId = item.Company.EntrepreneurId;
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, checkProjectUserIdModel, "EditProjectPolicy");

            if (authResult.Succeeded)
            {
                if (id == null)
                {
                    return(NotFound());
                }

                var project = _context.Projects.Find(id);

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

                ViewData["CompanyId"]         = new SelectList(_context.Companies, "Id", "Email", project.CompanyId);
                ViewData["ProjectCategoryId"] = new SelectList(_context.Set <ProjectCategory>(), "Id", "Id", project.ProjectCategoryId);
                return(View(project));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> CreateReward(int?id)
        {
            var project = _context.Projects.Where(x => x.Id == id).Include(x => x.Company).ThenInclude(x => x.Entrepreneur);

            var checkProjectUserIdModel = new CheckProjectUserIdModel();

            foreach (var item in project)
            {
                checkProjectUserIdModel.EntreprenuerId = item.Company.Entrepreneur.Id;
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, checkProjectUserIdModel, "EditProjectPolicy");

            if (authResult.Succeeded)
            {
                ViewData["ProjectId"] = id;
                return(View());
            }

            return(RedirectToAction("Login", "Account"));
        }