Exemple #1
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Моля влезте в системата отново или си изчистете кеш данните на браузъра."));
            }

            var entity = await _companyService.GetByIdAsync <CompanyViewModel>(id);

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

            var poster = this._userManager.GetUserId(User);

            if (poster != entity.PosterId)
            {
                return(Redirect($"/Identity/Account/AccessDenied"));
            }

            RequirePassword = await _userManager.HasPasswordAsync(user);

            if (RequirePassword)
            {
                if (!await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    ModelState.AddModelError(string.Empty, "Password not correct.");
                    return(Page());
                }
            }

            await _jobsService.DeleteAllByCompany(id);

            var result = await _companyService.Delete(id);

            if (result.Success)
            {
                Redirect($"/Identity/Companies/Posts/");
            }

            return(Page());
        }