Exemple #1
0
        private void DeleteVendorCommand(object model)
        {
            var vendor = model as Vendor;

            if (OnMessageBoxEvent("Do you want to delete this entry?"))
            {
                _repositoryManager.DeleteVendor(vendor);
                _vendors.Remove(vendor);
                VendorList.Remove(VendorList.Single(x => x.VendorId == vendor.VendorId));
            }
        }
        private void DeleteButtonClick(object sender)
        {
            var vendor = sender as Vendor;

            using (var db = new AppDbContext())
            {
                var vendorFromDB = db.Vendors.SingleOrDefault(x => x.ID == vendor.ID);
                db.Remove(vendorFromDB);
                var user = db.Users.SingleOrDefault(x => x.ID == _user.ID);
                user.VendorsCount--;
                var reviewList = db.Reviews.ToList();

                foreach (var review in reviewList.Where(x => x.VendorID == vendor.ID))
                {
                    db.Remove(review);
                }
                db.SaveChanges();
            }

            var itemToRemove = VendorList.Single(d => d.ID == vendor.ID);

            VendorList.Remove(itemToRemove);
        }