public IActionResult Get(int id) { IActionResult ret = null; ContributionCategory entity = null; try { using (var db = new BTAContext()) { entity = db.ContributionCategory.Find(id); if (entity != null) { ret = StatusCode(StatusCodes.Status200OK, entity); } else { Logger.LogError(string.Format("Can't find contribution category entry: {0}", id)); ret = StatusCode(StatusCodes.Status404NotFound); } } } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while attempting to retrieve a single contribution category entry."); ret = StatusCode(StatusCodes.Status500InternalServerError); } return(ret); }
public IActionResult Post([FromBody] ContributionCategory entity) { var result = new ContributionCategoryActionResult(false, new List <string>(), null); try { if (entity != null) { using (var db = new BTAContext()) { db.ContributionCategory.Add(entity); db.SaveChanges(); result.Success = true; result.StatusMessages.Add("Successfully added contribution category."); result.Data = entity; } } else { result.Success = false; result.StatusMessages.Add("Invalid data passed to create new contribution category."); result.Data = null; } } catch (Exception ex) { Logger.LogError("Exception trying to insert a new contribution category entry."); Logger.LogError(ex.ToString()); result.Success = false; result.Data = null; result.StatusMessages.Add("Exception trying to insert a new contribution category entry."); } return(StatusCode(StatusCodes.Status200OK, result)); }
public IActionResult Delete(int id) { var returnResult = new ContributionCategoryActionResult(false, new List <string>(), null); try { using (var db = new BTAContext()) { if (db.ContributionCategory.Any(x => x.ContributionCategoryId == id) == false) { returnResult.StatusMessages.Add("Attempted to delete a nonexisting contribution category."); } else { var resultCategory = db.ContributionCategory.Single(x => x.ContributionCategoryId == id); db.ContributionCategory.Remove(resultCategory); db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultCategory; returnResult.StatusMessages.Add("Successfully deleted contribution category."); } } } catch (Exception e) { Logger.LogError("An exception occurred while attempting to delete a contribution category."); Logger.LogError(e.ToString()); returnResult.Success = false; returnResult.StatusMessages.Add("An exception occurred while attempting to delete a contribution category."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public IActionResult Get(bool includeInactive) { IActionResult ret = null; List <ContributionCategory> list = new List <ContributionCategory>(); try { using (var db = new BTAContext()) { if (db.ContributionCategory.Count() > 0) { // If includeInactive == true, return all, otherwise return only active records. list = db.ContributionCategory .Where(x => (x.Active.HasValue && x.Active.Value) || includeInactive) .OrderBy(p => p.DisplayOrder) .ToList(); ret = StatusCode(StatusCodes.Status200OK, list); } } } catch (Exception ex) { Logger.LogError(ex, "Exception trying to get all contribution categories."); ret = StatusCode(StatusCodes.Status200OK, list); } return(ret); }
public IActionResult Get(int id) { IActionResult ret = null; ContributionType entity = null; try { using (var db = new BTAContext()) { entity = db.ContributionType.Find(id); if (entity != null) { ret = StatusCode(StatusCodes.Status200OK, entity); } else { ret = StatusCode(StatusCodes.Status404NotFound, "Can't Find contribution type for id: " + id.ToString()); } } } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while trying to retrieve a single contribution type."); ret = StatusCode(StatusCodes.Status500InternalServerError); } return(ret); }
public IActionResult GetViewModels(bool includeInactive) { IActionResult ret = null; List <ContributionTypeViewModel> list = new List <ContributionTypeViewModel>(); try { using (var db = new BTAContext()) { if (db.ContributionType.Count() > 0) { // If includeInactive == true, return all, otherwise return only active records. list = db.ContributionType .Where(x => x.Active ?? false || includeInactive) .Select(x => new ContributionTypeViewModel() { ContributionTypeID = x.ContributionTypeId, CategoryID = x.CategoryId, CategoryDescription = x.Category.Description, ContributionTypeName = x.ContributionTypeName, DisplayOrder = x.DisplayOrder, Active = x.Active ?? false }).ToList(); } ret = StatusCode(StatusCodes.Status200OK, list); } } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while trying to retrieve contribution types."); ret = StatusCode(StatusCodes.Status500InternalServerError); } return(ret); }
public IActionResult Get(bool includeInactive) { IActionResult ret = null; List <ContributionType> list = new List <ContributionType>(); try { using (var db = new BTAContext()) { if (db.ContributionType.Count() > 0) { // If includeInactive == true, return all, otherwise return only active records. list = db.ContributionType .Where(x => (x.Active.HasValue && x.Active.Value) || includeInactive) .OrderBy(x => x.DisplayOrder) .ToList(); } ret = StatusCode(StatusCodes.Status200OK, list); } } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while trying to retrieve contribution types."); ret = StatusCode(StatusCodes.Status500InternalServerError); } return(ret); }
public IActionResult ReportView([FromForm] string reportParameters) { ReportParameters reportParms = JsonConvert.DeserializeObject <ReportParameters>(reportParameters); ExcelPackage excel = new ExcelPackage(); excel.Workbook.Worksheets.Add(reportParms.ReportName); using (var db = new BTAContext()) { var rpt = db.Report.SingleOrDefault(x => x.Name == reportParms.ReportName); if (rpt == null) { throw new ArgumentException("An invalid report name was passed", "Report Name"); } var rptFactory = new ReportFactory(db); var rptHandler = rptFactory.Create(reportParms.ReportName); rptHandler.ProcessReport(excel, reportParms, db); } string fileName = string.Format("{0}_{1:yyyyMMdd_hhmmss}.xlsx", reportParms.ReportName, DateTime.Now); string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; var mstream = new MemoryStream(); excel.SaveAs(mstream); Logger.LogDebug("Content Type: {0} | File Name: {1} | File Size: {2}", contentType, fileName, mstream.Length); var fsr = new FileStreamResult(mstream, contentType) { FileDownloadName = fileName }; return(fsr); }
public IActionResult Delete(int id) { var returnResult = new ContributorActionResult(false, new List <string>(), null); try { using (var db = new BTAContext()) { if (db.Contributor.Any(x => x.ContributorId == id) == false) { returnResult.Success = false; returnResult.StatusMessages.Add(string.Format("Unable to locate contributor for id: {0}", id)); returnResult.Data = null; } else { var resultContributor = db.Contributor.Single(x => x.ContributorId == id); db.Remove(resultContributor); db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultContributor; returnResult.StatusMessages.Add("Successfully deleted contributor."); } } } catch (Exception e) { Logger.LogError(e.ToString()); returnResult.Success = false; returnResult.StatusMessages.Add("An exception occurred while attempting to delete the contributor."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public SecurityUserAuth ValidateUser(User user) { SecurityUserAuth ret = new SecurityUserAuth(); User authUser = null; using (var db = new BTAContext()) { // Attempt to validate user authUser = db.User.FirstOrDefault(u => u.UserName.ToLower() == user.UserName.ToLower() && u.Password == user.Password); if (authUser != null) { db.Entry(authUser).Collection(x => x.UserClaim).Load(); foreach (var uc in authUser.UserClaim) { db.Entry(uc).Reference(x => x.Claim).Load(); } } } if (authUser != null) { // Build User Security Object ret = BuildUserAuthObject(authUser); } return(ret); }
public IActionResult Get(int id) { IActionResult ret = null; Address entity = null; try { using (var db = new BTAContext()) { entity = db.Address.Find(id); if (entity != null) { ret = StatusCode(StatusCodes.Status200OK, entity); } else { ret = StatusCode(StatusCodes.Status404NotFound, "Can't Find Address: " + id.ToString()); } } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to retrieve a single Address."); } return(ret); }
public IActionResult Delete(int id) { var returnResult = new AddressActionResult(false, new List <string>(), null); try { using (var db = new BTAContext()) { if (db.Address.Any(x => x.AddressId == id) == false) { returnResult.StatusMessages.Add("Attempted to delete a nonexisting address."); } else { var resultAddress = db.Address.Single(x => x.AddressId == id); db.Address.Remove(resultAddress); db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultAddress; returnResult.StatusMessages.Add("Successfully deleted address."); } } } catch (Exception e) { returnResult.Success = false; returnResult.StatusMessages.Add(e.Message); returnResult.Data = null; } return(returnResult.Success ? StatusCode(StatusCodes.Status200OK, returnResult) : StatusCode(StatusCodes.Status500InternalServerError, returnResult)); }
public IActionResult Get() { IActionResult ret = null; List <Address> list = new List <Address>(); try { using (var db = new BTAContext()) { if (db.Address.Count() > 0) { list = db.Address .OrderBy(r => r.State) .ThenBy(r => r.City) .ThenBy(r => r.PostalCode) .ToList(); } ret = StatusCode(StatusCodes.Status200OK, list); } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to get all Addresses"); } return(ret); }
public IActionResult ExecuteReport([FromBody] ReportParameters reportParameters) { ExcelPackage excel = new ExcelPackage(); excel.Workbook.Worksheets.Add(reportParameters.ReportName); using (var db = new BTAContext()) { var rpt = db.Report.SingleOrDefault(x => x.Name == reportParameters.ReportName); if (rpt == null) { throw new ArgumentException("An invalid report name was passed", "Report Name"); } var rptFactory = new ReportFactory(db); var rptHandler = rptFactory.Create(reportParameters.ReportName); rptHandler.ProcessReport(excel, reportParameters, db); } string fileName = string.Format("{0}_{1:yyyyMMdd_hhmmss}.xlsx", reportParameters.ReportName, DateTime.Now); var mstream = new MemoryStream(); excel.SaveAs(mstream); return(new FileStreamResult(mstream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = string.Format("{0}_{1:yyyyMMdd_hhmmss}.xlsx", reportParameters.ReportName, DateTime.Now) }); }
public IActionResult Put([FromBody] CashJournal entity) { IActionResult ret = null; try { if (entity != null) { using (var db = new BTAContext()) { db.Update(entity); db.SaveChanges(); ret = StatusCode(StatusCodes.Status200OK, entity); } } else { ret = StatusCode(StatusCodes.Status400BadRequest, "Invalid data passed for cash journal update"); } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to update cash journal entry: " + entity.CashJournalId.ToString()); } return(ret); }
public IActionResult Get() { IActionResult ret = null; List <Report> list = new List <Report>(); try { using (var db = new BTAContext()) { if (db.Report.Count() > 0) { list = db.Report.Where(r => r.Active ?? false).OrderBy(r => r.DisplayOrder).ToList(); ret = StatusCode(StatusCodes.Status200OK, list); } else { ret = StatusCode(StatusCodes.Status404NotFound, "Can't Find Reports"); } } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to get all reports"); } return(ret); }
public IActionResult Get() { IActionResult ret = null; List <CashJournal> list = new List <CashJournal>(); try { using (var db = new BTAContext()) { if (db.CashJournal.Count() > 0) { list = db.CashJournal.OrderBy(p => p.CreatedDate).ToList(); ret = StatusCode(StatusCodes.Status200OK, list); } else { ret = StatusCode(StatusCodes.Status404NotFound, "Can't Find Cash Journal Entries"); } } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to get all cash journal entries"); } return(ret); }
public IActionResult Get() { IActionResult ret = null; List <Contributor> list = new List <Contributor>(); try { using (var db = new BTAContext()) { if (db.Contributor.Count() > 0) { list = db.Contributor .OrderBy(r => r.LastName) .ThenBy(r => r.FirstName) .ThenBy(r => r.MiddleName) .ToList(); } ret = StatusCode(StatusCodes.Status200OK, list); } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to get all Contributor"); } return(ret); }
public IActionResult GetUsers() { IActionResult results = null; List <SecurityUserEdit> users = new List <SecurityUserEdit>(); try { using (var db = new BTAContext()) { users = db.User.Select(x => new SecurityUserEdit() { UserID = x.UserId, UserName = x.UserName, DisplayName = x.DisplayName, Password = x.Password }).ToList(); foreach (var u in users) { var userClaims = db.UserClaim.Where(x => x.UserId == u.UserID).ToList(); u.Claims = userClaims.Select(x => x.Claim).ToList(); } results = StatusCode(StatusCodes.Status200OK, users); } } catch (Exception e) { results = HandleException(e, "Exception trying to get all users"); } return(results); }
public IActionResult Post([FromBody] CashJournal entity) { IActionResult ret = null; try { if (entity != null) { using (var db = new BTAContext()) { db.CashJournal.Add(entity); db.SaveChanges(); ret = StatusCode(StatusCodes.Status201Created, entity); } } else { ret = StatusCode(StatusCodes.Status400BadRequest, "Invalid data passed to create new cash journal entry"); } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to insert a new cash journal entry"); } return(ret); }
public IActionResult Put([FromBody] Address address) { string json = JsonConvert.SerializeObject(address); var returnResult = new AddressActionResult(false, new List <string>(), null); if (address != null) { if (address.AddressId <= 0) { returnResult.StatusMessages.Add("Attempting to update an existing address, but an Id is not present."); } else { try { using (var db = new BTAContext()) { var resultAddress = db.Address.SingleOrDefault(x => x.AddressId == address.AddressId); if (resultAddress != null) { resultAddress.AddressLine1 = address.AddressLine1; resultAddress.AddressLine2 = address.AddressLine2; resultAddress.AddressLine3 = address.AddressLine3; resultAddress.City = address.City; resultAddress.State = address.State; resultAddress.PostalCode = address.PostalCode; db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultAddress; returnResult.StatusMessages.Add("Successfully updated address."); } else { returnResult.Success = false; returnResult.StatusMessages.Add(string.Format("Unable to locate address for index: {0}", address.AddressId)); returnResult.Data = null; } } } catch (Exception e) { returnResult.Success = false; returnResult.StatusMessages.Add(e.Message); returnResult.Data = null; } } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty address posted for update."); returnResult.Data = null; } return(returnResult.Success ? StatusCode(StatusCodes.Status200OK, returnResult) : StatusCode(StatusCodes.Status500InternalServerError, returnResult)); }
public IActionResult Post([FromBody] Contributor contributor) { var returnResult = new ContributorActionResult(false, new List <string>(), null); if (contributor != null) { try { using (var db = new BTAContext()) { var contrib = new Contributor() { FirstName = contributor.FirstName, MiddleName = contributor.MiddleName, LastName = contributor.LastName, AddressId = contributor.AddressId }; var resultContributor = db.Contributor.Add(contrib); db.SaveChanges(); var entity = resultContributor.Entity; if (entity != null) { returnResult.Success = true; returnResult.StatusMessages.Add("Successfully added contributor."); returnResult.Data = entity; } else { returnResult.Success = false; returnResult.StatusMessages.Add("Failed to add contributor."); returnResult.Data = entity; } } } catch (Exception e) { string errMsg = "An exception occurred while attempting to add a contributor."; Logger.LogError(e, errMsg); returnResult.Success = false; returnResult.StatusMessages.Add(errMsg); returnResult.Data = null; } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty contributor posted for add."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public IActionResult Put([FromBody] Contributor contributor) { var returnResult = new ContributorActionResult(false, new List <string>(), null); if (contributor != null) { try { using (var db = new BTAContext()) { var resultContributor = db.Contributor.SingleOrDefault(x => x.ContributorId == contributor.ContributorId); if (resultContributor != null) { resultContributor.FirstName = contributor.FirstName; resultContributor.MiddleName = contributor.MiddleName; resultContributor.LastName = contributor.LastName; resultContributor.AddressId = contributor.AddressId; db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultContributor; returnResult.StatusMessages.Add("Successfully updated contributor."); } else { string errMsg = string.Format("Unable to locate contributor for id: {0}", contributor.ContributorId); Logger.LogError(errMsg, null); returnResult.Success = false; returnResult.StatusMessages.Add(errMsg); returnResult.Data = null; } } } catch (Exception e) { string excMsg = "An exception occurred while attempting to update a contributor."; Logger.LogError(e, excMsg); returnResult.Success = false; returnResult.StatusMessages.Add(excMsg); returnResult.Data = null; } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty contributor posted for update."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public void ProcessReport(ExcelPackage excel, ReportParameters reportParameters, DbContext db) { var workSheet = excel.Workbook.Worksheets[reportParameters.ReportName]; workSheet.Cells[1, 1].Value = "I have successfully processed the report!"; BTAContext dc = (BTAContext)db; var reports = dc.Report; int whichRow = 2; foreach (var rpt in reports) { string cellContents = string.Format("ID: {0} | Name: {1} | Display Name: {2} | Active: {3} | Display Order: {4}", rpt.ReportId, rpt.Name, rpt.DisplayName, rpt.Active, rpt.DisplayOrder); workSheet.Cells[whichRow, 1].Value = cellContents; whichRow++; } }
public IActionResult Post([FromBody] Address address) { string json = JsonConvert.SerializeObject(address); var returnResult = new AddressActionResult(false, new List <string>(), null); if (address != null) { if (address.AddressId > 0) { returnResult.StatusMessages.Add("Attempting to create a new address, but an Id is present."); } else { try { using (var db = new BTAContext()) { var resultAddress = db.Address.Add(address); db.SaveChanges(); var entity = resultAddress.Entity; if (entity != null) { returnResult.Success = true; returnResult.StatusMessages.Add("Successfully added address."); returnResult.Data = entity; } } } catch (Exception e) { returnResult.Success = false; returnResult.StatusMessages.Add(e.Message); returnResult.Data = null; } } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty address posted for add."); returnResult.Data = null; } return(returnResult.Success ? StatusCode(StatusCodes.Status200OK, returnResult) : StatusCode(StatusCodes.Status500InternalServerError, returnResult)); }
public IActionResult Put([FromBody] ContributionType contributionType) { var returnResult = new ContributionTypeActionResult(false, new List <string>(), null); if (contributionType != null) { try { using (var db = new BTAContext()) { var resultContributionType = db.ContributionType.SingleOrDefault(x => x.ContributionTypeId == contributionType.ContributionTypeId); if (resultContributionType != null) { resultContributionType.CategoryId = contributionType.CategoryId; resultContributionType.ContributionTypeName = contributionType.ContributionTypeName; resultContributionType.Description = contributionType.Description; db.SaveChanges(); returnResult.Success = true; returnResult.Data = resultContributionType; returnResult.StatusMessages.Add("Successfully updated contribution type."); } else { returnResult.Success = false; returnResult.StatusMessages.Add(string.Format("Unable to locate contribution type for id: {0}", contributionType.ContributionTypeId)); returnResult.Data = null; } } } catch (Exception e) { returnResult.Success = false; returnResult.StatusMessages.Add(e.Message); returnResult.Data = null; } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty contribution type posted for update."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public IActionResult Post([FromBody] ContributionType contributionType) { var returnResult = new ContributionTypeActionResult(false, new List <string>(), null); if (contributionType != null) { try { using (var db = new BTAContext()) { var resultContributionType = db.ContributionType.Add(contributionType); db.SaveChanges(); var entity = resultContributionType.Entity; if (entity != null) { returnResult.Success = true; returnResult.StatusMessages.Add("Successfully added contribution type."); returnResult.Data = entity; } } } catch (Exception e) { Logger.LogError(e, "An exception occurred while attempting to add a contribution type."); returnResult.Success = false; returnResult.StatusMessages.Add("An exception occurred while attempting to add a contribution type."); returnResult.Data = null; } } else { returnResult.Success = false; returnResult.StatusMessages.Add("Empty contribution type posted for add."); returnResult.Data = null; } return(StatusCode(StatusCodes.Status200OK, returnResult)); }
public IActionResult GetVM(int id) { IActionResult ret = null; Contributor entity = null; ContributorViewModel viewModel = null; try { using (var db = new BTAContext()) { entity = db.Contributor.SingleOrDefault(x => x.ContributorId == id); if (entity != null) { viewModel = new ContributorViewModel(entity); var entityAddress = db.Address.SingleOrDefault(x => x.AddressId == entity.AddressId); if (entityAddress != null) { viewModel.AddressText = string.Format("{0}, {1}, {2} {3}", entityAddress.AddressLine1, entityAddress.City, entityAddress.State, entityAddress.PostalCode); } ret = StatusCode(StatusCodes.Status200OK, viewModel); } else { ret = StatusCode(StatusCodes.Status404NotFound, "Can't Find Contributor: " + id.ToString()); } } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to retrieve a single Contributor."); } return(ret); }
public IActionResult GetVM() { IActionResult ret = null; List <ContributorViewModel> list = new List <ContributorViewModel>(); try { using (var db = new BTAContext()) { if (db.Contributor.Count() > 0) { list = (from cnt in db.Contributor join adr in db.Address on cnt.AddressId equals adr.AddressId into cntAdr from cntadr in cntAdr.DefaultIfEmpty() orderby cnt.LastName, cnt.FirstName, cnt.MiddleName select new ContributorViewModel() { ContributorId = cnt.ContributorId, FirstName = cnt.FirstName, MiddleName = cnt.MiddleName, LastName = cnt.LastName, AddressId = cnt.AddressId, AddressText = cntadr != null ? string.Format("{0}, {1}, {2} {3}", cntadr.AddressLine1, cntadr.City, cntadr.State, cntadr.PostalCode) : null }).ToList(); } ret = StatusCode(StatusCodes.Status200OK, list); } } catch (Exception ex) { ret = HandleException(ex, "Exception trying to get all Contributor"); } return(ret); }