public async Task <IActionResult> SetMainPhotoSupplier(int supplierId, int id)
        {
            if (supplierId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var supplierFromRepo = await _repo.GetSupplier(supplierId);

            if (!supplierFromRepo.PhotoForSuppliers.Any(p => p.PhotoId == id))
            {
                return(Unauthorized());
            }
            var DesiredMainPhoto = await _repo.GetPhotoForSupplier(id);

            if (DesiredMainPhoto.IsMain)
            {
                return(BadRequest("هذه هي الصورة الأساسية بالفعل"));
            }
            var CurrentMainPhoto = await _repo.GetMainPhotoForSupplier(supplierId);

            CurrentMainPhoto.IsMain = false;
            DesiredMainPhoto.IsMain = true;
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("لايمكن تعديل الصورة الأساسية"));
        }
Esempio n. 2
0
        public async Task <IActionResult> SetMainPhotoSupplier(int userId, int id)
        {
            var userFromRepo = await _repo.GetUser(userId);

            if (!userFromRepo.PhotoForSuppliers.Any(p => p.PhotoId == id))
            {
                return(Unauthorized());
            }
            var DesiredMainPhoto = await _repo.GetPhotoForSupplier(id);

            if (DesiredMainPhoto.IsMain)
            {
                return(BadRequest("هذه هي الصورة الأساسية بالفعل"));
            }
            var CurrentMainPhoto = await _repo.GetMainPhotoForSupplier(userId);

            CurrentMainPhoto.IsMain = false;
            DesiredMainPhoto.IsMain = true;
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("لايمكن تعديل الصورة الأساسية"));
        }