Ejemplo n.º 1
0
        public ArtefactInfoDto GetById(int artefactInfoId)
        {
            ArtefactInfo artefactInfo = Db.ArtefactInfos.Find(artefactInfoId);

            if (artefactInfo == null)
            {
                NotFoundException();
            }

            return(Mapper.Map <ArtefactInfoDto>(artefactInfo));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetBytes(int artefactInfoId)
        {
            HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            ArtefactInfo artefactInfo = Db.ArtefactInfos.Find(artefactInfoId);

            if (artefactInfo == null)
            {
                NotFoundException();
            }

            result.Content = new ByteArrayContent(artefactInfo.File);
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            return(result);
        }
Ejemplo n.º 3
0
        public bool Delete(int artefactInfoId)
        {
            ArtefactInfo artefactInfo = Db.ArtefactInfos.Include("Artefact").FirstOrDefault(m => m.Id == artefactInfoId);

            if (artefactInfo == null)
            {
                NotFoundException();
            }

            artefactInfo.IsDeleted    = true;
            artefactInfo.ModifiedDate = DateTime.Now;

            Db.SaveChanges();

            return(true);
        }
Ejemplo n.º 4
0
        public ArtefactInfoDto Create(ArtefactInfoDto dto)
        {
            ArtefactInfo artefactInfo = new ArtefactInfo
            {
                Description      = dto.Description,
                File             = dto.File,
                FileExtension    = dto.FileExtension,
                ArtefactInfoType = (int)dto.ArtefactInfoType,
                Content          = dto.Content,
                CreatedDate      = DateTime.UtcNow,
                ModifiedDate     = DateTime.UtcNow,
                IsDeleted        = false,
                Artefact         = Db.Artefacts.Find(dto.Artefact.Id)
            };

            Db.ArtefactInfos.Add(artefactInfo);

            Db.SaveChanges();

            return(Mapper.Map <ArtefactInfoDto>(artefactInfo));
        }
Ejemplo n.º 5
0
        public ArtefactInfoDto Update(ArtefactInfoDto dto)
        {
            ArtefactInfo artefactInfo = Db.ArtefactInfos.Include("Artefact").FirstOrDefault(m => m.Id == dto.Id);

            if (artefactInfo == null)
            {
                NotFoundException();
            }

            artefactInfo.Description      = dto.Description;
            artefactInfo.File             = dto.File;
            artefactInfo.FileExtension    = dto.FileExtension;
            artefactInfo.ArtefactInfoType = (int)dto.ArtefactInfoType;
            artefactInfo.Content          = dto.Content;
            artefactInfo.ModifiedDate     = DateTime.UtcNow;
            artefactInfo.IsDeleted        = dto.IsDeleted;
            artefactInfo.Artefact         = Db.Artefacts.Find(dto.Artefact.Id);

            Db.SaveChanges();

            return(Mapper.Map <ArtefactInfoDto>(artefactInfo));
        }