public async Task <ActionResult> Edit(ArtefactInfoDto artefactInfo, HttpPostedFileBase ArtefactInfoFile)
        {
            var             request = new HTTPrequest();
            ArtefactInfoDto artefactInfo_editted = await request.Get <ArtefactInfoDto>("api/artefactInfo/" + artefactInfo.Id.ToString());

            // Checks Name is not Null or Empty
            if (artefactInfo.Artefact.Id.ToString() == null || string.IsNullOrEmpty(artefactInfo.Artefact.Id.ToString()))
            {
                ViewBag.ValidationName = "Artefact is required.";
                return(View(artefactInfo));
            }

            if (ModelState.IsValid)
            {
                artefactInfo_editted.Artefact         = artefactInfo.Artefact;
                artefactInfo_editted.Content          = artefactInfo.Content;
                artefactInfo_editted.Description      = artefactInfo.Description;
                artefactInfo_editted.ArtefactInfoType = artefactInfo.ArtefactInfoType;
                if (ArtefactInfoFile != null)
                {
                    HttpPostedFileBase mediaFile = Request.Files["ArtefactInfoFile"];

                    artefactInfo_editted.File = new byte[mediaFile.ContentLength];
                    mediaFile.InputStream.Read(artefactInfo_editted.File, 0, mediaFile.ContentLength);
                    string fileExtension = Path.GetExtension(mediaFile.FileName);
                    artefactInfo_editted.FileExtension = fileExtension;
                }


                artefactInfo = await request.Put <ArtefactInfoDto>("api/artefactInfo", artefactInfo_editted);

                return(RedirectToAction("Index"));
            }
            return(View(artefactInfo));
        }
        // GET: ArtefactInfo/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var request = new HTTPrequest();

            ArtefactInfoDto artefactInfo = await request.Get <ArtefactInfoDto>("api/artefactInfo/" + id);

            if (artefactInfo == null)
            {
                return(HttpNotFound());
            }

            //TODO review this works
            HttpResponseMessage bytesResponse = await request.GetResponseMessage("api/artefactInfo/" + id + "/bytes");

            byte[] response = await bytesResponse.Content.ReadAsByteArrayAsync();

            //sets bytes to actual byte response
            artefactInfo.File = response;

            return(View(artefactInfo));
        }
Exemplo n.º 3
0
 public ArtefactInfoDto Update([FromBody] ArtefactInfoDto dto)
 {
     try
     {
         return(new ArtefactInfoHandler(isTest).Update(dto));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        // GET: ArtefactInfo/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var             request      = new HTTPrequest();
            ArtefactInfoDto artefactInfo = await request.Get <ArtefactInfoDto>("api/artefactInfo/" + id);

            if (artefactInfo == null)
            {
                return(HttpNotFound());
            }
            return(View(artefactInfo));
        }
        public async Task <ActionResult> GetVideo()
        {
            var             request      = new HTTPrequest();
            ArtefactInfoDto artefactInfo = await request.Get <ArtefactInfoDto>("api/artefactInfo/1");

            if (artefactInfo == null)
            {
                return(HttpNotFound());
            }

            HttpResponseMessage bytesResponse = await request.GetResponseMessage("api/artefactInfo/1/bytes");

            byte[] response = await bytesResponse.Content.ReadAsByteArrayAsync();

            return(File(response, "video/mp4"));
        }
        public async Task <ActionResult> Create(ArtefactInfoDto artefactInfo, HttpPostedFileBase ArtefactInfoFile)
        {
            ArtefactInfoDto newArtefactInfo = new ArtefactInfoDto();

            newArtefactInfo.Id               = artefactInfo.Id;
            newArtefactInfo.Artefact         = artefactInfo.Artefact;
            newArtefactInfo.ArtefactInfoType = artefactInfo.ArtefactInfoType;
            newArtefactInfo.CreatedDate      = DateTime.Now;
            newArtefactInfo.ModifiedDate     = DateTime.Now;
            newArtefactInfo.Description      = artefactInfo.Description;
            // need to parse apostrophes out
            newArtefactInfo.Content = artefactInfo.Content;

            // Checks Name is not Null or Empty
            if (artefactInfo.Artefact.Id.ToString() == null || string.IsNullOrEmpty(artefactInfo.Artefact.Id.ToString()))
            {
                ViewBag.ValidationName = "Artefact is required.";
                return(View(artefactInfo));
            }

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                //HttpPostedFileBase newFile = Request.Files["ArtefactInfoFile"];
                //HttpPostedFileBase newFile = ArtefactInfoFile;
                if (ArtefactInfoFile != null && ArtefactInfoFile.ContentLength > 0)
                {
                    artefactInfo.File = new byte[ArtefactInfoFile.ContentLength];
                    ArtefactInfoFile.InputStream.Read(artefactInfo.File, 0, ArtefactInfoFile.ContentLength);
                    string fileExtension = Path.GetExtension(ArtefactInfoFile.FileName);
                    artefactInfo.FileExtension = fileExtension;
                    if (ArtefactInfoFile == null)
                    {
                        throw new ArgumentException("file");
                    }
                }

                await request.Post <ArtefactInfoDto>("api/artefactInfo", artefactInfo);

                return(RedirectToAction("Index"));
            }

            return(View(artefactInfo));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                var             request      = new HTTPrequest();
                ArtefactInfoDto artefactInfo = await request.Get <ArtefactInfoDto>("api/artefactInfo/" + id);

                artefactInfo.IsDeleted = true;
                await request.Put <ArtefactInfoDto>("api/artefactInfo", artefactInfo);

                await request.Delete("api/artefactInfo/" + id.ToString());

                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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));
        }
        // GET: ArtefactInfo/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            var request = new HTTPrequest();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArtefactInfoDto artefactInfo = await request.Get <ArtefactInfoDto>("api/artefactInfo/" + id);

            if (artefactInfo == null)
            {
                return(HttpNotFound());
            }

            //ARTEFACT CATEGORY DROPDOWN
            List <SelectListItem> artefactDropdown = new List <SelectListItem>();

            artefactDropdown = await PopulateArtefactDropdown();

            ViewBag.ArtefactList = artefactDropdown;

            return(View(artefactInfo));
        }