diff --git a/RMuseum/Controllers/DonationAccountingController.cs b/RMuseum/Controllers/DonationAccountingController.cs index ee228406..1e5501dd 100644 --- a/RMuseum/Controllers/DonationAccountingController.cs +++ b/RMuseum/Controllers/DonationAccountingController.cs @@ -15,6 +15,29 @@ namespace RMuseum.Controllers [Route("api/donations")] public class DonationAccountingController : Controller { + /// + /// returns all donations + /// + /// + [HttpGet] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorDonationViewModel[]))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetDonations() + { + try + { + var res = await _donationService.GetDonations(); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + catch (Exception exp) + { + return BadRequest(exp.ToString()); + } + } + /// /// add donation + regenerate donations page /// @@ -69,6 +92,29 @@ namespace RMuseum.Controllers } } + /// + /// returns all expenses + /// + /// + [HttpGet("expenses")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorExpense[]))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetExpenses() + { + try + { + var res = await _donationService.GetExpenses(); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + catch (Exception exp) + { + return BadRequest(exp.ToString()); + } + } + /// /// add expense + regenerate donations page /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 907a5d14..2b41496c 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -584,6 +584,12 @@ + + + returns all donations + + + add donation + regenerate donations page @@ -598,6 +604,12 @@ + + + returns all expenses + + + add expense + regenerate donations page @@ -6901,6 +6913,18 @@ + + + returns all donations + + + + + + returns all expenses + + + Show Donating Information (temporary switch off/on) @@ -8000,6 +8024,18 @@ + + + returns all donations + + + + + + returns all expenses + + + donation page row diff --git a/RMuseum/Services/IDonationService.cs b/RMuseum/Services/IDonationService.cs index d72cbbdb..2738499e 100644 --- a/RMuseum/Services/IDonationService.cs +++ b/RMuseum/Services/IDonationService.cs @@ -57,6 +57,18 @@ namespace RMuseum.Services /// Task> RegenerateDonationsPage(Guid editingUserId, string note); + /// + /// returns all donations + /// + /// + Task> GetDonations(); + + /// + /// returns all expenses + /// + /// + Task> GetExpenses(); + /// /// Show Donating Information (temporary switch off/on) /// diff --git a/RMuseum/Services/Implementation/DonationService.cs b/RMuseum/Services/Implementation/DonationService.cs index 4773d581..d877ab5d 100644 --- a/RMuseum/Services/Implementation/DonationService.cs +++ b/RMuseum/Services/Implementation/DonationService.cs @@ -283,6 +283,68 @@ namespace RMuseum.Services.Implementation } } + /// + /// returns all donations + /// + /// + public async Task> GetDonations() + { + try + { + return new RServiceResult + ( + await _context.GanjoorDonations + .AsNoTracking() + .OrderByDescending(d => d.Id) + .Select + ( + d => + new GanjoorDonationViewModel() + { + Id = d.Id, + Amount = d.Amount, + AmountString = d.AmountString, + DateString = d.DateString, + DonorName = d.DonorName, + ExpenditureDesc = d.ExpenditureDesc, + ImportedRecord = d.ImportedRecord, + RecordDate = d.RecordDate, + Remaining = d.Remaining, + Unit = d.Unit + } + ).ToArrayAsync() + + ); + } + catch(Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + + /// + /// returns all expenses + /// + /// + public async Task> GetExpenses() + { + try + { + return new RServiceResult + ( + await _context.GanjoorExpenses + .AsNoTracking() + .OrderByDescending(x => x.Id) + .ToArrayAsync() + + ); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + /// /// donation page row ///