Exemple #1
0
        private DTOImageCollection ConvertToDTOImageCollection(ImageCollection tempList)
        {
            DTOImageCollection returnList = new DTOImageCollection();

            foreach (Image d in tempList)
            {
                DTOImage tempImage = Mapper.Map <DTOImage>(d);
                returnList.Add(tempImage);
            }
            return(returnList);
        }
Exemple #2
0
        public async Task <IActionResult> AddProfilePicture([FromForm] DTOImage image, Guid id)
        {
            if (image.Image == null || image.Image.Length == 0)
            {
                return(Content("file not selected"));
            }

            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot/profileImages",
                image.Image.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await image.Image.CopyToAsync(stream);

                using (var unit = _factory.GetUOF())
                {
                    try
                    {
                        // find user
                        var currentAppuser = unit.Users.Get(id);
                        // Add Image
                        // TODO change connectionstring for production
                        string conString = ConfigurationExtensions
                                           .GetConnectionString(_configuration, "profileImages");
                        currentAppuser.Image = conString + "/" + image.Image.FileName;
                        unit.Complete();
                        return(Ok());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
            }
        }