示例#1
0
 public static PartnerOrganizationViewModel Map(this PartnerOrganization partner)
 {
     return(new PartnerOrganizationViewModel
     {
         Name = partner?.Name,
         RegistrationCode = partner?.RegistrationCode
     });
 }
示例#2
0
        public static IApplicationBuilder UseUserRegistration(this IApplicationBuilder app, string managerCode, string extensionId)
        {
            app.Use(async(context, next) =>
            {
                if (context.User.HasClaim(c => c.Type == "newUser" && c.Value == "true" && !context.User.HasClaim(c => c.Type == "extension_zaprole")))
                {
                    IGraphServiceClient graphClient = app.ApplicationServices.GetService <IGraphServiceClient>();

                    Claim id = context.User.Claims.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").FirstOrDefault();
                    if (id == null)
                    {
                        throw new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required on new user signin");
                    }

                    Claim registrationCode = context.User.Claims.Where(x => x.Type == "extension_RegistrationCode").FirstOrDefault();
                    if (registrationCode == null)
                    {
                        await graphClient.Users[id.Value].Request().DeleteAsync();
                        throw new ArgumentException("Registration Code is required on new user signin");
                    }

                    if (managerCode == registrationCode.Value)
                    {
                        context.User = await UpdateUserRole(context.User, "org_a_manager", id.Value, extensionId, graphClient);
                    }
                    else
                    {
                        IRepository <PartnerOrganization> partnerRepository = app.ApplicationServices.GetService <IRepository <PartnerOrganization> >();

                        PartnerOrganization partner = partnerRepository.Get(x => x.RegistrationCode == registrationCode.Value).FirstOrDefault();

                        if (partner == null)
                        {
                            await graphClient.Users[id.Value].Request().DeleteAsync();
                            throw new ArgumentException("No Partner organization found");
                        }

                        IRepository <Employee> employeeRepository = app.ApplicationServices.GetService <IRepository <Employee> >();

                        Employee employee = employeeRepository.Get(x => x.EmployeeId == id.Value).FirstOrDefault();
                        if (employee == null)
                        {
                            await employeeRepository.Add(new Employee {
                                EmployeeId = id.Value, PartnerOrgId = partner.id
                            });
                        }

                        context.User = await UpdateUserRole(context.User, "org_b_employee", id.Value, extensionId, graphClient);
                    }
                }

                await next.Invoke();
            });

            return(app);
        }
示例#3
0
        public async Task <IActionResult> AddPartner(PartnerOrganizationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PartnerOrganization partner = viewModel.Map();

            partner.RegistrationCode = this.GetCode();

            await this.repository.Add(partner);

            return(await this.Index());
        }
        public ActionResult PartnerOrganizations(PartnerOrganizationViewModel model)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            PartnerOrganization o = new PartnerOrganization();
            o.PartnerOrganizationType_ID = model.PartnerOrganizationType_ID;
            o.Title = model.Title;
            o.Abbr = model.Abbr;
            o.Description = model.Description;
            o.YearFounded = model.YearFounded;
            o.ColorCode = model.ColorCode;
            db.PartnerOrganizations.Add(o);
            db.SaveChanges();

            return View(model);
        }
示例#5
0
        public async Task <IActionResult> Register(NewUserViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Claim id = this.HttpContext.User.Claims.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").FirstOrDefault();

            if (id == null)
            {
                throw new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required");
            }

            if (managerCode == viewModel.RegistrationCode)
            {
                await this.UpdateUserRole("org_a_manager", id.Value);
            }
            else
            {
                PartnerOrganization partner = (await this.partnerRepository.Get(
                                                   "SELECT * FROM c WHERE c.RegistrationCode = @registrationCode",
                                                   new Dictionary <string, object> {
                    { "@registrationCode", viewModel.RegistrationCode }
                })).FirstOrDefault();

                if (partner == null)
                {
                    ViewData["ErrorMessage"] = this.stringLocalizer["WrongCodeError"];
                    return(View("Index"));
                }

                await this.UpdateUserRole("org_b_employee", id.Value);
            }

            return(Redirect("/AzureADB2C/Account/SignOut"));
        }