예제 #1
0
        public async Task <IActionResult> AddManufacturer(Manufacturer manufacturer)
        {
            _repo.Add <Manufacturer>(manufacturer);
            await _repo.SaveAll();

            return(CreatedAtAction("GetManufacturers", new { id = manufacturer.IDManufacturer }, manufacturer));
        }
예제 #2
0
        public async Task <IActionResult> UpdateProduct(int id, ProductForUpdateDto productForUpdateDto)
        {
            var productFromRepo = await _repo.GetProduct(id);

            _mapper.Map(productForUpdateDto, productFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Cập nhật sản phẩm id= {id} thất bại.");
        }
예제 #3
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdateDto userForUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(userForUpdateDto, userFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Cập nhập user {id} thất bại");
        }
예제 #4
0
 public IActionResult Contact(ContactViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var contact = Mapper.Map <ContactViewModel, Contact>(model);
             rep.SaveEntity(contact);
             rep.SaveAll();
             ViewBag.UserMessage = "Thanks for contacting us ,we will get back to you shortly";
         }
         return(View());
     }
     catch (Exception ex)
     {
         this.Logger.LogError(ex.Message);
         return(null);
     }
 }
예제 #5
0
        public async Task <IActionResult> AddPhotoForProduct(int idProduct, [FromForm] PhotoForCreationDto photoForCreationDto)
        {
            var product = await _repo.GetProduct(idProduct);

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

            if (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("fill").Gravity("face")
                    };
                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            photoForCreationDto.Url      = uploadResult.Uri.ToString();
            photoForCreationDto.PublicId = uploadResult.PublicId;

            var photo = _mapper.Map <Photo>(photoForCreationDto);

            if (!product.Photos.Any(u => u.IsMain))
            {
                photo.IsMain = true;
            }

            product.Photos.Add(photo);

            if (await _repo.SaveAll())
            {
                var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoToReturn));
            }

            return(BadRequest("Could not add the photo"));
        }
예제 #6
0
        public async Task <IActionResult> UpdateOrder(int id, int state)
        {
            var orderFromRepo = await _repo.GetOrderById(id);

            var orderUpated = orderFromRepo;

            orderUpated.OrderState = state;
            _mapper.Map(orderUpated, orderFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Duyệt hóa đơn = {id} thất bại.");
        }