public Task <Result <InvoiceCoreModel> > Edit(UpdateInvoiceModel model) => Result <InvoiceCoreModel> .TryAsync(async() => { var invoice = (await _repository.FirstOrDefaultAsync <Invoice>(i => i.Id == model.Id, i => i.UserSurvey)) .Data; if (invoice == null) { return(Result <InvoiceCoreModel> .Failed(Error.WithData(1000, new[] { "invoice not found " }))); } var profile = await _membershipServiceApi.AuthAuthApiService.Profile(new BaseModel { Id = invoice.UserId }); if (model.Status != (InvoiceStatus)invoice.Status && model.Status == InvoiceStatus.Pending && model.Enabled) { _coreSmtpClient.SendInvoiceReady(profile.Data.Email, profile.Data.Firstname + " " + profile.Data.Lastname); } invoice.Amount = model.Amount + model.Amount * 5 / 100; invoice.TaxAmount = model.Amount * 5 / 100; invoice.Title = model.Title; invoice.Description = model.Description; invoice.Amount = model.Amount; if (model.Status == InvoiceStatus.Paid) { invoice.IsPaid = true; if (invoice.UserSurvey.Any()) { _coreSmtpClient.SendPaysForInvoicesNotif("*****@*****.**", profile.Data.Username, DateTime.Now.ToString("F")); } } invoice.Status = (byte)model.Status; invoice.Enabled = model.Enabled; await _repository.CommitAsync(); return(Result <InvoiceCoreModel> .Successful(_autoMapper.Map <InvoiceCoreModel>(invoice))); });
public async Task <Result <InvoiceCoreModel> > CaptureOrder(CaptureOrderModel model) { var invoice = await _repository.FirstOrDefaultAsync <Invoice>(i => i.Id == model.InvoiceId, i => i.PaypalOrder, i => i.Appointment, i => i.UserSurvey.Select(us => us.Tax)); if (!invoice.Success || invoice.Data == null) { return(Result <InvoiceCoreModel> .Failed(Error.WithData(1000, new[] { "Invoice not found" }))); } var capture = await _paypalHttpClient.Capture(invoice.Data.PaypalOrder.OrderId); if (!capture.Success) { return(Result <InvoiceCoreModel> .Failed(Error.WithData(1000, new[] { "Could not capture order" }))); } invoice.Data.IsPaid = true; invoice.Data.Enabled = true; invoice.Data.Status = (byte)InvoiceStatus.Paid; await _repository.CommitAsync(); var profile = await _membershipServiceApi.AuthAuthApiService.Profile(new BaseModel { Id = invoice.Data.UserId }); try { if (invoice.Data.UserSurvey != null && invoice.Data.UserSurvey.Any()) { invoice.Data.UserSurvey.FirstOrDefault().Tax.ToList() .ForEach(t => t.Status = (byte)TaxStatus.TaxProcessPending); await _repository.CommitAsync(); _coreSmtpClient.SendPaypalPayment(profile.Data.Email, profile.Data.Firstname + " " + profile.Data.Lastname); } if (invoice.Data.Appointment != null && invoice.Data.Appointment.Any()) { _coreSmtpClient.SendVipConsultation(profile.Data.Email, profile.Data.Firstname + " " + profile.Data.Lastname, invoice.Data.Appointment.FirstOrDefault().Date.ToString("F")); _coreSmtpClient.SendAppointmentBookNotif("*****@*****.**", profile.Data.Firstname + " " + profile.Data.Lastname, invoice.Data.Appointment.FirstOrDefault().Date.ToString("F")); await _messageBiz.Add(new CreateMessageModel { Title = "Your Appointment", Body = $"Your appointment has been confirmed. One of our AccNet representatives will reach out to you at the scheduled time : {invoice.Data.Appointment.FirstOrDefault().Date.ToString("F")} (PACIFIC STANDARD TIME)", ToUser = profile.Data.Id, Priority = MessagePriority.High }); } } catch (Exception e) { Console.WriteLine(e); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } _coreSmtpClient.SendPaysForInvoicesNotif("*****@*****.**", profile.Data.Username, DateTime.Now.ToString("F")); // var result = // await _membershipServiceApi.SystemUserApiService.Get(new MembershipService.ApiClient.Models.BaseModel // {Id = generalDataService.User.Id}); // _coreSmtpClient.SendInvoice(invoice.Data, result.Data); return(Result <InvoiceCoreModel> .Successful(new InvoiceCoreModel { Id = invoice.Data.Id, Amount = invoice.Data.Amount, Description = invoice.Data.Description, Title = invoice.Data.Title, Status = (InvoiceStatus)invoice.Data.Status, CreationDate = invoice.Data.CreationDate, Enabled = invoice.Data.Enabled, })); }