public async Task <IActionResult> AddPurchasedEvents([Bind("EventId,UserId")] PurchasedEvents purchasedEvents)
        {
            var aUser = await _context.PurchasedEvents.FirstOrDefaultAsync(u => u.EventId == purchasedEvents.EventId && u.UserId == purchasedEvents.UserId);

            // if valid

            if (aUser is null)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(purchasedEvents);
                    await _context.SaveChangesAsync();

                    TempData["success"] = "Purchase successfull";
                    return(RedirectToAction("Search", "Restrict", new { area = "Users" }));
                }
            }
            else
            {
                TempData["message"] = "You have already Purchased this event";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "EventId", "EventCity", purchasedEvents.EventId);
            ViewData["UserId"]  = new SelectList(_context.Users, "UserId", "EmailId", purchasedEvents.UserId);
            return(View(purchasedEvents));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,MobileNumber,EmailId,Password,UserId,UserRoleFk")] Users users)
        {
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["UserRoleFk"] = new SelectList(_context.UserRole, "UserRolePk", "UserRoleDescription", users.UserRoleFk);
            return(View(users));
        }
        public async Task <IActionResult> Create([Bind("EventId,EventName,EventVenue,EventDuration,EventDate,EventStatus,EventOrganizerId,EventType,EventCity,EventZip,EventDescription,EventStartTime")] Events events)
        {
            if (ModelState.IsValid)
            {
                if (events.EventDate >= DateTime.Now.Date)
                {
                    _context.Add(events);
                    await _context.SaveChangesAsync();

                    TempData["success"] = "New Event Created";
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["message"] = "Cannot create event with past date";
                }
            }
            ViewData["EventOrganizerId"] = new SelectList(_context.Users, "UserId", "EmailId", events.EventOrganizerId);
            return(View(events));
        }
        public async Task <IActionResult> SignUp([Bind("FirstName,LastName,MobileNumber,EmailId,Password,UserRoleFk")] Users loginInfo)
        {
            if (ModelState.IsValid)
            {
                var aUser = await _context.Users.FirstOrDefaultAsync(u => u.EmailId == loginInfo.EmailId);

                if (aUser is null)
                {
                    _context.Add(loginInfo);
                    await _context.SaveChangesAsync();

                    TempData["success"] = "Account created";

                    return(RedirectToAction(nameof(Login)));
                }
                else
                {
                    ViewData["message"] = "Choose a different emailid";
                }
            }
            return(View(loginInfo));
        }