public async Task <ActionResult <Container> > PostContainer(ContainerPostModel container) { var model = new Container { Code = container.Code, Description = container.Description, SectorId = container.SectorId, Type = container.Type, Volume = container.Volume }; _repo.Add(model); await _repo.SaveChangesAsync(); return(Ok(container)); }
public async Task <IActionResult> Post([FromBody] Container container) { try { _container.Add(container); if (await _container.SaveChangesAsync()) { return(Created($"/api/container/{container.Id}", container)); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou")); } return(BadRequest()); }
public async Task <IActionResult> Post(ContainerRequest containerRequest) { try { var container = new Container( name: containerRequest.Name, description: containerRequest.Description, serialNumber: containerRequest.SerialNumber, itemCount: containerRequest.ItemCount, boxCount: containerRequest.BoxCount, placement: containerRequest.Placement, expirationDate: containerRequest.ExpirationDate, manufacturingDate: containerRequest.ManufacturingDate, dateCreated: DateTime.Now); var containerEntity = new ContainerEntity() { Id = container.Id, Name = container.Name, Description = container.Description, SerialNumber = container.SerialNumber, ItemCount = container.ItemCount, BoxCount = container.BoxCount, Placement = container.Placement, ExpirationDate = container.ExpirationDate, ManufacturingDate = container.ManufacturingDate, DateCreated = container.DateCreated }; await _containerRepository.Add(containerEntity); await _context.SaveChangesAsync(); return(new OkResult()); } catch (Exception exception) { return(new BadRequestObjectResult(exception.Message.ToString())); } }
public ResponseStatus CreateOrder(OrderViewModel order) { var isDuplicatedOrder = false; var mOrder = Mapper.Map <OrderViewModel, Order_H>(order); var newestOrderObj = GetOrderEntryId(order.OrderD); var newestOrderNo = Convert.ToString(newestOrderObj.GetType().GetProperty("newOrderNo").GetValue(newestOrderObj, null)); if (newestOrderNo != order.OrderNo) { isDuplicatedOrder = true; mOrder.OrderNo = newestOrderNo; } _orderRepository.Add(mOrder); if (order.Containers != null && order.Containers.Count != 0) { var baseConNo = GetContainerDetailNo(mOrder.OrderD, mOrder.OrderNo); foreach (var container in order.Containers) { var con = Mapper.Map <ContainerViewModel, Order_D>(container); if (String.IsNullOrEmpty(con.ContainerTypeC)) { return(new ResponseStatus() { Successful = false, Message = "" }); } else { con.OrderD = order.OrderD; con.OrderNo = mOrder.OrderNo; con.DetailNo = baseConNo++; con.LocationDispatch1 = mOrder.LoadingPlaceN; con.LocationDispatch2 = mOrder.StopoverPlaceN; con.LocationDispatch3 = mOrder.DischargePlaceN; con.ContainerNo = con.ContainerNo.ToUpper(); con.ContainerSizeI = String.IsNullOrEmpty(con.ContainerSizeI) ? "" : con.ContainerSizeI; con.ContainerTypeC = String.IsNullOrEmpty(con.ContainerTypeC) ? "" : con.ContainerTypeC; con.UnitPrice = con.UnitPrice ?? 0; _containerRepository.Add(con); } } } SaveOrder(); if (isDuplicatedOrder) { return(new ResponseStatus() { Successful = true, Message = "duplicated", NewestOrderNo = newestOrderNo }); } return(new ResponseStatus() { Successful = true, Message = "" }); }