예제 #1
0
        public async Task <IActionResult> Register(string tripID)
        {
            var requestedTrip = await _context.Trip.Where(tr => tr.ID == tripID).FirstOrDefaultAsync();

            if (requestedTrip == null || HttpContext.Session.GetString("Email") == null || HttpContext.Session.GetString("Email").Length == 0)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "בקשה לא תקינה", ControllerToLink = "Trip", ActionToLink = nameof(Catalog), TextToLink = "חזרה לקטלוג הטיולים"
                }));
            }

            // To confirm the user exist and the trip  ID Exist
            //User from session

            var registeredUser = await _context.TripRegistration
                                 .Where(tr => tr.TripId == tripID).Where(tr => tr.UserEmail == HttpContext.Session.GetString("Email")).ToListAsync();

            if (registeredUser.Count != 0)
            {
                return(View("../TripRegistration/RegistrationExist"));
            }

            var tripReg = new TripRegistration();

            tripReg.ID                   = Guid.NewGuid().ToString();
            tripReg.TripId               = tripID;
            tripReg.UserEmail            = HttpContext.Session.GetString("Email");
            tripReg.RegistrationDateTime = DateTime.Now;

            _context.Add(tripReg);
            await _context.SaveChangesAsync();

            return(View("../TripRegistration/RegistrationSuccess"));
        }
        public async Task <IActionResult> Create([Bind("ID,TripId,UserEmail,RegistrationDateTime")] TripRegistration tripRegistration)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tripRegistration);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tripRegistration));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,ImageUrl,Country")] Place place)
        {
            if (getSessionUserType() != UserType.Admin)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "אינך מורשה לגשת לעמוד זה"
                }));
            }
            place.ID = Guid.NewGuid().ToString();
            if (ModelState.IsValid)
            {
                _context.Add(place);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(place));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Email,FullName,Phone,Password,Type")] User user)
        {
            if (ModelState.IsValid)
            {
                if (UserExists(user.Email))
                {
                    ModelState.AddModelError("UserExistsError", "האימייל שבחרת תפוס");
                    return(View(user));
                }
                user.Type = UserType.Tourist;
                _context.Add(user);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("Email", user.Email.ToString());
                HttpContext.Session.SetString("FullName", user.FullName.ToString());
                HttpContext.Session.SetInt32("Type", (int)user.Type);
                return(RedirectToAction("Index", "Home"));
            }
            return(View(user));
        }