public async Task <ActionResult> UpdateProcess(int id, ManufacturingProcessForUpdateDto process) { if (!Enum.IsDefined(typeof(ManufacturingProcessStatus), process.Status)) { return(BadRequest("Status doesn't exist")); } try { ManufacturingProcess result = await dbContext.ManufacturingProcesses.Where(mp => mp.Id == id).FirstOrDefaultAsync(); if (result == null) { return(NotFound($"Process with Id: {id} not found")); } ManufacturingProcess processEntity = mapper.Map <ManufacturingProcess>(process); processEntity.Id = id; dbContext.Entry(result).State = EntityState.Detached; dbContext.ManufacturingProcesses.Update(processEntity); await dbContext.SaveChangesAsync(); return(Ok(new Response <ManufacturingProcessDto>(mapper.Map <ManufacturingProcessDto>(processEntity)))); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> CreateProcess(ManufacturingProcessForCreationDto process) { try { ManufacturingProcess processEntity = mapper.Map <ManufacturingProcess>(process); dbContext.ManufacturingProcesses.Add(processEntity); await dbContext.SaveChangesAsync(); ManufacturingProcessDto processToReturn = mapper.Map <ManufacturingProcessDto>(processEntity); return(CreatedAtAction(nameof(GetProcess), new { id = processToReturn.Id }, processToReturn)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> GetProcess(int id) { try { ManufacturingProcess process = await dbContext.ManufacturingProcesses.FindAsync(id); if (process == null) { return(NotFound()); } return(Ok(new Response <ManufacturingProcessDto>(mapper.Map <ManufacturingProcessDto>(process)))); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }