Ejemplo n.º 1
0
        public IHttpActionResult Put(long id, AssetWriteModel model)
        {
            if (model == null)
            {
                return(BadRequest(Constants.MISSING_MESSAGE_BODY));
            }

            if (!_assetRepo.Exists(id))
            {
                return(NotFound());
            }

            if (!_productRepo.Exists(model.ProductId.Value))
            {
                return(BadRequest(UNKNOWN_PRODUCT));
            }

            var dto = MapToDto(model, id, modifiedBy: _jwt.UserId);

            _assetRepo.Update(dto);

            // Refetch the data.
            dto = _assetRepo.GetById(id);
            var readModel = MapToModel(dto);

            return(Ok(readModel));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post(AssetWriteModel model)
        {
            if (model == null)
            {
                return(BadRequest(Constants.MISSING_MESSAGE_BODY));
            }

            var  dto = MapToDto(model, createdBy: _shibbolethAttribs.GetUid());
            long id  = _repo.Insert(dto);

            // Refetch the data.
            dto = _repo.GetById(id);
            var readModel = MapToModel(dto);

            return(CreatedAtRoute("GetAssetById", new { id = readModel.Id }, readModel));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Post(AssetWriteModel model)
        {
            if (model == null)
            {
                return(BadRequest(Constants.MISSING_MESSAGE_BODY));
            }

            if (!_productRepo.Exists(model.ProductId.Value))
            {
                return(BadRequest(UNKNOWN_PRODUCT));
            }

            var  dto = MapToDto(model, createdBy: _jwt.UserId);
            long id  = _assetRepo.Insert(dto);

            // Refetch the data.
            dto = _assetRepo.GetById(id);
            var readModel = MapToModel(dto);

            return(CreatedAtRoute(nameof(GetAssetById), new { id = readModel.Id }, readModel));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Put(long id, AssetWriteModel model)
        {
            if (model == null)
            {
                return(BadRequest(Constants.MISSING_MESSAGE_BODY));
            }

            if (!_repo.Exists(id))
            {
                return(NotFound());
            }

            var dto = MapToDto(model, id, modifiedBy: _shibbolethAttribs.GetUid());

            _repo.Update(dto);

            // Refetch the data.
            dto = _repo.GetById(id);
            var readModel = MapToModel(dto);

            return(Ok(readModel));
        }
Ejemplo n.º 5
0
 private static AssetDto MapToDto(
     AssetWriteModel input, long?id = null, string createdBy = null, string modifiedBy = null) =>
 new AssetDto
 {
     Id            = id,
     CreatedBy     = createdBy,
     ModifiedBy    = modifiedBy,
     IctsReference = input.IctsReference,
     Tag           = input.Tag,
     Serial        = input.Serial,
     Product       = new ProductDto {
         Id = input.ProductId.Value
     },
     Description   = input.Description,
     InvoiceDate   = input.InvoiceDate,
     InvoiceNumber = input.InvoiceNumber,
     Price         = input.Price,
     PaidBy        = input.PaidBy,
     Owner         = input.Owner,
     InstallDate   = input.InstallDate,
     InstalledBy   = input.InstalledBy,
     Remark        = input.Remark,
     TeamAsset     = input.TeamAsset.Value
 };