Exemplo n.º 1
0
        public FinishedProduct FinishedProductForUpdate(UpdatedFinishedProductDto updated)
        {
            FinishedProduct current = new FinishedProduct();

            current.OrderId     = updated.orderId;
            current.SubmittedBy = updated.submitedBy;
            current.RecievedBy  = updated.recievedBy;
            current.Quantity    = updated.quantity;
            return(current);
        }
Exemplo n.º 2
0
        public IActionResult UpdateFinishedProductRecord(uint id, [FromBody] UpdatedFinishedProductDto updatedData)
        {
            try {
                if (updatedData == null)
                {
                    return(StatusCode(400));
                }

                if (!ModelState.IsValid)
                {
                    return(new InvalidInputResponse(ModelState));
                }

                id = (id == 0) ? (uint)updatedData.id : id;

                var finishedProduct = _query.GetFinishedProductById(id);

                if (finishedProduct == null)
                {
                    return(StatusCode(404, $"Product with id: {id} Not Found : "));
                }

                var submittedBy = _employeesQuery.GetEmployeeById(updatedData.submitedBy);
                var recievedBy  = _employeesQuery.GetEmployeeById(updatedData.recievedBy);

                if (submittedBy == null || recievedBy == null)
                {
                    return(StatusCode(404, "Employee Not Found"));
                }

                var order = _productionOrderQuery.GetWorkOrderItemById(updatedData.orderId);

                if (order == null)
                {
                    return(StatusCode(404, "Order Not Found"));
                }

                var updatedFinishedProduct = _factory.FinishedProductForUpdate(updatedData);

                if (_command.UpdateFinishedProduct(updatedFinishedProduct))
                {
                    return(StatusCode(204));
                }
                else
                {
                    return(StatusCode(500, "Unkown Error Occured while processing Request, Try Again"));
                }
            } catch (Exception e) {
                _logger.LogError(500, e.Message, e);

                return(StatusCode(500, e));
            }
        }