示例#1
0
        public IActionResult Update([FromRoute] int id, [FromBody] FieldWorkerProduct request)
        {
            request.SetAudit(CurrentLoggedUserId);
            var fieldWorkerProduct = _fieldWorkerProductService.Update(request);

            return(Ok(fieldWorkerProduct.Id));
        }
示例#2
0
        public IActionResult Create([FromBody] FieldWorkerProduct request)
        {
            var fieldWorkerProduct = new FieldWorkerProduct();

            request.SetAudit(CurrentLoggedUserId);

            if (ModelState.IsValid)
            {
                fieldWorkerProduct = _fieldWorkerProductService.Create(request);
            }

            return(Ok(fieldWorkerProduct.Id));
        }
        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));
        }