Exemplo n.º 1
0
        public Asset CreateAsset(Asset asset)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var current = AssetDao.ReadFromFile().ToList();

            if (asset.Id == "")
            {
                var id = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                id       = id.Replace('/', '_');
                id       = id.Replace('+', '-');
                asset.Id = id;
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);  //ID has to be auto assigned
            }
            current.Add(asset);

            AssetDao.WriteToFile(current);

            return(asset);
        }
Exemplo n.º 2
0
        public IHttpActionResult DeleteAsset(string id)
        {
            var list        = AssetDao.ReadFromFile().ToList();
            var assetInFile = list.SingleOrDefault(c => Equals(c.Id, id));

            if (assetInFile == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            list.Remove(assetInFile);

            AssetDao.WriteToFile(list);
            return(Ok());
        }
Exemplo n.º 3
0
        public IHttpActionResult UpdateAssetCount(AssetPatchRequest request)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var list        = AssetDao.ReadFromFile().ToList();
            var assetInFile = list.SingleOrDefault(c => Equals(c.Id, request.Id));

            if (assetInFile == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            list.Remove(assetInFile);
            assetInFile.Count = request.Count;
            list.Add(assetInFile);
            AssetDao.WriteToFile(list);
            return(Ok());
        }