示例#1
0
        public async Task <ActionResult <Api.Track> > PostTrack([FromBody] Api.Track track)
        {
            try
            {
                if (!await ModelState.TryValidateObjectAsync(track))
                {
                    return(BadRequest(ModelState));
                }
                track.Name = track.Name?.ToLower();

                var mTrack = mapper.Map <Track>(track);
                await trackLogic.CreateTrackDocumentAsync(mTrack);

                await trackLogic.CreateLoginDocumentAsync(mTrack);

                return(Created(mapper.Map <Api.Track>(mTrack)));
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.Conflict)
                {
                    logger.Warning(ex, $"Conflict, Create '{typeof(Api.Track).Name}' by name '{track.Name}'.");
                    return(Conflict(typeof(Api.Track).Name, track.Name));
                }
                throw;
            }
        }
示例#2
0
        public async Task <ActionResult <Api.Track> > PutTrack([FromBody] Api.Track track)
        {
            try
            {
                if (!await ModelState.TryValidateObjectAsync(track))
                {
                    return(BadRequest(ModelState));
                }
                track.Name = track.Name?.ToLower();

                var mTrack = await tenantRepository.GetTrackByNameAsync(new Track.IdKey {
                    TenantName = RouteBinding.TenantName, TrackName = track.Name
                });

                mTrack.SequenceLifetime              = track.SequenceLifetime;
                mTrack.MaxFailingLogins              = track.MaxFailingLogins;
                mTrack.FailingLoginCountLifetime     = track.FailingLoginCountLifetime;
                mTrack.FailingLoginObservationPeriod = track.FailingLoginObservationPeriod;
                mTrack.PasswordLength          = track.PasswordLength;
                mTrack.CheckPasswordComplexity = track.CheckPasswordComplexity;
                mTrack.CheckPasswordRisk       = track.CheckPasswordRisk;
                mTrack.AllowIframeOnDomains    = track.AllowIframeOnDomains;
                await tenantRepository.UpdateAsync(mTrack);

                return(Ok(mapper.Map <Api.Track>(mTrack)));
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Update '{typeof(Api.Track).Name}' by name '{track.Name}'.");
                    return(NotFound(typeof(Api.Track).Name, track.Name));
                }
                throw;
            }
        }