Exemplo n.º 1
0
        public ActionResult Save(NewSupplierViewModel model)
        {
            var address = model.Address;

            address.Cep = address.Cep.Replace("-", "").Replace(".", "");

            var supplier = model.Supplier;

            supplier.CNPJ = supplier.CNPJ.Replace(".", "").Replace("/", "").Replace(".", "").Replace("-", "");


            if (model.Address.Id == 0)
            {
                _context.Addresses.Add(address);
            }
            else
            {
                var addressToModify = _context
                                      .Addresses
                                      .SingleOrDefault(a => a.Id == address.Id);

                if (addressToModify == null)
                {
                    return(HttpNotFound());
                }

                addressToModify.Cep        = address.Cep;
                addressToModify.IdCity     = address.IdCity;
                addressToModify.IdState    = address.IdState;
                addressToModify.Complement = address.Complement;
                addressToModify.Number     = address.Number;
                addressToModify.Street     = address.Street;
            }
            _context.SaveChanges();

            if (supplier.Id == 0)
            {
                supplier.IdAddress = address.Id;
                _context.Suppliers.Add(supplier);
            }
            else
            {
                var supplierToModify = _context
                                       .Suppliers
                                       .SingleOrDefault(s => s.Id == supplier.Id);

                supplierToModify.IdAddress = address.Id;
                supplierToModify.Name      = supplier.Name;
                supplierToModify.CNPJ      = supplier.Name;
            }
            _context.SaveChanges();

            return(RedirectToAction("SupplierList", "Supplier"));
        }
Exemplo n.º 2
0
        public ViewResult SupplierList()
        {
            var viewModel = new NewSupplierViewModel()
            {
                Suppliers = _context.Suppliers.ToList(),
                States    = _context.States.ToList(),
                Addresses = _context.Addresses.ToList(),
                Cities    = new List <City>()
            };

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public NewSupplierView()
        {
            InitializeComponent();
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            var viewModel = new NewSupplierViewModel();

            this.DataContext = viewModel;
            if (viewModel.CloseAction == null)
            {
                viewModel.CloseAction = new Action(this.Close);
            }
        }
Exemplo n.º 4
0
        public void Should_Success_Instatiate_New_Supplier()
        {
            var supplier = new NewSupplierViewModel()
            {
                _id    = 1,
                code   = "Code",
                name   = "Name",
                import = false
            };


            Assert.True(supplier != null);
        }
Exemplo n.º 5
0
        public void Should_Succes_Instantiate_NewSupplierViewModel()
        {
            int    id     = 1;
            string code   = "code test";
            string nama   = "name test";
            bool   import = true;


            NewSupplierViewModel nspm = new NewSupplierViewModel();

            nspm._id    = id;
            nspm.code   = code;
            nspm.name   = nama;
            nspm.import = import;

            Assert.Equal(id, nspm._id);
            Assert.Equal(nama, nspm.name);
            Assert.Equal(code, nspm.code);
            Assert.Equal(import, nspm.import);
        }
Exemplo n.º 6
0
 public NewSupplierPage()
 {
     InitializeComponent();
     BindingContext = new NewSupplierViewModel();
 }