Example #1
0
        public async Task <IActionResult> CreatePayment([FromBody] PaymentDto Payment)
        {
            try
            {
                var result = await paymentService.AddPayment(Payment);

                return(Created($"api/Payments/{result.Data.Id}", result));
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
Example #2
0
        public async Task <object> AddPayment(PaymentRequest request)
        {
            try
            {
                var user = await _userService.GetUser((int)request.UserId);

                if (request.IsBonusPayment)
                {
                    decimal bonuceCoef = 5;

                    if (user.BonusScore < (request.Cost * bonuceCoef))
                    {
                        return(JsonResults.Error(errorNum: 404, errorMessage: "Not enough bonus score"));
                    }

                    user.BonusScore -= (int)(request.Cost * bonuceCoef);

                    var modelBonusPoint = new Bonus_Points
                    {
                        ServiceId = request.ServiceId,
                        UserId    = request.UserId,
                        Amount    = (request.Cost * bonuceCoef),
                        DateOfUse = DateTime.Now
                    };

                    await _bonus_PointService.AddBonus_Point(modelBonusPoint);
                }
                else
                {
                    user.BonusScore += (int)request.Cost;

                    var modelPayment = new Payment
                    {
                        UserId          = request.UserId,
                        Cost            = request.Cost,
                        ServiceId       = request.ServiceId,
                        Entert_CenterId = request.Entert_CenterId,
                        PaymentDate     = DateTime.Now
                    };

                    await _paymentsService.AddPayment(modelPayment);
                }

                await _userService.UpdateUser(user);

                var modelTicket = new Ticket
                {
                    PreOrder_Date = DateTime.Now,
                    ServiceId     = request.ServiceId,
                    UserId        = request.UserId,
                    Price         = request.Cost,
                    IsUse         = false
                };

                await _ticketService.AddTicket(modelTicket);

                return(JsonResults.Success());
            }
            catch (Exception ex)
            {
                return(JsonResults.Error(400, ex.Message));
            }
        }