public void EnsureManufacturingPlanGetSetWorks() { //Arrange OperationsMDP opmdp = new OperationsMDP("Tool", "name", 30, 1); DateTime dt = new DateTime(); List <OperationsMDP> lista = new List <OperationsMDP>(); lista.Add(opmdp); List <OperationsMDP> lista2 = new List <OperationsMDP>(); lista2.Add(opmdp); ManufacturingPlan mp = new ManufacturingPlan(dt, lista); //Assert Assert.Equal("Tool", mp.Operations[0].ToolDesc); Assert.Equal("name", mp.Operations[0].Name); Assert.Equal(30, mp.Operations[0].Duration); Assert.Equal(1, mp.Operations[0].operationTypeId); Assert.Equal(lista2, mp.Operations); }
public ActionResult PutProduct(ProductsDTO productDTO) { ManufacturingPlan manufacturing = _IManufacturingPlanRepository.Select(productDTO.ManufacturingPlanId); Product product = new Product(new Name(productDTO.Name), manufacturing); return(Ok(_IProductRepository.Update(product))); }
public void EnsureProductGetSetWorks() { //Arrange Name na = new Name("Teste1"); OperationsMDP opmdp = new OperationsMDP("Tool", "name", 30, 1); DateTime dt = new DateTime(); List <OperationsMDP> lista = new List <OperationsMDP>(); lista.Add(opmdp); List <OperationsMDP> lista2 = new List <OperationsMDP>(); lista2.Add(opmdp); ManufacturingPlan mp = new ManufacturingPlan(dt, lista); ManufacturingPlan mp2 = new ManufacturingPlan(dt, lista); var mockito = new Mock <Product>(); Product p = new Product(na, mp); //Assert Assert.Equal("Teste1", p.Name.name); Assert.Equal("Tool", p.ManufacturingPlan.Operations[0].ToolDesc); Assert.Equal("name", p.ManufacturingPlan.Operations[0].Name); Assert.Equal(30, p.ManufacturingPlan.Operations[0].Duration); Assert.Equal(1, p.ManufacturingPlan.Operations[0].operationTypeId); Assert.Equal(lista2, p.ManufacturingPlan.Operations); //Assert.Equal(mp2, p.ManufacturingPlan); }
public async Task <ActionResult <ProductDTO> > PostProduct([FromBody] ProductDTO dto) { try { //Create Manufacturing plan ManufacturingPlan manufacturingPlan = _serviceProduct.CreateManufacturingPlan(dto.Plan.Operations); //Create Product Product product = new Product(new Ref(dto.Ref), manufacturingPlan); //Create Product var productResponse = await _serviceProduct.PostProduct(product); return(CreatedAtAction("PostProduct", productResponse.ToDto())); } catch (KeyNotFoundException e) { return(NotFound(e.Message)); } catch (FormatException e) { return(BadRequest(e.Message)); } catch (WebException e) { Console.Write(e.StackTrace); return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public async Task <ManufacturingPlan> Update(ManufacturingPlan entity) { _context.Update(entity); await _context.SaveChangesAsync(); return(entity); }
public async Task <ManufacturingPlan> Create(ManufacturingPlan entity) { await _context.Set <ManufacturingPlan>().AddAsync(entity); await _context.SaveChangesAsync(); return(entity); }
public ActionResult <ProductsDTO> PostProduct(ProductsDTO productDTO) { ManufacturingPlan manufacturing = _IManufacturingPlanRepository.Select(productDTO.ManufacturingPlanId); Product product = new Product(new Name(productDTO.Name), manufacturing); _IProductRepository.Insert(product); return(CreatedAtAction(nameof(GetProduct), new { id = product.Id }, product)); }
// IN DTO ===> OBJECT //======================================================================== public static Product InDtoToProduct(InProductDTO productDto, ManufacturingPlan manufacturingPlan) { return(new Product { ProductName = productDto.Name, ProductDescription = productDto.Description, ProductPrice = productDto.Price, ManufacturingPlan = manufacturingPlan }); }
public ActionResult PutManufacturingPlan(ManufacturingPlanDTO manufacturingPlanDTO) { List <OperationsMDP> list = new List <OperationsMDP>(); foreach (int item in manufacturingPlanDTO.Operactions) { list.Add(_IOperationRepository.Select(item)); } ManufacturingPlan manufacturing = new ManufacturingPlan(manufacturingPlanDTO.Date, list); return(Ok(_IManufacturingPlanRepository.Update(manufacturing))); }
public ActionResult PostManufacturingPlan(ManufacturingPlanDTO manufacturingPlanDTO) { List <OperationsMDP> list = new List <OperationsMDP>(); foreach (int item in manufacturingPlanDTO.Operactions) { list.Add(_IOperationRepository.Select(item)); } ManufacturingPlan manufacturingPlan = new ManufacturingPlan(manufacturingPlanDTO.Date, list); _IManufacturingPlanRepository.Insert(manufacturingPlan); return(CreatedAtAction(nameof(GetManufacturingPlan), new { id = manufacturingPlan.Id }, manufacturingPlan)); }
// OBJECT ===> OUT DTO //======================================================================== public static OutManufacturingPlanDTO ManufacturingPlanToOutDto(ManufacturingPlan manufacturingPlan) { List <int> lstOpsOutIds = new List <int>(); foreach (var id in manufacturingPlan.LstOperations) { lstOpsOutIds.Add(id.OperationId); } return(new OutManufacturingPlanDTO { Id = manufacturingPlan.Id, Name = manufacturingPlan.Name, Description = manufacturingPlan.Description, operations = lstOpsOutIds }); }
// OBJECT ===> IN DTO //======================================================================== public static InManufacturingPlanDTO ManufacturingPlanToInDto(ManufacturingPlan manufacturingPlan) { var mpDto = new InManufacturingPlanDTO { Name = manufacturingPlan.Name, Description = manufacturingPlan.Description, operations = new List <int>() }; foreach (var opid in manufacturingPlan.LstOperations.ToList() .Where(mp => mp.ManufacturingPlanId == manufacturingPlan.Id)) { mpDto.operations.Add(opid.OperationId); } return(mpDto); }
public ManufacturingPlan CreateManufacturingPlan(ICollection <OperationIdDTO> idsCollection) { ManufacturingPlan manufacturingPlan = new ManufacturingPlan(); foreach (var opIdDTO in idsCollection) { Guid guid; if (!Guid.TryParse(opIdDTO.Id, out guid)) { throw new FormatException("Invalid Guid format."); } WebRequest request = WebRequest.Create("https://masterdatafactory.azurewebsites.net/api/operation/exists/" + opIdDTO.Id); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8); if (response.StatusDescription != "OK") { throw new WebException("Can't find api request URL"); } bool exists; using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { exists = Boolean.Parse(reader.ReadToEnd()); } response.Close(); if (!exists) { throw new KeyNotFoundException("Operation does not exists"); } if (!manufacturingPlan.Ids.Contains(new OperationId(opIdDTO.Id))) { manufacturingPlan.AddOperationId(opIdDTO.Id); } } return(manufacturingPlan); }
// IN DTO ===> OBJECT //======================================================================== public static ManufacturingPlan InDtoToManufacturingPlan(InManufacturingPlanDTO manufacturingPlanDto) { List <OperationManufacturingPlan> lstOperations = new List <OperationManufacturingPlan>(); var newMp = new ManufacturingPlan { Name = manufacturingPlanDto.Name, Description = manufacturingPlanDto.Description, LstOperations = lstOperations }; foreach (var opId in manufacturingPlanDto.operations) { newMp.LstOperations.Add(new OperationManufacturingPlan() { OperationId = opId }); } return(newMp); }
public bool Update(ManufacturingPlan manufacturingPlan) { _context.Entry(manufacturingPlan).State = EntityState.Modified; try { _context.SaveChanges(); return(true); } catch (DbUpdateConcurrencyException) { if (manufacturingPlan.Id.Equals(-1)) { throw new Exception("No ManufacturingPlan with that id"); } else { throw; } } }
public static ManufacturingPlanDTO generateDto(ManufacturingPlan manufacturingPlan) { List <int> Operactions = new List <int>(); ManufacturingPlanDTO m = new ManufacturingPlanDTO(); if (manufacturingPlan.Id != -1) { m.ManufacturingPlanId = manufacturingPlan.Id; } if (manufacturingPlan.Date != null) { m.Date = manufacturingPlan.Date; } if (manufacturingPlan.Operations != null) { foreach (OperationsMDP i in manufacturingPlan.Operations) { Operactions.Add(i.Id); } m.Operactions = Operactions; } return(m); }
public bool Insert(ManufacturingPlan manufacturingPlan) { _context.ManufacturingPlans.Add(manufacturingPlan); _context.SaveChanges(); return(true); }
public async Task Delete(ManufacturingPlan entity) { _context.Remove(entity); await _context.SaveChangesAsync(); }
public void Add(ManufacturingPlan product) { _manuFacturingPlans.Add(product); }
public void Delete(ManufacturingPlan product) { _manuFacturingPlans.Remove(product); }
public void Update(ManufacturingPlan product) { _context.Update(product); }