Ejemplo n.º 1
0
        public IActionResult Edit(CustomersEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var membership = membershipData.GetMembershipById(model.Customer.Id);
                model.Customer.Membership = membership;

                if (model.Customer.Id == 0)
                {
                    model.Customer          = customerData.Create(model.Customer);
                    TempData["TempMessage"] = "New customer is created!";
                }
                else
                {
                    model.Customer          = customerData.Update(model.Customer);
                    TempData["TempMessage"] = "Data for customer is updated!";
                }

                customerData.Commit();
                return(RedirectToAction("List"));
            }
            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            model.Memberships = new SelectList(memberships, "Id", "Display");
            model.Gender      = htmlHelper.GetEnumSelectList <Gender>();
            model.City        = htmlHelper.GetEnumSelectList <City>();
            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var membership = membershipData.GetMembershipById(Customer.MembershipId);
                Customer.Membership = membership;

                if (Customer.Id == 0)
                {
                    Customer = customerData.Create(Customer);
                    TempData["TempMessage"] = "New customer is created!";
                }
                else
                {
                    Customer = customerData.Update(Customer);
                    TempData["TempMessage"] = "Data for customer is updated!";
                }

                customerData.Commit();
                return(RedirectToPage("./List"));
            }

            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            Memberships = new SelectList(memberships, "Id", "Display");
            Gender      = htmlHelper.GetEnumSelectList <Gender>();
            City        = htmlHelper.GetEnumSelectList <City>();
            return(Page());
        }
Ejemplo n.º 3
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var membership = membershipData.GetMebershipById(Customer.MembershipId);
                Customer.Membership = membership;

                if (Customer.Id == 0)
                {
                    Customer            = customerData.Create(Customer);
                    TempData["Message"] = "The Object is created!";
                }
                else
                {
                    Customer            = customerData.Update(Customer);
                    TempData["Message"] = "The Object is updated!";
                }

                customerData.Commit();
                return(RedirectToPage("./List"));
            }

            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.GetMembershipType() });

            Memberships = new SelectList(memberships, "Id", "Display");
            return(Page());
        }
Ejemplo n.º 4
0
        public IActionResult Create(CustomerDto customer)
        {
            var dbCustomer = new Customer();

            dbCustomer.FirstName    = customer.FirstName;
            dbCustomer.LastName     = customer.LastName;
            dbCustomer.MembershipId = customer.MembershipId;
            customerData.Create(dbCustomer);
            customerData.Commit();
            return(CreatedAtRoute("FetchCustomer", new { id = dbCustomer.Id }, dbCustomer));
        }
        public ActionResult Create(Customer customer)
        {
            try
            {
                // TODO: Add insert logic here

                db.Create(customer);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }