コード例 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = _applicationDbContext.Users
                       .Include(u => u.UserManagerUsers)
                       .FirstOrDefault(u => u.UserName == HttpContext.User.Identity.Name);

            var prevManager = _applicationDbContext.Managers
                              .Include(m => m.Users)
                              .FirstOrDefault(m => m.IP.ToString() == RSUEditM.prevMIP && m.Port == RSUEditM.prevMPort);

            if (prevManager == null)
            {
                // TODO
            }

            var manager = _applicationDbContext.Managers
                          .Include(m => m.Users)
                          .FirstOrDefault(m => m.IP.ToString() == RSUEditM.prevMIP && m.Port == RSUEditM.prevMPort);

            if (manager == null)
            {
                // TODO
            }

            if (prevManager.IP.ToString() != RSUEditM.ManagerIP || prevManager.Port != RSUEditM.ManagerPort)
            {
                var managerUserprev = user.UserManagerUsers.FirstOrDefault(umu => umu.ManagerUserManagerId == prevManager.Id)?.ManagerUser;
                if (managerUserprev == null)
                {
                    NotFound($"There's no Manager User assigned to this User, with {prevManager.Id} Manager");
                }

                var managerUser = user.UserManagerUsers.FirstOrDefault(umu => umu.ManagerUserManagerId == manager.Id)?.ManagerUser;
                if (managerUser == null)
                {
                    NotFound($"There's no Manager User assigned to this User, with {manager.Name} Manager");
                }

                await _rsuService.DeleteAsync(managerUserprev, RSUEditM.Id);

                await _rsuService.AddAsync(managerUser, RSUEditM.MapToRSUWithManager(manager));
            }
            else
            {
                var managerUser = user.UserManagerUsers.FirstOrDefault(umu => umu.ManagerUserManagerId == manager.Id)?.ManagerUser;
                if (managerUser == null)
                {
                    NotFound($"There's no Manager User assigned to this User, with {manager.Name} Manager");
                }

                await _rsuService.UpdateAsync(managerUser, RSUEditM.MapToRSUWithManager(manager));
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(int?id, int?managerId)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var user = _applicationDbContext.Users
                       .Include(u => u.UserManagerUsers)
                       .FirstOrDefault(u => u.UserName == HttpContext.User.Identity.Name);

            if (user == null)
            {
                // TODO finish
            }

            if (!managerId.HasValue)
            {
                return(NotFound());
            }

            var manager = _applicationDbContext.Managers
                          .Include(m => m.Users)
                          .FirstOrDefault(m => m.Id == managerId.Value);

            if (manager == null)
            {
                return(NotFound());
            }

            var managerUser = user.UserManagerUsers.FirstOrDefault(umu => umu.ManagerUserManagerId == managerId)?.ManagerUser;

            if (managerUser == null)
            {
                return(NotFound($"There's no Manager User assigned to this User, with {RSU.Manager.Name} Manager"));
            }

            RSU = await _rsuService.GetAsync(managerUser, id.Value);

            if (RSU == null)
            {
                return(NotFound());
            }
            else
            {
                await _rsuService.DeleteAsync(managerUser, id.Value);
            }


            return(RedirectToPage("./Index"));
        }