예제 #1
0
        private void DeleteVare()
        {
            CurrentVarer.Name        = Name;
            CurrentVarer.Description = Description;
            CurrentVarer.Price       = Price;
            CurrentVarer.Stock       = Stock;
            //CurrentVarer.Id = Id;

            _db.products.Remove(CurrentVarer);

            try
            {
                _db.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }

            Remove(CurrentVarer);
            MediatorImpl.NotifyColleagues("Del", true);
        }
예제 #2
0
        private void AddVare()
        {
            Product product = new Product();

            CurrentAfdelingIndex = 0;
            ProduktIndex newFunc = new ProduktIndex();

            product.Name        = Name;
            product.Price       = Price;
            product.Stock       = Stock;
            product.Description = "Description missing";
            product.Department  = Department;
            Add(product);
            _db.products.Add(product);
            // Show what the error is if SaveChanges(); fail.
            try
            {
                _db.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            //Add(newFunc);
            //CurrentVarer = newFunc;
            CurrentVarer = product;
            MediatorImpl.NotifyColleagues("Add", true);
        }