public HttpResponseMessage CreateFullInterestGroup(InterestGroupModel interestGroupModel) { if (interestGroupModel.Name == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Interest group could not be created, missing name"); } interestGroupModel.Id = DatabaseInteractor.GetHighestInterestGroupId() + 1; // Add manager to members if (interestGroupModel.Members.Count == 0) { interestGroupModel.Members.Add(interestGroupModel.Manager); } DatabaseInteractionResponse result = DatabaseInteractor.CreateInterestGroup(interestGroupModel); if (result.Success) { return Request.CreateResponse(HttpStatusCode.OK, interestGroupModel); } return Request.CreateResponse(HttpStatusCode.BadRequest, "Interest group could not be created. The following error occurred: " + result.Message); }
public static DatabaseInteractionResponse UpdateInterestGroup(InterestGroupModel interestGroupModel) { DatabaseInteractionResponse deleteResponse = DeleteInterestGroup(interestGroupModel.Id); return deleteResponse.Success ? CreateInterestGroup(interestGroupModel) : deleteResponse; }
public static DatabaseInteractionResponse CreateInterestGroup(InterestGroupModel interestGroupModel) { // Check if userId is currently being used if (GetInterestGroupById(interestGroupModel.Id) != null) { return new DatabaseInteractionResponse() { Success = false, Message = "There already exists an interest group with the id: " + interestGroupModel.Id }; } List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@interestGroupId", interestGroupModel.Id), new SqlParameter("@name", interestGroupModel.Name), new SqlParameter("@description", interestGroupModel.Description), new SqlParameter("@managerId", interestGroupModel.Manager.Id), new SqlParameter("@imageUrl", interestGroupModel.ImageUrl) }; DatabaseInteractionResponse interestGroupResponse = ExecuteSqlNonQuery("CreateInterestGroup", parameters); if (interestGroupResponse.Success) { foreach (UserModel user in interestGroupModel.Members) { DatabaseInteractionResponse userResponse = AddUserToInterestGroup(interestGroupModel.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 interestGroupResponse; }