Example #1
0
        public IActionResult Update(int id, [FromBody] AddOrUpdateAssetResource config)
        {
            var result = _mapper.Map <Asset>(config);
            //validate object
            var validateResult = _assetService.validateAsset(result);

            if (!validateResult.flag)
            {
                return(BadRequest(validateResult.errors));
            }

            var asset = _queryAll.ExecuteOne(id);

            if (asset == null)
            {
                return(NotFound());
            }

            if (config.AssetName != null)
            {
                asset.AssetName = config.AssetName;
            }
            if (config.Department != null)
            {
                asset.Department = config.Department;
            }
            if (config.CountryOfDepartment != null)
            {
                asset.CountryOfDepartment = config.CountryOfDepartment;
            }
            if (config.EMailAdressOfDepartment != null)
            {
                asset.EMailAdressOfDepartment = config.EMailAdressOfDepartment;
            }
            if (config.PurchaseDate != null)
            {
                asset.PurchaseDate = config.PurchaseDate;
            }
            if (config.broken != asset.broken)
            {
                asset.broken = config.broken;
            }

            _command.ExecuteUpdate(asset);

            return(Ok());
        }
Example #2
0
        public IActionResult Add([FromBody] AddOrUpdateAssetResource resource)
        {
            var result = new Asset
            {
                AssetName               = resource.AssetName,
                broken                  = resource.broken,
                CountryOfDepartment     = resource.CountryOfDepartment,
                Department              = resource.Department,
                EMailAdressOfDepartment = resource.EMailAdressOfDepartment,
                PurchaseDate            = resource.PurchaseDate,
            };
            //validate object
            var validateResult = _assetService.validateAsset(result);

            if (!validateResult.flag)
            {
                return(BadRequest(validateResult.errors));
            }
            _command.ExecuteAdd(result);

            return(Created(result.ID.ToString(), ToResource(result)));
        }