static void Main(string[] args) { /* ShowDatabase showDatabase = new ShowDatabase(); showDatabase.DeleteAll(); showDatabase.Create(new Show { Name = "Something other" }); var show = showDatabase.ReadAll().First(); show.Name = "not something other"; showDatabase.Update(show); using (var db = new DatabaseContext()) { //var query = from r in db.Shows select r; foreach (var item in showDatabase.ReadAll()) { Console.WriteLine($"{item.Name}, {item.ShowId}"); } Console.WriteLine("Done"); Console.ReadKey(); } */ var show = new Show { Name = "Does not create an error", ShowId = 0 }; var fasade = new ShowDatabase(); fasade.Create(show); }
public DTOReponseObject<Show> CreateShow(Show show) { if (ValidateForNullAndEmptyString(show)) //sussess { _repository.Create(show); return new DTOReponseObject<Show>(HttpStatusCode.Accepted, show, ""); } return new DTOReponseObject<Show>(HttpStatusCode.BadRequest, show, "A show must have all fields filled, with the exception of id"); }
public DTOReponseObject<Show> UpdateShow(Show updatedShow) { if (!ValidateForNullAndEmptyString(updatedShow)) { return new DTOReponseObject<Show>(HttpStatusCode.BadRequest, updatedShow, "A show must have all fields filled, even the id"); } try { _repository.Update(updatedShow); return new DTOReponseObject<Show>(HttpStatusCode.OK, null, ""); } catch(Exception e) { return new DTOReponseObject<Show>(HttpStatusCode.InternalServerError, updatedShow, $"{e.Message}"); } }
public bool ValidateForNullAndEmptyString(Show show) { if (show == null) return false; else if (show.Name == null || show.Name == "") return false; else if (show.ShowSummary == null || show.ShowSummary == "") return false; else if (show.ShowTrailer == null || show.ShowTrailer == "") return false; else if (show.TicketShow == null || show.TicketShow == "") return false; else if (show.CoverImage == null || show.CoverImage == "") return false; else return true; }