Beispiel #1
0
        public async Task <IHttpActionResult> AddToBasket(int veId)
        {
            if (veId <= 0)
            {
                return(BadRequest($"{nameof(veId)} must be greater than 0"));
            }

            var userId = ControllerHelper.GetCurrentUserId();

            // Check VE is exists already in basket
            if (!await client.IsUniqueVeInBasket(veId, userId))
            {
                return(Content(HttpStatusCode.OK, new OrderItemDto {
                    VeId = veId
                }));
            }

            var access       = GetUserAccess(WebHelper.GetClientLanguage(Request));
            var entityResult = elasticService.QueryForId <ElasticArchiveRecord>(veId, access);
            var entity       = entityResult.Response?.Hits?.FirstOrDefault()?.Source;

            if (entity == null)
            {
                return(Content(HttpStatusCode.NotFound, $"No Ve found with id {veId}"));
            }

            if (!entity.CanBeOrdered ||
                !(entity.Level == "Dossier" || entity.Level == "Subdossier" || entity.Level == "Dokument"))
            {
                return(Content(HttpStatusCode.Conflict, "Ve can not be ordered according to index"));
            }

            if (access.RolePublicClient == AccessRoles.RoleOe2 &&
                entity.MetadataAccessTokens.Contains($"EB_{access.UserId}"))
            {
                return(Content(HttpStatusCode.Conflict, "This Ve cannot be ordered as Ö2 user. Ö3 role is required."));
            }

            var indexSnapShot = OrderHelper.GetOrderingIndexSnapshot(entity);

            var orderItemDb = await client.AddToBasket(indexSnapShot, userId);

            return(Content(HttpStatusCode.Created, ConvertDbItemToDto(orderItemDb, OrderType.Bestellkorb, true)));
        }