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 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 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 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 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 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 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 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)); }