public IHttpActionResult UpdateWaiveFee(BookingInfo booking)
 {
     var invoice = new InvoiceHandler(Services).UpdateWaiveFee(booking.BookingId, CurrentUser.Id);
     return Json(new { Status = invoice.IsSuccess, Messsage = invoice.Messsage });
 }
Ejemplo n.º 2
0
        public JsonResult UpdateWaiveFee(Guid bookingId)
        {
            try
            {
                if (IsSpecialist())
                {
                    var test = new InvoiceHandler(Services).UpdateWaiveFee(bookingId, CurrentUser.Id);
                    return Json(new { success = test.IsSuccess, Messsage = test.Messsage });
                    //List<InvoiceDto> invoices = Services.Invoices.GetInvoiceByBookingId(bookingId);
                    //if (invoices != null && invoices.Any())
                    //{
                    //    var customerInvoice = invoices.First(x => x.Booking.Customer.Id == x.User.Id && x.Type == InvoiceType.Consultation);
                    //    var specialistInvoice = invoices.First(x => x.Booking.Specialist.Id == x.User.Id);

                    //    if (PaymentMethod.PrePayment.Equals(customerInvoice.User.PaymentMethod))
                    //    {
                    //        Log.Debug("Prepayment. User id: " + customerInvoice.User.Id);
                    //        customerInvoice.User.PrePaymentAmount = customerInvoice.User.PrePaymentAmount + specialistInvoice.Amount;
                    //        Services.Users.UpdateUserInfo(customerInvoice.User);
                    //    }
                    //    else
                    //    {
                    //        Log.Debug("Refund Transaction id: " + customerInvoice.TransactionId);
                    //        var result = Services.Payment.Refund(customerInvoice.TransactionId, specialistInvoice.Amount);
                    //        if (!result.Success)
                    //        {
                    //            return Json(new { success = false, Messsage = result.ErrorMessage });
                    //        }
                    //    }

                    //    InvoiceDto waivedFeeInvoice = Services.Invoices.UpdateWaiveFeeForSpecialistByBookingId(bookingId, CurrentUser.Id);
                    //    Log.Debug("Update waive fee: " + bookingId);
                    //    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    //    {
                    //        //Subtract consultation fee
                    //        waivedFeeInvoice.Amount = -waivedFeeInvoice.Amount;

                    //        string mailContent = Services.Invoices.TranformToInvoiceTemplate(
                    //            waivedFeeInvoice.User, waivedFeeInvoice, null, ConstEmailTemplateKey.WaiveFeeTemplate, null);

                    //        byte[] pdfAsByte = HtmlToPdf.GetPdfData(mailContent, AppSettings.BaseUrl);

                    //        string fileName = string.Format("invoice_{0}.pdf", waivedFeeInvoice.InvoiceNumber);

                    //        Services.Invoices.SendInvoice(fileName, pdfAsByte,
                    //            mailContent, customerInvoice.User.Email, string.Format(ConstEmailSubject.WaiveFeeInvoice, waivedFeeInvoice.Booking.ReferenceNo));
                    //    });

                    //    return Json(new { success = true });
                    //}
                    //return Json(new { success = false });
                }
            }
            catch (Exception e)
            {
                Log.Error("BookingController_UpdateWaiveFee_Error:", e);
            }
            return Json(new { success = false });
        }