public MinistryOwner DeleteMinistryOwner(int id) { MinistryOwner ministryOwner = db.MinistryOwner.Find(id); if (ministryOwner == null) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Delete", string.Empty, $"MinistryOwner {id} not found to delete."); return(null); } try { db.MinistryOwner.Remove(ministryOwner); db.SaveChanges(); _loggerService.CreateLog("Jordan", "MinistryOwner", "Delete", ministryOwner.ToString()); } catch (Exception e) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Delete", ministryOwner.ToString(), "Error deleting ministryOwner: " + e.Message); return(null); } return(ministryOwner); }
public MinistryOwner GetMinistryOwnerById(int id) { MinistryOwner ministryOwner = db.MinistryOwner.Find(id); _loggerService.CreateLog("Jordan", "MinistryOwner", "Get By Id", id.ToString(), $"Results found: {ministryOwner != null}"); return(ministryOwner); }
public IHttpActionResult GetById(int id) { _loggerService.CreateLog(_user, "API", "MinistryOwnerController", "MinistryOwner", "Get By Id", id.ToString(), null); MinistryOwner ministryOwner = _ministryOwnerRepository.GetMinistryOwnerById(id); if (ministryOwner == null) { return(NotFound()); } return(Ok(ministryOwner)); }
public MinistryOwner InsertMinistryOwner(MinistryOwner ministryOwner) { try { ministryOwner.CreatedDateTime = DateTime.Now; db.MinistryOwner.Add(ministryOwner); db.SaveChanges(); _loggerService.CreateLog("Jordan", "MinistryOwner", "Create", ministryOwner.ToString()); return(ministryOwner); } catch (Exception e) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Create", ministryOwner.ToString(), "Error creating this record: " + e.Message); return(null); } }
public IHttpActionResult Insert(MinistryOwner ministryOwner) { _loggerService.CreateLog(_user, "API", "MinistryOwnerController", "MinistryOwner", "Insert", ministryOwner.ToString(), null); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdMinistryOwner = _ministryOwnerRepository.InsertMinistryOwner(ministryOwner); if (createdMinistryOwner == null) { BadRequest("There was a problem inserting your record. Please try again."); } return(Created($"api/ministryOwner?id={createdMinistryOwner.Id}", createdMinistryOwner)); }
public MinistryOwner UpdateMinistryOwner(MinistryOwner updatedMinistryOwner) { var currentMinistryOwner = db.MinistryOwner.Find(updatedMinistryOwner.Id); if (currentMinistryOwner == null) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Update", string.Empty, $"MinistryOwner {updatedMinistryOwner.Id} not found to update."); return(null); } if (updatedMinistryOwner.Name != null) { currentMinistryOwner.Name = updatedMinistryOwner.Name; } currentMinistryOwner.Archived = updatedMinistryOwner.Archived; currentMinistryOwner.ModifiedDateTime = DateTime.Now; db.Entry(currentMinistryOwner).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException e) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Update", currentMinistryOwner.ToString(), "Error updating ministryOwner: " + e.Message); return(null); } catch (Exception e) { _loggerService.CreateLog("Jordan", "MinistryOwner", "Update", currentMinistryOwner.ToString(), "Error updating ministryOwner: " + e.Message); return(null); } _loggerService.CreateLog("Jordan", "MinistryOwner", "Update", currentMinistryOwner.ToString()); return(currentMinistryOwner); }
public IHttpActionResult Update(int id, [FromBody] MinistryOwner ministryOwner) { _loggerService.CreateLog(_user, "API", "MinistryOwnerController", "MinistryOwner", "Update", ministryOwner.ToString(), null); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ministryOwner.Id) { return(BadRequest("The Id's do not match")); } var updatedMinistryOwner = _ministryOwnerRepository.UpdateMinistryOwner(ministryOwner); if (updatedMinistryOwner == null) { return(BadRequest("There was a problem updating your record. Please try again")); } return(Ok($"api/ministryowner?id={ministryOwner.Id}")); }
public MinistryOwnerController() { MinistryOwner[] ministryOwners = new MinistryOwner[] { new MinistryOwner { MinistryOwnerId = 1, MinistryOwnerName = "Brian Pikalow", CreatedDateTime = DateTime.Today, ModifiedDateTIme = DateTime.Today.AddDays(1), Archived = false }, new MinistryOwner { MinistryOwnerId = 2, MinistryOwnerName = "John Parrot", CreatedDateTime = DateTime.Today, ModifiedDateTIme = DateTime.Today.AddDays(1), Archived = false }, new MinistryOwner { MinistryOwnerId = 3, MinistryOwnerName = "Brian Quigley", CreatedDateTime = DateTime.Today, ModifiedDateTIme = DateTime.Today.AddDays(1), Archived = false }, new MinistryOwner { MinistryOwnerId = 4, MinistryOwnerName = "Don Cousins", CreatedDateTime = DateTime.Today, ModifiedDateTIme = DateTime.Today.AddDays(1), Archived = false }, new MinistryOwner { MinistryOwnerId = 5, MinistryOwnerName = "Rocky Barra", CreatedDateTime = DateTime.Today, ModifiedDateTIme = DateTime.Today.AddDays(1), Archived = false } }; _ministryOwners = ministryOwners; }