コード例 #1
0
        public IActionResult DeleteConfirmedAsync(int id)
        {
            var userAccountId = applicationUserService.GetAll().Where(p => p.Id == id && p.RecordStatus == Helpdesk.Model.Enums.RecordStatus.A).Select(p => p.AccountId).FirstOrDefault();

            var userIdentityId = userManager.Users.Where(p => p.IsEnabled).Where(p => p.AccountId == userAccountId).Select(p => p.Id).FirstOrDefault();

            var user = userManager.FindByIdAsync(userIdentityId).Result;

            if (user == null)
            {
                return(new NotFoundResult());
            }

            var demands = demandService.GetAllDemand().Where(p => p.ApplicationUserAccountId == user.AccountId && ((p.IsAccepted && p.IsDissolved && p.IsCompleted != true) || (p.IsAccepted && p.IsDissolved != true && p.IsCompleted != true))).ToList();

            if (demands.Count > 0)
            {
                return(UnprocessableEntity());
            }

            var userMapping = companyAgentMappingService.GetMappingsByUserId(id);

            user.IsEnabled = false;
            var result = userManager.UpdateAsync(user);

            applicationUserService.Delete(user.AccountId);

            foreach (var map in userMapping)
            {
                companyAgentMappingService.Delete(map.Id);
            }

            foreach (var demand in demands)
            {
                demandService.UpdateForDeletedUser(demand);
            }

            return(Ok());
        }
コード例 #2
0
        public ContentResult GetAllIncomingDemands(int?orderType, string filterType)
        {
            var user = httpContextAccessor.HttpContext.User;
            IEnumerable <Claim> claims = user.Claims;
            var userIdentityId         = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var account           = userManager.FindByIdAsync(userIdentityId).Result;
            var roles             = userManager.GetRolesAsync(account).Result;
            var applicationUserId = applicationUserService.GetAllUser().Where(p => p.AccountId == account.AccountId).Select(p => p.Id).FirstOrDefault();

            //Belirtilen filtredeki tüm talepler
            var incomingDemands = demandService.GetAll(filterType, roles.ToList(), account.AccountId);

            if (!roles.Contains("Admin"))
            {
                //User'a ait tüm mappingler
                var mapping = companyAgentMappingService.GetMappingsByUserId(applicationUserId);

                //Özelleştirme koşularını sağlayan nihai talepler
                List <Demand> demands = new List <Demand>();

                //En az bir özelliştirme yapılan firmaların id'leri
                List <int> idsForCustomizedCompany = new List <int>();

                //Hiç özelliştirme yapılmayan firmaların id'leri
                List <int> idsForNoncustomizedCompany = new List <int>();

                foreach (var companyId in mapping.Select(p => p.CompanyId))
                {
                    var mapCompanyIds = companyAgentMappingService.GetMappingsByCompanyId(companyId);

                    if (mapCompanyIds.Where(p => p.IsSpecifiedForCompany).Select(q => q.CompanyId).ToList().Count > 0)
                    {
                        idsForCustomizedCompany.AddRange(mapCompanyIds.Where(p => p.IsSpecifiedForCompany).Select(q => q.CompanyId).ToList());
                    }
                    else
                    {
                        idsForNoncustomizedCompany.AddRange(mapCompanyIds.Select(q => q.CompanyId).ToList());
                    }
                }

                if (idsForCustomizedCompany.Count > 0)
                {
                    //Kullanıcının o firmada özelleştirilen bir mappingi var mı?
                    var maps = mapping.Where(p => idsForCustomizedCompany.Contains(p.CompanyId) && p.ApplicationUserId == applicationUserId && p.IsSpecifiedForCompany);

                    var demandsNew = incomingDemands.Where(p => maps.Select(q => q.CompanyId).Contains(p.CompanyId)).ToList();

                    demands.AddRange(demandsNew);
                }

                if (idsForNoncustomizedCompany.Count > 0)
                {
                    var maps = mapping.Where(p => idsForNoncustomizedCompany.Contains(p.CompanyId));

                    var demandsNew = incomingDemands.Where(p => maps.Select(q => q.CompanyId).Contains(p.CompanyId)).ToList();

                    demands.AddRange(demandsNew);
                }

                incomingDemands = demands;
            }

            if (orderType != null)
            {
                if (orderType == 1)
                {
                    incomingDemands = incomingDemands.OrderBy(p => p.OrderOfUrgencyId);
                }
                else if (orderType == 2)
                {
                    incomingDemands = incomingDemands.OrderByDescending(p => p.OrderOfUrgencyId);
                }
                else if (orderType == 3)
                {
                    incomingDemands = incomingDemands.OrderBy(p => p.CreateDate);
                }
                else if (orderType == 4)
                {
                    incomingDemands = incomingDemands.OrderByDescending(p => p.CreateDate);
                }
            }

            return(Content(JsonConvert.SerializeObject(incomingDemands), "application/json"));
        }