Exemplo n.º 1
0
        public async Task <IActionResult> UpdateClassifiedAds(string id, ClassifiedAdsForUserUpdate classifiedAdsForUserUpdate)
        {
            var user = await _userManager.Users.SingleOrDefaultAsync(x => x.Id.ToString().ToLower() == id.ToString().ToLower() && x.Id.ToString().ToLower() == User.GetUserId().ToString().ToLower());

            if (user == null)
            {
                return(Unauthorized());
            }

            var classifiedAdsForUserUpdateFromRepo = await _repo.GetClassifiedAdDetaiForUser(classifiedAdsForUserUpdate.Id);

            if (classifiedAdsForUserUpdateFromRepo.AppUserId != id)
            {
                return(Unauthorized());
            }

            _mapper.Map(classifiedAdsForUserUpdate, classifiedAdsForUserUpdateFromRepo);

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

            //throw new Exception($"Updating classified ad {id} failed on save");
            throw new Exception($"Зачувувањето на огласот со ид= {id} не беше успешно");
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateClassifiedAds(int id, ClassifiedAdsForUserUpdate classifiedAdsForUserUpdate)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var classifiedAdsForUserUpdateFromRepo = await _repo.GetClassifiedAdDetail(classifiedAdsForUserUpdate.Id);

            _mapper.Map(classifiedAdsForUserUpdate, classifiedAdsForUserUpdateFromRepo);

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

            //throw new Exception($"Updating classified ad {id} failed on save");
            throw new Exception($"Зачувувањето на огласот со ид= {id} не беше успешно");
        }