Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description")] Todos todos)
        {
            if (id != todos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(todos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TodosExists(todos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(todos));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(string id, [Bind("UserId,RoleId")] AspNetUserRoles aspNetUserRoles)
        {
            if (id != aspNetUserRoles.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aspNetUserRoles);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspNetUserRolesExists(aspNetUserRoles.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.AspNetRoles, "Id", "Id", aspNetUserRoles.RoleId);
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUserRoles.UserId);
            return(View(aspNetUserRoles));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,TodoId")] Tasks tasks)
        {
            if (id != tasks.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tasks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TasksExists(tasks.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", new RouteValueDictionary(
                                            new { controller = "Todos", action = "Details", Id = tasks.TodoId })));
            }
            ViewData["TodoId"] = new SelectList(_context.Todos, "Id", "Description", tasks.TodoId);


            return(View(tasks));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,AspNetUserId,Moment,Eventdescription")] Logbooks Logbooks)
        {
            if (id != Logbooks.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(Logbooks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LogbooksExists(Logbooks.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AspNetUserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", Logbooks.AspNetUserId);
            return(View(Logbooks));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TaskId,UserId,BeginTask,EndTask,State")] UserTasks userTasks)
        {
            if (id != userTasks.Id)
            {
                return(NotFound());
            }

            // Protection : If a user try to access another usertask page, redirect to the homepage
            var currentRole   = User.FindFirstValue(ClaimTypes.Role);
            var currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);



            if (currentRole == "User")
            {
                if (userTasks.UserId != currentUserId)
                {
                    return(RedirectToAction("Index", new RouteValueDictionary(
                                                new { controller = "Home", action = "Index", Id = userTasks.UserId })));
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userTasks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserTasksExists(userTasks.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                // Add the event into the Logbooks
                //EXAM

                /*return RedirectToAction("Create", new RouteValueDictionary(
                 *      new { controller = "Logbookss", action = "Create", Id = userTasks.UserId }));*/

                // Redirect the user to the details vue of the user
                if (id == userTasks.Id)
                {
                    return(RedirectToAction("Details", new RouteValueDictionary(
                                                new { controller = "AspNetUsers", action = "Details", Id = userTasks.UserId })));
                }
                return(RedirectToAction(nameof(Index)));
            }

            // Add to the view usefull data informations
            ViewData["TaskId"] = new SelectList(_context.Tasks, "Id", "Description", userTasks.TaskId);
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", userTasks.UserId);
            ViewData["State"]  = new SelectList(_context.UserTasks, "Id", "State", userTasks.State);

            return(View(userTasks));
        }