Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (RSU.ManagerId == -1)
            {
                return(Page());
            }

            RSU.Manager = _applicationDbContext.Managers.Find(RSU.ManagerId);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

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

            await _rsuService.AddAsync(managerUser, RSU);

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
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"));
        }