Esempio n. 1
0
        public async Task <AgencySettingsStep2ViewModel> GetStep2ByUserIdAsync(string userId)
        {
            var agency = await _dbContext.Agencies.FirstOrDefaultAsync(c => c.ManagerId == userId);

            var agencyViewModel = new AgencySettingsStep2ViewModel
            {
                YearOfEstablishment = agency.YearOfEstablishment.GetValueOrDefault(),
                About             = agency.About,
                Id                = agency.Id,
                OrganizationOther = agency.OrganizationOther,
            };

            agencyViewModel.Emphases = Enum.GetValues(typeof(EmphasisType)).Cast <EmphasisType>().Select(c => new EmphasisViewModel
            {
                Selected     = agency.EmphasisList.Any(e => e.EmphasisType == c),
                EmphasisType = c
            }).ToList();

            agencyViewModel.Organizations = Enum.GetValues(typeof(OrganizationType)).Cast <OrganizationType>().Select(c => new OrganizationViewModel
            {
                Selected         = agency.Organizations.Any(e => e.Type == c),
                OrganizationType = c
            }).ToList();

            return(agencyViewModel);
        }
Esempio n. 2
0
        public async Task <ActionResult> Step2(AgencySettingsStep2ViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _agencyService.SaveStep2ByUserId(model, User.Identity.GetUserId());

                return(RedirectToAction(nameof(Step3)));
            }
            return(View(model));
        }
Esempio n. 3
0
        public async Task SaveStep2ByUserId(AgencySettingsStep2ViewModel model, string userId)
        {
            var agency = _dbContext.Agencies.FirstOrDefault(c => c.ManagerId == userId);

            if (agency == null)
            {
                throw new ArgumentNullException(nameof(agency));
            }
            agency.YearOfEstablishment = model.YearOfEstablishment;
            agency.About             = model.About;
            agency.OrganizationOther = model.OrganizationOther;

            foreach (var emphasisViewModel in model.Emphases)
            {
                if (emphasisViewModel.Selected && agency.EmphasisList.All(c => c.EmphasisType != emphasisViewModel.EmphasisType))
                {
                    agency.EmphasisList.Add(new Emphasis {
                        EmphasisType = emphasisViewModel.EmphasisType
                    });
                }
                else if (!emphasisViewModel.Selected && agency.EmphasisList.Any(c => c.EmphasisType == emphasisViewModel.EmphasisType))
                {
                    var item = agency.EmphasisList.FirstOrDefault(c => c.EmphasisType == emphasisViewModel.EmphasisType);
                    if (item != null)
                    {
                        _dbContext.Emphases.Remove(item);
                    }
                }
            }
            foreach (var organization in model.Organizations)
            {
                if (organization.Selected && agency.Organizations.All(c => c.Type != organization.OrganizationType))
                {
                    agency.Organizations.Add(new Organization {
                        Type = organization.OrganizationType
                    });
                }
                else if (!organization.Selected && agency.Organizations.Any(c => c.Type == organization.OrganizationType))
                {
                    var item = agency.Organizations.FirstOrDefault(c => c.Type == organization.OrganizationType);
                    if (item != null)
                    {
                        _dbContext.Organizations.Remove(item);
                    }
                }
            }
            await _dbContext.SaveChangesAsync();
        }
Esempio n. 4
0
        public ActionResult AddBranch(AgencySettingsStep2ViewModel model)
        {
            var list = _agencyService.AddBranch(model.AddBranchModel, User.Identity.GetUserId());

            return(PartialView("_BranchesTablePartial", list));
        }