public async Task <IActionResult> PutAlloy(int id, Alloy alloy) { if (id != alloy.Id) { return(BadRequest()); } if (await _service.GetEntity(id) == null) { await _service.InsertEntity(alloy); } else { await _service.UpdateEntity(alloy); } return(NoContent()); }
public async Task <Alloy> CreateAlloyAsync(IEnumerable <KeyValuePair <string, double> > elements) { StringBuilder compositionInfo = new StringBuilder(); foreach (var element in elements .OrderByDescending(kvp => kvp.Value) .ThenByDescending(kvp => kvp.Key)) { compositionInfo.Append(element.Key); compositionInfo.Append($"{element.Value:F1}"); } string composition = compositionInfo.ToString().Trim(); if (dbContext.Alloys.Any(a => a.Composition == composition)) { throw new DuplicateObjectException(typeof(Alloy), composition); } var alloy = new Alloy(composition); await dbContext.Alloys.AddAsync(alloy); dbContext.SaveChanges(); return(alloy); }
public async Task <ActionResult <Alloy> > PostAlloy(Alloy alloy) { await _service.InsertEntity(alloy); return(CreatedAtAction("GetAlloy", new { id = alloy.Id }, alloy)); }
public static Alloy CreateAlloy(int alloyID) { Alloy alloy = new Alloy(); alloy.AlloyID = alloyID; return alloy; }
public void AddToAlloy(Alloy alloy) { base.AddObject("Alloy", alloy); }