コード例 #1
0
        public ActionResult AgentCustomizing([FromBody] CustomizedAgentViewModel customizedModel)
        {
            try
            {
                if (customizedModel.CompanyId > 0 && customizedModel.ApplicationUsers != null)
                {
                    var mappings = companyAgentMappingService.GetAll().Where(p => p.CompanyId == customizedModel.CompanyId && customizedModel.ApplicationUsers.Select(q => q.Id).Contains(p.ApplicationUserId));

                    foreach (var map in mappings)
                    {
                        map.IsSpecifiedForCompany = true;
                        companyAgentMappingService.Update(map);
                    }
                    return(View());
                }
                else
                {
                    return(UnprocessableEntity());
                }
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #2
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());
        }