Exemplo n.º 1
0
 public ActionResult Delete(string id = "", string id1 = "")
 {
     Logger.Debug("Inside Territory Controller- Delete");
     try
     {
         if (Session["OrganizationGUID"] != null)
         {
             int countCustomerStop = _IMarketRepository.GetMarketByTerritoryGUID(new Guid(id1), 1).Count();
             int countgobalUser    = _IGlobalUserRepository.GetGlobalUserByRegionandTerritory(new Guid(id), new Guid(id1)).Count();
             if (countCustomerStop == 0 && countgobalUser == 0)
             {
                 TerritoryModel territory = new TerritoryModel();
                 territory.RegionGUID    = id;
                 territory.TerritoryGUID = id1;
                 _IMarketRepository.DeleteMarketByTerritoryGUID(new Guid(territory.TerritoryGUID));
                 _ITerritoryRepository.DeleteTerritory(new Guid(territory.TerritoryGUID));
                 //_ITerritoryRepository.Save();
                 return(RedirectToAction("Index", "MyCompany", new { id = "Markets", regionguid = id }));
             }
             else
             {
                 if (countCustomerStop > 0 && countgobalUser > 0)
                 {
                     TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Territory is associate with Users and Store.');</script>";
                 }
                 else if (countCustomerStop > 0)
                 {
                     TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Territory is associate with Store.');</script>";
                 }
                 else if (countgobalUser > 0)
                 {
                     TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Territory is associate with Users.');</script>";
                 }
                 return(RedirectToAction("Index", "MyCompany", new { id = "Markets", territoryguid = id1 }));
             }
         }
         else
         {
             return(RedirectToAction("SessionTimeOut", "User"));
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
         return(RedirectToAction("../MyCompany/Index/Markets"));
     }
 }