public void TestCustomBatchPropValues() { // Prerequisite entities Plastic pp = PlasticsRepository.CreatePlastic("PP", "Polypropylene"); Material mat = MaterialsRepository.CreateMaterial("mat", "manu", "manu-id", pp); StorageSite site = LocationsRepository.CreateStorageSite("test_site"); StorageArea area = LocationsRepository.CreateStorageArea(site, "test_area"); StorageLocation loc = new StorageLocation() { StorageSiteId = site.Id, StorageAreaId = area.Id, StorageSiteName = site.Name, StorageAreaName = area.Name }; CustomBatchProp prop1 = PropRepository.CreateCustomBatchProp("prop-1"); CustomBatchProp prop2 = PropRepository.CreateCustomBatchProp("prop-2"); // Create batch with custom prop values MaterialBatch batch = Repository.CreateMaterialBatch(mat, DateTime.Today.AddDays(17), loc, 42, 42, new Dictionary <Guid, string>() { { prop1.Id, "Ak Bars" }, { prop2.Id, "Aloha" } }, false); Assert.Equal(2, batch.CustomProps.Count); // Test updating batch.CustomProps[prop1.Id] = "UPDATE TEST"; Repository.UpdateMaterialBatch(batch); batch = Repository.GetMaterialBatch(batch.Id); Assert.Equal(2, batch.CustomProps.Count); Assert.Single(batch.CustomProps.Where(p => p.Value == "UPDATE TEST")); }
public void TestCustomBatchPropRepository() { Assert.Empty(Repository.GetAllCustomBatchProps()); // Create Repository.CreateCustomBatchProp("test_prop"); Repository.CreateCustomBatchProp("Super Prop"); // Check IEnumerable <CustomBatchProp> props = Repository.GetAllCustomBatchProps(); Assert.Equal(2, props.Count()); Assert.Single(props.Where(p => p.Name == "test_prop")); Assert.Single(props.Where(p => p.Name == "Super Prop")); // Update CustomBatchProp prop = props.First(p => p.Name == "test_prop"); prop.Name = "Aloha Prop"; Repository.UpdateCustomBatchProp(prop); prop = Repository.GetCustomBatchProp(prop.Id); Assert.Equal("Aloha Prop", prop.Name); // Delete Repository.DeleteCustomBatchProp(prop.Id); props = Repository.GetAllCustomBatchProps(); Assert.Single(props); Assert.Equal("Super Prop", props.Single().Name); }
/// <summary> /// Updates a custom batch property. /// </summary> /// <param name="prop">Prop to update.</param> /// <exception cref="NotImplementedException"></exception> public void UpdateCustomBatchProp(CustomBatchProp prop) { using (IDbConnection connection = GetNewConnection()) { connection.Execute("UPDATE batch_props SET name=@Name WHERE id=@id", new { prop.Id, prop.Name }); } }
/// <summary> /// Updates a custom batch property. /// </summary> /// <param name="name">The new name to set.</param> /// <returns>Returns the updated prop.</returns> /// <exception cref="CustomPropNotFoundException">Thrown if no matching prop could be found.</exception> public CustomBatchProp UpdateCustomBatchProp(Guid id, string name) { CustomBatchProp prop = GetCustomBatchPropOrThrowNotFoundException(id); prop.Name = name; PropRepository.UpdateCustomBatchProp(prop); return(prop); }
/// <summary> /// Gets a custom batch property. /// </summary> /// <param name="id">The property's ID.</param> /// <returns> /// Returns the property or null. /// </returns> /// <exception cref="NotImplementedException"></exception> public CustomBatchProp GetCustomBatchProp(Guid id) { CustomBatchProp prop = null; using (IDbConnection connection = GetNewConnection()) { prop = connection.QuerySingleOrDefault <CustomBatchProp>("SELECT * FROM batch_props WHERE id=@Id", new { id }); } return(prop); }
public CustomBatchProp CreateCustomBatchProp(string name) { CustomBatchProp prop = new CustomBatchProp() { Id = Guid.NewGuid(), Name = name }; Props.Add(prop.Id, prop); return(prop); }
/// <summary> /// Attempts to get a batch prop from the underlying repository and throws a <see cref="CustomPropNotFoundException"/> if no matching prop could be found. /// </summary> /// <param name="id">ID of the prop to get.</param> /// <exception cref="CustomPropNotFoundException">Thrown if no matching prop could be found.</exception> /// <returns>Returns the prop, if found.</returns> private CustomBatchProp GetCustomBatchPropOrThrowNotFoundException(Guid id) { CustomBatchProp prop = PropRepository.GetCustomBatchProp(id); // Check for prop existence if (prop == null) { throw new CustomPropNotFoundException(id); } return(prop); }
/// <summary> /// Creates a custom batch property. /// </summary> /// <param name="name">The property's name.</param> /// <returns> /// Returns the newly created prop. /// </returns> /// <exception cref="NotImplementedException"></exception> public CustomBatchProp CreateCustomBatchProp(string name) { Guid id = Guid.NewGuid(); CustomBatchProp prop = null; using (IDbConnection connection = GetNewConnection()) { connection.Execute("INSERT INTO batch_props (id, name) VALUES (@Id, @Name)", new { id, name }); prop = connection.QuerySingle <CustomBatchProp>("SELECT * FROM batch_props WHERE id=@Id", new { id }); } return(prop); }
public IActionResult CreateCustomBatchProp([FromBody] CustomBatchPropCreationRequest customBatchPropCreationRequest) { if (customBatchPropCreationRequest == null || string.IsNullOrWhiteSpace(customBatchPropCreationRequest.Name)) { return(HandleBadRequest("Missing prop data: a name and type are required.")); } try { CustomBatchProp prop = CustomBatchPropService.CreateCustomBatchProp(customBatchPropCreationRequest.Name); return(Created(GetNewResourceUri(prop.Id), prop)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public IActionResult UpdateCustomBatchProp(Guid id, [FromBody] CustomBatchPropUpdateRequest customBatchPropUpdateRequest) { if (customBatchPropUpdateRequest == null || string.IsNullOrWhiteSpace(customBatchPropUpdateRequest.Name)) { return(HandleBadRequest("A valid prop name needs tu be supplied.")); } try { CustomBatchProp prop = CustomBatchPropService.UpdateCustomBatchProp(id, customBatchPropUpdateRequest.Name); return(Ok(prop)); } catch (CustomPropNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public void UpdateCustomBatchProp(CustomBatchProp prop) { Props[prop.Id] = prop; }