public async Task <IActionResult> GetSupplier(int id) { var supplierFroRepo = await _repo.GetSupplier(id); var supplier = _mapper.Map <SupplierReturnDTO>(supplierFroRepo); return(Ok(supplier)); }
public async Task <IActionResult> AddPhotosupplier(int supplierId, [FromForm] PhotoForCreateDto photoForCreateDto) { if (supplierId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var supplier = await _repo.GetSupplier(supplierId); 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 = supplierId; if (!supplier.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("خطا في اضافة الصورة")); }
public async Task <IActionResult> CreateProduct(int supplierId, int sectionId, ProductRegisterDTO productRegisterDTO) { var sectionFromRepo = await _repo.GetSection(sectionId); productRegisterDTO.SectionId = sectionFromRepo.SectionId; var supplierFromRepo = await _repo.GetSupplier(supplierId); productRegisterDTO.SupplierId = supplierFromRepo.Id; var product = _mapper.Map <Product>(productRegisterDTO); _repo.Add(product); if (await _repo.SaveAll()) { var productToReturn = _mapper.Map <ProductReturnDTO>(product); return(CreatedAtRoute("GetProduct", new { id = product.ProductId }, productToReturn)); } throw new Exception("حدث مشكلة في حفظ الرسالة الجديده"); }