Ejemplo n.º 1
0
 public ActionResult DeleteCompany(DeleteCompanyViewModel model)
 {
     if (ModelState.IsValid)
     {
         ViewBag.answer = "Вы действительно хотите удалить компанию с названием \"" + model.Name + "\"";
     }
     else
     {
         ViewBag.answer = "Произошла ошибка. Закройте это окно и обновите страницу";
     }
     return(PartialView("_DeleteCompanyPartial", model));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteCompany(DeleteCompanyViewModel model)
        {
            if (ModelState.IsValid)
            {
                await service.DeleteCompany(model);

                return(RedirectToAction("DisplayAllCompanies"));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteCompany(DeleteCompanyViewModel model)
        {
            var companyToDelete = await FindCompany(model.Id);

            if (companyToDelete == null)
            {
                throw new NullReferenceException($"No company with {model.Id} exists.");
            }
            else
            {
                companyToDelete.IsDeleted = true;
            }
            dbContext.Companies.Update(companyToDelete);
            await dbContext.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> DeleteCompany(int id)
        {
            var foundCompany = await service.FindCompany(id);

            if (foundCompany == null)
            {
                return(NotFound());
            }
            else if (foundCompany.IsDeleted)
            {
                return(RedirectToAction("DisplayAllCompanies"));
            }
            var companyToDelete = new DeleteCompanyViewModel();

            companyToDelete.Id        = foundCompany.Id;
            companyToDelete.IsDeleted = foundCompany.IsDeleted;
            return(View(companyToDelete));
        }