public HttpResponseMessage CreateFullEvent(EventModel eventModel) { if (eventModel.Name == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Event could not be created, missing name"); } eventModel.Id = DatabaseInteractor.GetHighestEventId() + 1; DatabaseInteractionResponse result = DatabaseInteractor.CreateEvent(eventModel); if (result.Success) { return Request.CreateResponse(HttpStatusCode.OK, eventModel); } return Request.CreateResponse(HttpStatusCode.BadRequest, "Event could not be created. The following error occurred: " + result.Message); }
public static DatabaseInteractionResponse CreateEvent(EventModel eventModel) { // Check if eventId is currently being used if (GetEventById(eventModel.Id) != null) { return new DatabaseInteractionResponse() { Success = false, Message = "There already exists an event with the id: " + eventModel.Id }; } List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@eventId", eventModel.Id), new SqlParameter("@name", eventModel.Name), new SqlParameter("@description", eventModel.Description), new SqlParameter("@time", eventModel.Time), new SqlParameter("@imageUrl", eventModel.ImageUrl), new SqlParameter("@location", eventModel.Location), new SqlParameter("@interestGroupId", eventModel.InterestGroup.Id) }; DatabaseInteractionResponse eventResponse = ExecuteSqlNonQuery("CreateEvent", parameters); if (eventResponse.Success) { foreach (UserModel user in eventModel.Attendees) { DatabaseInteractionResponse userResponse = AddUserToEvent(eventModel.Id, user.Id); // TODO: This is a really bad failure. Log on critical or undo everything if (!userResponse.Success) { return userResponse; } } return new DatabaseInteractionResponse() { Success = true }; } return eventResponse; }
public static DatabaseInteractionResponse UpdateEvent(EventModel eventModel) { DatabaseInteractionResponse deleteResponse = DeleteEvent(eventModel.Id); return deleteResponse.Success ? CreateEvent(eventModel) : deleteResponse; }