public void AllTablesViewModel_GetNewLocation_Null_Parameter_Should_Pass() { // Arrange // Act var result = AllTablesViewModel.GetNewLocation(null); // Assert Assert.IsNull(result); }
/// <summary> /// /// Creates new Locations, Contacts, SpecialQualities, DailyHours. /// /// </summary> /// /// /// <param name="newLocation"> ViewModel with properties corresponding to the fields for each table </param> /// /// /// <returns> /// /// False: If newLocation is null or there was an error when attempting to insert /// True: It newLocation is successfully inserted into the Database /// /// </returns> public virtual bool Create(AllTablesViewModel newLocation) { if (newLocation == null) // Non-valid ViewModel Object { return(false); } // Ensures we don't end up with any duplicate LocationIds while (db.LocationIdNotUnique(newLocation.LocationId)) { newLocation.LocationId = Guid.NewGuid().ToString(); } Locations location = AllTablesViewModel.GetNewLocation(newLocation); Contacts contact = AllTablesViewModel.GetNewContact(newLocation); SpecialQualities specialQuality = AllTablesViewModel.GetNewSpecialQualities(newLocation); DailyHours dailyHours = AllTablesViewModel.GetNewDailyHours(newLocation); try { db.AlterRecordInfo(AlterRecordInfoEnum.Create, location); if (contact != null) { db.AlterRecordInfo(AlterRecordInfoEnum.Create, contact); } if (specialQuality != null) { db.AlterRecordInfo(AlterRecordInfoEnum.Create, specialQuality); } if (dailyHours != null) { db.AlterRecordInfo(AlterRecordInfoEnum.Create, dailyHours); } db.SaveChanges(); } catch (Exception) { return(false); } return(true); }
/// <summary> /// /// Updates the Location Record in the Database /// /// </summary> /// /// /// <param name="newLocation"> ViewModel Object containing the data for the fields of all the tables provided by the user </param> /// /// /// <returns> /// /// True: If successfully updates Location record in DB /// False: If newLocation is null, of if there was a Database Update error /// /// </returns> public virtual async Task <bool> EditPostAsync(AllTablesViewModel newLocation) { if (newLocation == null) { return(false); } // Get each table's Object Locations location = AllTablesViewModel.GetNewLocation(newLocation); location.Contact = AllTablesViewModel.GetNewContact(newLocation); location.SpecialQualities = AllTablesViewModel.GetNewSpecialQualities(newLocation); location.DailyHours = AllTablesViewModel.GetNewDailyHours(newLocation); bool result = false; // Value to be returned try { Locations response = await db.ReadOneRecordAsync(newLocation.LocationId).ConfigureAwait(true); if (response is null) // Location does not exist { return(false); } db._AddDeleteRow(response.Contact, location.Contact); db._AddDeleteRow(response.SpecialQualities, location.SpecialQualities); db._AddDeleteRow(response.DailyHours, location.DailyHours); response = location; result = db.AlterRecordInfo(AlterRecordInfoEnum.Update, response); return(result); } catch (Exception e) { errorMessage = e; return(false); } }