示例#1
0
        // Donate
        public async Task <IActionResult> Donate()
        {
            var user = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

            var user_id = user.Value;

            var cart = _context.Cart.Where(c => c.UserId == user_id);

            if (String.IsNullOrEmpty(user_id))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in cart)
                {
                    Donation donation = new Donation();
                    donation.Amount    = item.Amount;
                    donation.SpeciesId = item.SpeciesId;
                    donation.UserId    = item.UserId;
                    _context.Add(donation);
                }

                await _context.SaveChangesAsync();
            }

            //await RemoveFromCartByUser(user_id);
            // var donate = _context.Donation.Where(c => c.UserId == user_id);
            return(RedirectToAction("Index", "type=donation"));
            // View(await donate.ToListAsync());
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Label")] CountryCode countryCode)
        {
            if (ModelState.IsValid)
            {
                _context.Add(countryCode);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(countryCode));
        }
        public async Task <IActionResult> Create([Bind("Id,ComName,Name,SciName,title")] Species species)
        {
            if (ModelState.IsValid)
            {
                db_context.Add(species);
                await db_context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(species));
        }