public async Task <IActionResult> Post(GenaralCreateDto model)
        {
            Guid userId = Guid.Parse(sharedIdentityService.GetUserId);

            model.UserId = userId;
            Response <NoContent> response;

            try
            {
                IDTO dto = model.RequestType switch
                {
                    RequestType.Deposit => mapper.Map <CreateDepositRequest>(model),
                    RequestType.Product => mapper.Map <CreateProductDepositRequest>(model),
                    RequestType.NewType => mapper.Map <CreateNewTypeRequest>(model),
                    _ => throw new CustomException()
                };
                IEntityBase entity = null;
                switch (model.RequestType)
                {
                case RequestType.Deposit:
                    entity = await genericDepositRequestService.AddAsync(dto);

                    entity.CreatedUserId = userId;
                    await genericDepositRequestService.Commit();

                    break;

                case RequestType.Product:
                    entity = await genericProductRequestService.AddAsync(dto);

                    entity.CreatedUserId = userId;
                    await genericProductRequestService.Commit();

                    break;

                case RequestType.NewType:
                    entity = await genericNewTypeRequestService.AddAsync(dto);

                    entity.CreatedUserId = userId;
                    await genericNewTypeRequestService.Commit();

                    break;

                default:
                    throw new CustomException();
                }
                response = Response <NoContent> .Success(StatusCodes.Status201Created);

                logger.LogResponse(response, "Request başarıyla oluşturuldu ve eklendi.");
            }
            catch
            {
                response = Response <NoContent> .Fail(
                    statusCode : StatusCodes.Status400BadRequest,
                    isShow : true,
                    path : "[POST] api/request",
                    errors : "Desteklenmeyen istek tipi"
                    );

                logger.LogResponse(response, "Desteklenmeyen istek tipi.");
            }
            return(CreateResponseInstance(response));
        }
Esempio n. 2
0
        public async Task <Response <NoContent> > PostRequestAsync(GenaralCreateDto dto)
        {
            var httpResponse = await httpClient.PostAsJsonAsync("api/request", dto);

            return(await httpResponse.Content.ReadFromJsonAsync <Response <NoContent> >());
        }