Beispiel #1
0
 public IActionResult CreateActivity(ActivityViewModel model)
 {
     if (ModelState.IsValid)
     {
         int?     Id          = HttpContext.Session.GetInt32("id");
         User     user        = _context.users.SingleOrDefault(u => u.UserId == Id);
         Activity NewActivity = new Activity
         {
             Title       = model.Title,
             Datetime    = model.Date + model.Time,
             Duration    = model.Duration * model.Units,
             Description = model.Description,
             UserId      = (int)Id,
             Address     = model.Address,
         };
         _context.activities.Add(NewActivity);
         _context.SaveChanges();
         Activity lastActivity = _context.activities.Last();
         int      activityId   = lastActivity.ActivityId;
         return(RedirectToAction("Activity", new { ActivityId = activityId }));
     }
     return(View("Add", model));
 }
        public IActionResult Register(RegistrationViewModel model1)
        {
            if (ModelState.IsValid)
            {
                User NewUser = new User
                {
                    FirstName = model1.FirstName,
                    LastName  = model1.LastName,
                    Email     = model1.Email,
                    Password  = model1.Password
                };
                _context.users.Add(NewUser);
                _context.SaveChanges();
                User last = _context.users.Last();
                int  id   = last.UserId;
                HttpContext.Session.SetInt32("id", id);
                return(RedirectToAction("Index", "Dashboard"));
            }
            ModelBundle Bundle = new ModelBundle {
                model1 = model1, model2 = new LoginViewModel()
            };

            return(View("Index", Bundle));
        }