Example #1
0
        public IActionResult Material(int materialId)
        {
            var material = _service.GetMaterial(materialId);

            if (material == null)
            {
                return(RedirectToAction("ResourceNotFound", "Error", new { error = "MateriaƂ o podanym Id nie istnieje." }));
            }

            var vm = PrepareMaterialViewModel(material);

            return(View(vm));
        }
        public IActionResult ApproveMaterial(int materialId, bool isRedirectToMaterial)
        {
            var loggedUser = _userService.FindByIdentityUserId(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var material = _materialsService.GetMaterial(materialId);

            if (material == null)
            {
                return(RedirectToAction("ResourceNotFound", "Error", new { error = "materiaƂ o podanym Id nie istnieje." }));
            }

            _materialsService.ApproveMaterial(material, loggedUser);

            if (isRedirectToMaterial)
            {
                return(RedirectToAction("Material", "Materials", new { area = "Main", materialId }));
            }

            return(RedirectToAction("MaterialsToApprove"));
        }
Example #3
0
        public HttpResponseMessage Get(int id)
        {
            // Check if exist
            var materialImage = _materialService.GetMaterial(id);

            if (materialImage == null || materialImage.Image == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            // Check if correct mime type
            MediaTypeHeaderValue mimeTypeHeader;

            try
            {
                mimeTypeHeader = new MediaTypeHeaderValue(materialImage.MimeType);
            }
            catch (System.FormatException)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }

            // Create response
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(new MemoryStream(materialImage.Image))
            };

            result.Content.Headers.ContentType = mimeTypeHeader;
            result.Headers.CacheControl        = new CacheControlHeaderValue()
            {
                MaxAge  = _age,
                Public  = false,
                NoCache = false,
                Private = true,
            };
            result.Content.Headers.Expires = DateTime.UtcNow.Add(_age);

            return(result);
        }