public void Execute(int id)
        {
            var vendor = _context.Vendors.SingleOrDefault(v => v.VendorId == id);

            if (vendor == null)
            {
                throw new NotFoundException <int>("vendor", id);
            }
            if (vendor.IsSystemReservedVendor())
            {
                throw new Exception("This Vendor is required for proper system function and may not be deleted");
            }

            foreach (var application in vendor.Applications.ToList())
            {
                _deleteApplicationCommand.Execute(application.ApplicationId);
            }

            foreach (var user in vendor.Users.ToList())
            {
                _context.Users.Remove(user);
            }

            _context.Vendors.Remove(vendor);
            _context.SaveChanges();
        }
        public ActionResult Delete(DeleteApplicationModel model)
        {
            var application = _getApplicationByIdQuery.Execute(model.ApplicationId);

            if (application.IsSystemReservedApplication())
            {
                return(JsonError("This Application is required for proper system function and may not be deleted"));
            }

            _deleteApplicationCommand.Execute(model.ApplicationId);
            return(JsonSuccess("Application deleted successfully"));
        }
 public ActionResult Delete(DeleteApplicationModel model)
 {
     try
     {
         _deleteApplicationCommand.Execute(model.ApplicationId);
         return(JsonSuccess("Application deleted successfully"));
     }
     catch (Exception ex)
     {
         return(JsonError(ex.Message));
     }
 }
        public void Execute(int id)
        {
            var vendor = _context.Vendors.SingleOrDefault(v => v.VendorId == id);

            if (vendor == null)
            {
                return;
            }

            foreach (var user in vendor.Users.ToList())
            {
                _context.Users.Remove(user);
            }

            foreach (var application in vendor.Applications.ToList())
            {
                _deleteApplicationCommand.Execute(application.ApplicationId);
            }

            _context.Vendors.Remove(vendor);
            _context.SaveChanges();
        }
 public Task <IResult> Handle(IDeleteApplicationCommand deleteApplicationCommand, int id)
 {
     deleteApplicationCommand.Execute(id);
     return(Task.FromResult(AdminApiResponse.Deleted("Application")));
 }