public async Task <ActionResult <Photo> > CreateAsync(Photo photo)
        {
            _logger.LogInformation("Create invoked");

            //user.Identity.Name works because:
            // 1) on the Identity Server Project Config I added the JwtClaimTypes.Name in the UserClaims of the "photos" ApiResource
            // 2) in this startup I added options.TokenValidationParameters.NameClaimType = JwtClaimTypes.Name; in the AddJwtBearer("Bearer", options =>{ ... })
            return(await photosService.CreateAsync(photo.Title, photo.PhotoFile, photo.ImageMimeType, photo.Description, User.Identity.Name));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create([Bind("Description, Filter")] PhotoViewModel item, string tags, IFormFile file, int?Iso, double?Aperture, double?Exposure, double?FocalLength, string Model, string Brand)
        {
            if (ModelState.IsValid && file.Length > 0)
            {
                var fileName = Convert.ToString(Guid.NewGuid()) + Path.GetExtension(ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'));

                item.Path = fileName;

                fileName = Path.Combine(_environment.WebRootPath, "data/photos") + $@"/{User.Identity.Name}/{fileName}";

                var dir = Path.Combine(_environment.WebRootPath, "data/photos") + $@"/{User.Identity.Name}";

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                using (var fs = System.IO.File.Create(fileName))
                {
                    await file.CopyToAsync(fs);

                    await fs.FlushAsync();
                }

                var manufacturer = Brand;
                var model        = Model;

                if (manufacturer == null || model == null)
                {
                    using (var image = new MagickImage(fileName))
                    {
                        var profile = image.GetExifProfile();

                        if (profile != null)
                        {
                            foreach (var value in profile.Values)
                            {
                                if (value.Tag == ExifTag.Make && manufacturer == null)
                                {
                                    manufacturer = value.ToString();
                                }
                                else if (value.Tag == ExifTag.Model && model == null)
                                {
                                    model = value.ToString();
                                }
                            }
                        }
                    }
                }

                int pid = await _photosService.CreateAsync(item.Filter, item.Description, item.Path, manufacturer, model, Iso, Exposure, Aperture, FocalLength, tags);

                return(RedirectToAction("Details", "Photos", new { id = pid }));
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public override async Task <CreateReply> Create(CreateRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Create invoked");
            var user = context.GetHttpContext().User;
            //user.Identity.Name works because:
            // 1) on the Identity Server Project Config I added the JwtClaimTypes.Name in the UserClaims of the "photos" ApiResource
            // 2) in this startup I added options.TokenValidationParameters.NameClaimType = JwtClaimTypes.Name; in the AddJwtBearer("Bearer", options =>{ ... })
            Photo ph = await photosService.CreateAsync(request.Title, request.PhotoFile.ToByteArray(), request.ImageMimeType, request.Description, user.Identity.Name);

            return(ph.ToCreateReply());
        }