コード例 #1
0
        public async Task <IActionResult> Get([FromRoute] Guid?id)
        {
            IActionResult result = null;

            try
            {
                if (result == null && (!id.HasValue || id.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing invitation id parameter value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory        settingsFactory = scope.Resolve <SettingsFactory>();
                    CoreSettings           settings        = settingsFactory.CreateAccount(_settings.Value);
                    IUserInvitationFactory factory         = scope.Resolve <IUserInvitationFactory>();
                    IUserInvitation        innerInvitation = await factory.Get(settings, id.Value);

                    if (innerInvitation != null && !(await UserCanAccessInvitation(settings, innerInvitation)))
                    {
                        innerInvitation = null;
                    }
                    if (innerInvitation == null)
                    {
                        result = NotFound();
                    }
                    else
                    {
                        IMapper mapper = MapperConfigurationFactory.CreateMapper();
                        result = Ok(
                            await Map(mapper, settings, innerInvitation)
                            );
                    }
                }
            }
            catch (Exception ex)
            {
                using (ILifetimeScope scope = _container.BeginLifetimeScope())
                {
                    await LogException(ex, scope.Resolve <IExceptionService>(), scope.Resolve <SettingsFactory>(), _settings.Value);
                }
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
コード例 #2
0
        public async Task <IActionResult> Update([FromRoute] Guid?id, [FromBody] UserInvitation userInvitation)
        {
            IActionResult result = null;

            try
            {
                if (result == null && (!id.HasValue || id.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing id parameter value");
                }
                if (result == null && userInvitation == null)
                {
                    result = BadRequest("Missing user invitation body");
                }
                if (result == null && !userInvitation.ExpirationTimestamp.HasValue)
                {
                    result = BadRequest("Missing expiration timestamp value");
                }
                if (result == null && !userInvitation.Status.HasValue)
                {
                    result = BadRequest("Missing status value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory        settingsFactory   = scope.Resolve <SettingsFactory>();
                    CoreSettings           settings          = settingsFactory.CreateAccount(_settings.Value);
                    IAccountFactory        accountFactory    = scope.Resolve <IAccountFactory>();
                    IUserInvitationFactory invitationFactory = scope.Resolve <IUserInvitationFactory>();
                    IUserInvitation        innerInvitation   = await invitationFactory.Get(settings, id.Value);

                    if (innerInvitation != null && !(await UserCanAccessInvitation(settings, innerInvitation)))
                    {
                        innerInvitation = null;
                    }
                    if (innerInvitation == null)
                    {
                        result = NotFound();
                    }
                    else
                    {
                        if (DateTime.UtcNow < innerInvitation.ExpirationTimestamp &&
                            innerInvitation.Status != UserInvitationStatus.Cancelled &&
                            userInvitation.Status == (short)UserInvitationStatus.Completed &&
                            !UserTokenHasAccount(innerInvitation.AccountId))
                        {
                            await AddAccountUser(scope.Resolve <IUserFactory>(), scope.Resolve <IAccountSaver>(), settings, innerInvitation.AccountId);
                        }
                        IMapper mapper = MapperConfigurationFactory.CreateMapper();
                        mapper.Map <UserInvitation, IUserInvitation>(userInvitation, innerInvitation);
                        IUserInvitationSaver saver = scope.Resolve <IUserInvitationSaver>();
                        await saver.Update(settings, innerInvitation);

                        result = Ok(await Map(mapper, settings, innerInvitation));
                    }
                }
            }
            catch (Exception ex)
            {
                using (ILifetimeScope scope = _container.BeginLifetimeScope())
                {
                    await LogException(ex, scope.Resolve <IExceptionService>(), scope.Resolve <SettingsFactory>(), _settings.Value);
                }
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }