private Distributor Update(Distributor d, string name, string description, string telephone, string email,
                                   string contact, PriceList pl, string code, Country c, decimal discount,
                                   Lookup paymentTerm, Lookup saleCondition, Lookup type, string alternativeEmail)
        {
            bool updateDiscount = false;

            d.Name        = name;
            d.Description = description;
            d.Telephone   = telephone;
            d.Email       = email;
            if (d.PriceList == null || pl == null || d.PriceList.ID != pl.ID)
            {
                updateDiscount = true;
            }
            if (pl != null)
            {
                d.PriceList = ControllerManager.PriceList.GetById(pl.ID); // Because we use it in the AssignDiscount method
            }
            else
            {
                d.PriceList = pl;
            }

            d.Code              = code;
            d.Country           = c;
            d.Contact           = contact;
            d.DistributorStatus = DistributorStatus.Active;
            d.PaymentTerm       = paymentTerm;
            d.SaleConditions    = saleCondition;

            if (d.Discount != discount)
            {
                updateDiscount = true;
            }

            d.Discount         = discount;
            d.Type             = type;
            d.AlternativeEmail = alternativeEmail;

            repository.Save(d);
            repository.CommitChange();

            if (updateDiscount)
            {
                ControllerManager.PriceList.CalculateDiscounts(d.PriceList);
            }
            CacheManager.ExpireAll(typeof(Distributor));
            return(d);
        }
Beispiel #2
0
        public void CanEditContact()
        {
            MockRepository         mock        = new MockRepository();
            IDistributorRepository mockedRepos = mock.CreateMock <IDistributorRepository>();

            Distributor expDistributor = new Distributor();

            expDistributor.Address  = "pepe street.";
            expDistributor.Code     = "1234";
            expDistributor.Discount = 15;
            expDistributor.Email    = "*****@*****.**";
            expDistributor.Name     = "testing Distributor";
            Contact expC = new Contact("Gali", "Emi", "*****@*****.**");

            expC.Distributor = expDistributor;
            expDistributor.Contacts.Add(expC);

            Contact contact = new Contact("Emi Cambiado", "Gali cambiado", "*****@*****.**");

            contact.Distributor = expDistributor;

            Expect.Call(mockedRepos.GetById(5)).Return(expDistributor).Repeat.AtLeastOnce();
            Expect.Call(mockedRepos.SaveContact(expC)).Return(contact);
            mockedRepos.CommitChange();
            LastCall.On(mockedRepos);
            mock.ReplayAll();
            DistributorController dc = new DistributorController(mockedRepos);

            Contact c = dc.EditContact(5, 0, "Emi Cambiado", "Gali cambiado", "*****@*****.**");

            Assert.AreNotEqual("Emi", c.Name);
            Assert.AreEqual("Gali cambiado", c.LastName);
            Assert.AreNotEqual("*****@*****.**", c.Email);
        }