Exemplo n.º 1
0
        public ActionResult AgentCustomizing()
        {
            try
            {
                var user = httpContextAccessor.HttpContext.User;
                IEnumerable <Claim> claims = user.Claims;

                var currentUserRole = httpContextAccessor.HttpContext.User.FindAll(ClaimTypes.Role).Select(p => p.Value);
                var currentUser     = userManager.GetUserAsync(HttpContext.User).Result;
                var accountId       = currentUser.AccountId;

                var companyId = 0;

                var mapping = companyAgentMappingService.GetAll();

                var customizedAgentViewModel = new CustomizedAgentViewModel();

                if (currentUserRole.Contains("Company Admin"))
                {
                    companyId = companyUserService.GetCompanyUserbyUserAccountId(accountId).CompanyId;
                    mapping   = companyAgentMappingService.GetMappingsByCompanyId(companyId);
                    customizedAgentViewModel.CompanyId = companyId;
                }

                var agentList = applicationUserService.GetAllUser();

                var joinedData = mapping.Join(agentList,
                                              e1 => e1.ApplicationUserId,
                                              e2 => e2.Id,
                                              (e1, e2) => e2).Distinct();

                ViewBag.Agents = JsonConvert.SerializeObject(joinedData);

                var companies = companyService.GetAllCompanyJson();
                ViewBag.Companies = companies;

                ViewBag.Model = JsonConvert.SerializeObject(customizedAgentViewModel);
            }
            catch (Exception)
            {
                throw;
            }

            return(View());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit([FromBody] UserViewModel userViewModel)
        {
            try
            {
                var account = userManager.FindByIdAsync(userViewModel.IdentityUserId).Result;
                var roles   = userManager.GetRolesAsync(account).Result;
                account.FirstName   = userViewModel.UserDto.FirstName;
                account.LastName    = userViewModel.UserDto.LastName;
                account.Email       = userViewModel.UserDto.Email;
                account.PhoneNumber = userViewModel.UserDto.MobileNumber;
                account.Id          = userViewModel.IdentityUserId;

                await userManager.UpdateAsync(account);

                var deleteRoles = userManager.RemoveFromRolesAsync(account, roles).Result;

                await userManager.AddToRolesAsync(account, userViewModel.UserRoles.Where(p => p.Selected).Select(p => p.RoleName).ToList());

                userViewModel.UserDto.ModifiedUser = User.FindFirst("FullName").Value;

                if (userViewModel.Companies != null)
                {
                    var mapping = companyAgentMappingService.GetAll().Where(p => p.ApplicationUserId == userViewModel.UserDto.Id && p.RecordStatus == Helpdesk.Model.Enums.RecordStatus.A);

                    //Eski maplerde olmayıp yeni seçtiği company'ler
                    var conflictedCompanies = userViewModel.Companies.Where(p => !mapping.Select(q => q.CompanyId).Contains(p.Id)).ToList();

                    //Eski maplerde olan fakat şimdi seçmediği company'ler
                    var nonConflictedMapping = mapping.Where(p => !userViewModel.Companies.Select(q => q.Id).Contains(p.CompanyId));

                    if (userViewModel.RecordSelection != 1)
                    {
                        foreach (var item in nonConflictedMapping)
                        {
                            companyAgentMappingService.Delete(item.Id);
                        }
                    }

                    if (conflictedCompanies.Count > 0)
                    {
                        companyAgentMappingService.Create(conflictedCompanies, userViewModel.UserDto.Id);
                    }
                }

                applicationUserService.Update(userViewModel.UserDto);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }