public ActionResult Create(MemberCard member, int?id)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", member));
            }

            // Create a memberCard

            var memberCard = new MemberCard()
            {
                CustomerID     = id.Value,
                MemberCardCode = MemberCard.GetMemberCardCode(),
                Type           = MembershipType.Basic,
                CreationDate   = MemberCard.GetCreationDate(),
                Credits        = 0,
                NewsLetter     = member.NewsLetter
            };

            // Send memberCard to DB
            _context.MemberCards.Add(memberCard);
            _context.SaveChanges();

            // where i will send the user
            return(RedirectToAction("Index", "Customers"));
        }
예제 #2
0
        public IHttpActionResult Create(int?id)
        {
            if (_context.MemberCards
                .Any(m => m.CustomerID == id))
            {
                return(BadRequest("The membercard already exists"));
            }

            var memberCard = new MemberCard
            {
                CustomerID     = id.Value,
                MemberCardCode = MemberCard.GetMemberCardCode(),
                Type           = MembershipType.Basic,
                CreationDate   = MemberCard.GetCreationDate(),
                Credits        = 0
            };

            _context.MemberCards.Add(memberCard);
            _context.SaveChanges();

            return(Ok());
        }