Ejemplo n.º 1
0
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new FormCustomerViewModel()
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("Form", viewModel));
            }

            if (customer.Id == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _context.Customers.Single(c => c.Id == customer.Id);
                customerInDb.Name                     = customer.Name;
                customerInDb.BirthDate                = customer.BirthDate;
                customerInDb.MembershipTypeId         = customer.MembershipTypeId;
                customerInDb.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Customer"));
        }
Ejemplo n.º 2
0
 public ActionResult Save(CustomerDto customerDto)
 {
     if (customerDto == null)
     {
         return(HttpNotFound());
     }
     if (!ModelState.IsValid)
     {
         var ViewModel = new FormCustomerViewModel
         {
             CustomerDto     = new CustomerDto(),
             MembershipTypes = _context.MembershipTypes.ToList()
         };
         return(View("CustomerForm", ViewModel));
     }
     if (customerDto.Id == 0)
     {
         _context.Customers.Add(Mapper.Map <CustomerDto, Customer>(customerDto));
     }
     else
     {
         var CustomerInDB = _context.Customers.Single(c => c.Id == customerDto.Id);
         Mapper.Map(customerDto, CustomerInDB);
     }
     _context.SaveChanges();
     return(RedirectToAction("Index", "Customers"));
 }
Ejemplo n.º 3
0
        public ActionResult Save(Customer customer)
        {
            //bool result = ModelState.Remove("customer.Id");
            if (!ModelState.IsValid)
            {
                var custVM = new FormCustomerViewModel()
                {
                    Memberships = _dbcontext.Memberships.ToList(),
                    Customer    = customer,
                };
                return(View("FormCustomer", custVM));
            }

            if (customer.Id == 0)
            {
                _dbcontext.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _dbcontext.Customers.Single(c => c.Id == customer.Id);
                customerInDb.Name             = customer.Name;
                customerInDb.MembershipTypeId = customer.MembershipTypeId;
                customerInDb.IsSubscribe      = customer.IsSubscribe;
            }

            _dbcontext.SaveChanges();
            return(RedirectToAction("Index", "Customer"));
        }
Ejemplo n.º 4
0
        public ActionResult New()
        {
            var viewModel = new FormCustomerViewModel()
            {
                Customer        = new Customer(),
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            return(View("Form", viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult New()
        {
            var new_custVM = new FormCustomerViewModel()
            {
                Memberships = _dbcontext.Memberships.ToList(),
                Customer    = new Customer(),
            };

            return(View("FormCustomer", new_custVM));
        }
Ejemplo n.º 6
0
        public ActionResult NewCustomer()
        {
            var membershipTypes = _context.membershipTypes.ToList();
            var viewModel       = new FormCustomerViewModel()
            {
                MembershipTypes = membershipTypes,
            };

            return(View("CustomerForm", viewModel));
        }
Ejemplo n.º 7
0
        public ActionResult EditCustomer(int id)
        {
            ViewBag.Heading = "Edit Customer";
            var ViewModel       = new FormCustomerViewModel();
            var MemberShipTypes = _context.MembershipTypes.ToList();
            var Customer        = _context.Customers.FirstOrDefault(c => c.Id == id);

            ViewModel.CustomerDto     = Mapper.Map <Customer, CustomerDto>(Customer);
            ViewModel.MembershipTypes = MemberShipTypes;
            return(View("CustomerForm", ViewModel));
        }
Ejemplo n.º 8
0
        public ActionResult New()
        {
            var membershipTypes       = _context.MembershipTypes.ToList();
            var formCustomerViewModel = new FormCustomerViewModel
            {
                Customer        = new Customer(),
                MembershipTypes = membershipTypes
            };

            return(View("CustomerForm", formCustomerViewModel));
        }
Ejemplo n.º 9
0
        public ActionResult newCustomer()
        {
            ViewBag.Heading = "New Customer";
            var membershipTypes = _context.MembershipTypes.ToList();
            var viewModel       = new FormCustomerViewModel()
            {
                CustomerDto     = new CustomerDto(),
                MembershipTypes = membershipTypes
            };

            return(View("CustomerForm", viewModel));
        }
Ejemplo n.º 10
0
        public ActionResult CreateCustomer(Customers customer, string create)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new FormCustomerViewModel
                {
                    MembershipTypes = _context.membershipTypes.ToList(),
                    Customer        = customer
                };
                return(View("CustomerForm", viewModel));
            }
            switch (create)
            {
            case "save":
                _context.Customers.Add(customer);
                _context.SaveChanges();

                break;

            case "edit":
                var selectedCustomer = _context.Customers.Single(c => c.id == customer.id);

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

                selectedCustomer.name                     = customer.name;
                selectedCustomer.birthDate                = customer.birthDate;
                selectedCustomer.membershipType           = customer.membershipType;
                selectedCustomer.membershipTypeId         = customer.membershipTypeId;
                selectedCustomer.isSubscribedToNewsLetter = customer.isSubscribedToNewsLetter;

                _context.SaveChanges();


                break;

            default:
                return(HttpNotFound());

            case "erase":
                var SelectedCustomer = _context.Customers.SingleOrDefault(c => c.id == customer.id);
                _context.Customers.Remove(SelectedCustomer);
                _context.SaveChanges();
                break;
            }


            return(RedirectToAction("Customers"));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int id)
        {
            var customer = _context.Customers.SingleOrDefault(c => c.Id == id);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new FormCustomerViewModel()
            {
                Customer        = customer,
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            return(View("Form", viewModel));
        }
Ejemplo n.º 12
0
        public ActionResult Customer(int id)
        {
            var customer = _context.Customers.SingleOrDefault(c => c.id == id);

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

            var viewModel = new FormCustomerViewModel
            {
                Customer        = customer,
                MembershipTypes = _context.membershipTypes.ToList()
            };

            return(View("Customer", customer));
        }
Ejemplo n.º 13
0
        public ActionResult Edit(int id)
        {
            var customer = _context.Customers.SingleOrDefault(m => m.Id == id);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            var membershipTypes       = _context.MembershipTypes.ToList();
            var formCustomerViewModel = new FormCustomerViewModel
            {
                MembershipTypes = membershipTypes,
                Customer        = customer
            };

            return(View("CustomerForm", formCustomerViewModel));
        }