public async Task <IActionResult> GetUser(int id)
        {
            var userFroRepo = await _repo.GetUser(id);

            var user = _mapper.Map <UserReturnDTO>(userFroRepo);

            return(Ok(user));
        }
Example #2
0
        public async Task <IActionResult> AddPhotosupplier(int userId, [FromForm] PhotoForCreateDto photoForCreateDto)
        {
            var user = await _repo.GetUser(userId);

            var file         = photoForCreateDto.File;
            var uploadResult = new ImageUploadResult();

            if (file != null && file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File           = new FileDescription(file.Name, stream),
                        Transformation = new Transformation()
                                         .Width(500).Height(500).Crop("scale")
                    };
                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }
            photoForCreateDto.Url      = uploadResult.Uri.ToString();
            photoForCreateDto.PublicId = uploadResult.PublicId;
            var photo = _mapper.Map <PhotoForSupplier>(photoForCreateDto);

            photo.SupplierId = userId;
            if (!user.PhotoForSuppliers.Any(p => p.IsMain))
            {
                photo.IsMain = true;
            }
            _repo.Add(photo);
            if (await _repo.SaveAll())
            {
                var photoToRetrun = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhotoSupplier", new { id = photo.PhotoId }, photoToRetrun));
            }

            return(BadRequest("خطا في اضافة الصورة"));
        }