Beispiel #1
0
 public ActionResult Delete(int id, IFormCollection collection)
 {
     try
     {
         deptRepository.Delete(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(deptRepository.Delete(id)));
     }
 }
        public ActionResult Delete(int id)
        {
            var isDeleted = _deptRepository.Delete(id);

            if (!isDeleted)
            {
                ViewBag.Message = "Could not delete department. Employees are assined to it.";
                List <Department> departments = _deptRepository.Get();
                return(View("Index", departments));
            }
            return(RedirectToAction("Index"));
        }
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         int res = deptRepository.Delete(id);
         if (res == 0)//If no rows were affected
         {
             throw new Exception("Удаления не произведено!");
         }
         return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         string msg = ex.Message.Replace('\n', ' ').Replace('\r', ' ');
         return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)
         {
             ReasonPhrase = msg
         });
     }
 }
Beispiel #4
0
 public void Delete()
 {
     mDeptRepository.Delete(this);
 }