Exemplo n.º 1
0
        public StorageExport Create(StorageExport request)
        {
            var storageExport = _repository.Add(request);

            _repository.Save();

            return(storageExport);
        }
Exemplo n.º 2
0
        public IActionResult Create([FromBody] StorageExport request)
        {
            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Storage Export was successfull created!"
            };

            try
            {
                request.SetAudit(CurrentLoggedUserId);
                var storageExport = _storageExportService.Create(request);
                actionResult.EntityId = storageExport.Id;
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create storage export was unsuccessfully, please try again!";

                return(Ok(actionResult));
            }

            try
            {
                var product = _productService.GetById(request.ProductId);
                product.StorageQuantity -= request.Quantity;
                _productService.Update(product);
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create storage export was successfully, but Storage Quantity of the product was not updated properly, please contact Office worker!";

                return(Ok(actionResult));
            }

            var fieldWorkerProducts = _fieldWorkerProductService.GetByCriteria(new FieldWorkerProductSearchRequest
            {
                FieldWorkerId = request.FieldWorkerId,
                ProductId     = request.ProductId
            });

            try
            {
                if (fieldWorkerProducts.Count() == 0)
                {
                    var fieldWorkerProduct = new FieldWorkerProduct
                    {
                        FieldWorkerId = request.FieldWorkerId,
                        ProductId     = request.ProductId,
                        Quantity      = request.Quantity
                    };
                    fieldWorkerProduct.SetAudit(CurrentLoggedUserId);

                    _fieldWorkerProductService.Create(fieldWorkerProduct);
                }
                else
                {
                    var fieldWorkerProduct = fieldWorkerProducts.First();
                    fieldWorkerProduct.Quantity += request.Quantity;
                    fieldWorkerProduct.SetAudit(CurrentLoggedUserId);

                    _fieldWorkerProductService.Update(fieldWorkerProduct);
                }
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create storage export was successfully, but Field Worker Quantity of the product was not updated properly, please contact Office worker!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }