public bool SaveUnit(ProductionLineDTO lineDTO, long userId, long orgId) { ProductionLine line = new ProductionLine(); if (lineDTO.LineId == 0) { line.LineId = lineDTO.LineId; line.LineNumber = lineDTO.LineNumber; line.LineIncharge = lineDTO.LineIncharge; line.Remarks = lineDTO.Remarks; line.IsActive = lineDTO.IsActive; line.OrganizationId = orgId; line.EUserId = lineDTO.EUserId; line.EntryDate = DateTime.Now; productionLineRepository.Insert(line); } else { line = GetProductionLineOneByOrgId(lineDTO.LineId, orgId); line.LineNumber = lineDTO.LineNumber; line.LineIncharge = lineDTO.LineIncharge; line.Remarks = lineDTO.Remarks; line.IsActive = lineDTO.IsActive; line.OrganizationId = orgId; line.UpUserId = lineDTO.UpUserId; line.UpdateDate = DateTime.Now; productionLineRepository.Update(line); } return(productionLineRepository.Save()); }
public ActionResult <ProductionLineDTO> GetProductionLine(int id) { var q = _IProductionLineRepository.Select(id); ProductionLineDTO p = ProductionLineDTO.generateDto(q); return(Ok(p)); }
public async Task <ProductionLine> PostProductionLine(ProductionLineDTO productionLineDTO) { List <Machine> machines = ValidateMachines(productionLineDTO.Machines).Result; ProductionLine productionLine = new ProductionLine(new ProductionLineDescription(productionLineDTO.description), machines); await _productionLineRepository.Create(productionLine); return(productionLine); }
public ActionResult <ProductionLine> PostProductionLine(ProductionLineDTO DTO) { ProductionLine productionLine = new ProductionLine(DTO.Name); productionLine.Machines = DTO.Machines; _productionLineRepository.Add(productionLine); _productionLineRepository.SaveChanges(); return(CreatedAtAction(nameof(GetProductionLine), new { id = productionLine.Id }, productionLine)); }
public async Task UpdateProductionLine(Guid Id, ProductionLineDTO productionLineDTO) { ProductionLine productionLine = await GetProductionLineById(Id); List <Machine> machines = ValidateMachines(productionLineDTO.Machines).Result; //Machine machine = await _machineService.GetMachineById(machineGuid); productionLine.Description = new ProductionLineDescription(productionLineDTO.description); productionLine.Machines = machines; await _productionLineRepository.Update(Id, productionLine); }
public IEnumerable <ProductionLineDTO> GetAllProductionLine() { var q = _IProductionLineRepository.SelectAll().ToList(); List <ProductionLineDTO> list = new List <ProductionLineDTO>(); foreach (ProductionLine p in q) { ProductionLineDTO productionLine = ProductionLineDTO.generateDto(p); list.Add(productionLine); } return(list); }
public IActionResult PutProductionLine(int id, ProductionLineDTO DTO) { if (id != _productionLineRepository.GetBy(id).Id) { return(BadRequest()); } ProductionLine productionLine = new ProductionLine(DTO.Name); productionLine.Machines = DTO.Machines; _productionLineRepository.Update(productionLine); _productionLineRepository.SaveChanges(); return(NoContent()); }
public ActionResult <ProductionLineDTO> PostProductionLine(ProductionLineDTO productionLineDTO) { List <Machine> machines = new List <Machine>(); foreach (int item in productionLineDTO.machineList) { machines.Add(_IMachineRepository.Select(item)); } ProductionLine productionLine = new ProductionLine(machines); _IProductionLineRepository.Insert(productionLine); return(CreatedAtAction(nameof(GetAllProductionLine), new { id = productionLine.Id }, productionLine)); }
public async Task <ActionResult <ProductionLineDTO> > PostProductionLine([FromBody] ProductionLineDTO item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ProductionLine machine = await _serviceProductionLine.PostProductionLine(item); return(CreatedAtAction(nameof(PostProductionLine), machine.toDTO())); } catch (KeyNotFoundException ex) { return(NotFound(ex.Message)); } }
public ActionResult SaveProductionLine(ProductionLineViewModel productionLineViewModel) { bool isSuccess = false; if (ModelState.IsValid) { try { ProductionLineDTO dto = new ProductionLineDTO(); AutoMapper.Mapper.Map(productionLineViewModel, dto); isSuccess = _productionLineBusiness.SaveUnit(dto, UserId, OrgId); } catch (Exception ex) { isSuccess = false; } } return(Json(isSuccess)); }
public async Task <ActionResult <ProductionLineDTO> > UpdateProductionLine(Guid id, [FromBody] ProductionLineDTO item) { try { if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } await _serviceProductionLine.UpdateProductionLine(id, item); ProductionLine productionLine = await _serviceProductionLine.GetProductionLineById(id); return(productionLine.toDTO()); } catch (KeyNotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception exception) { return(BadRequest(exception.Message)); } }
public void EnsureProductionLineGetSetAndDTOWorks() { List <Operations> ops = new List <Operations>(); Operations op1 = new Operations { designation = new Designation { designation = "Op2" }, ToolDetails = new Details { Det = "teste2" }, Dur = new Duration { dur = 232 } }; Operations op2 = new Operations { designation = new Designation { designation = "Op2" }, ToolDetails = new Details { Det = "teste2" }, Dur = new Duration { dur = 232 } }; Operations op3 = new Operations { designation = new Designation { designation = "Op3" }, ToolDetails = new Details { Det = "teste233" }, Dur = new Duration { dur = 2323333 } }; ops.Add(op1); ops.Add(op2); ops.Add(op3); Machine machine1 = new Machine(new Designation("designation1"), new MachineType(new Designation("machineType1"), ops), new Model("model1"), new Location("factory1", "floor1", "section1"), new Position(1), new Capacity(1)); Machine machine2 = new Machine(new Designation("designation1"), new MachineType(new Designation("machineType1"), ops), new Model("model1"), new Location("factory1", "floor1", "section1"), new Position(1), new Capacity(1)); List <Machine> machines = new List <Machine>(); machines.Add(machine1); machines.Add(machine2); ProductionLine pl = new ProductionLine(machines); Assert.Equal(pl.machineList[0].designation, machine1.designation); Assert.Equal(pl.machineList[0].model, machine1.model); Assert.Equal(pl.machineList[0].location, machine1.location); Assert.Equal(pl.machineList[0].position, machine1.position); Assert.Equal(pl.machineList[0].capacity, machine1.capacity); List <int> list = new List <int>(); foreach (Machine item in machines) { list.Add(item.Id); } ProductionLineDTO pldto = new ProductionLineDTO(1, list); Assert.Equal(pl.machineList[0].Id, pldto.machineList[0]); }