Пример #1
0
        public async Task <IActionResult> CreateTransaction([FromBody] Models.TransactionRequest transactionRequest)
        {
            try
            {
                Entities.Transaction transaction = _mapper.Map <Entities.Transaction>(transactionRequest);
                transaction.SenderId = int.Parse(User.Claims.First(c => c.Type == "premisesID").Value);
                var createByID = int.Parse(User.Claims.First(c => c.Type == "userID").Value);
                transaction.CreateById = createByID;
                await _transactionBL.CreateSellFoodTransactionAsync(transaction);

                var transactionHash = await _foodDataBL.AddCertification(transactionRequest.FoodId, transactionRequest.CertificationNumber, createByID);

                await _foodBL.AddDetail(transactionRequest.FoodId, EFoodDetailType.VERIFY, transactionHash, transaction.CreateById);

                var reponseModel = new Models.TransactionReponse.CreateTransactionReponse()
                {
                    TransactionId = transaction.TransactionId
                };
                return(Ok(new { message = MessageConstant.INSERT_SUCCESS }));
            }
            catch (InvalidDataException ex)
            {
                return(BadRequest(new { message = ex.Message, error = ex.StackTrace }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = MessageConstant.UNHANDLE_ERROR, error = ex.StackTrace }));
            }
        }