public void SaveLocationFurnituring(LocationFurnituring LocationFurnituring) { // Preparare validation return data ICollection<ValidationResult> validationResults; // Try to validate given data if (LocationFurnituring.Validate(out validationResults)) { // Check that the LocationFurnituring exists LocationFurnituring LocationFurnituringCheck = LocationFurnituringDAL.GetLocationFurnituringById(LocationFurnituring.LocationId, LocationFurnituring.FurnituringId); // If a new LocationFurnituring should be created if (LocationFurnituringCheck == null) { LocationFurnituringDAL.InsertLocationFurnituring(LocationFurnituring); } // Existing LocationFurnituring should be updated else { // Update LocationFurnituring LocationFurnituringDAL.UpdateLocationFurnituring(LocationFurnituring); } } // Validation failed else { // Create exception ApplicationException exception = new ApplicationException("LocationFurnituring object contained invalid values."); // Add validation data to exception. exception.Data.Add("ValidationResults", validationResults); throw exception; } }
public IHttpActionResult Post(LocationFurnituring locationFurnituring) { // Check for bad values, done by the data annotations in the model class. if (!ModelState.IsValid) { return BadRequest(ModelState); } // Try to save locationFurnituring try { locationFurnituringService.SaveLocationFurnituring(locationFurnituring); } catch (DataBaseEntryNotFoundException) { return NotFound(); } catch (DuplicateNameException) { return Conflict(); } catch (ApprovedException exception) { return BadRequest(exception.Message); } catch { return InternalServerError(); } // Respond that the booking was created and redirect return Ok(locationFurnituring); //CreatedAtRoute("DefaultApi", new { id = locationFurnituring.LocationFurnituringId }, locationFurnituring); }
// Methods public void LocationFurnituringDelete(LocationFurnituring LocationFurnituring) { LocationFurnituringDelete(LocationFurnituring.LocationId, LocationFurnituring.FurnituringId); }
public void SaveLocationFurniturings(LocationFurnituring[] LocationFurniturings) { foreach (LocationFurnituring LocationFurnituring in LocationFurniturings) { this.SaveLocationFurnituring(LocationFurnituring); } }
public void UpdateLocationFurnituring(LocationFurnituring LocationFurnituring) { // Create connection object using (this.CreateConnection()) { try { SqlCommand cmd; // Connect to database cmd = this.Setup("appSchema.usp_LocationFurnituringUpdate", DALOptions.closedConnection); // Add in parameters for Stored procedure cmd.Parameters.Add("@LocationId", SqlDbType.Int).Value = LocationFurnituring.LocationId; cmd.Parameters.Add("@FurnituringId", SqlDbType.SmallInt).Value = LocationFurnituring.FurnituringId; cmd.Parameters.Add("@MaxPeople", SqlDbType.Int).Value = LocationFurnituring.MaxPeople; // Open DB connection connection.Open(); // Execute insert to database cmd.ExecuteNonQuery(); } catch (Exception) { // Throw exception throw new ApplicationException(DAL_ERROR_MSG); } } }