public override async Task <ServiceResult> Update(int id, RadnikPrijemUpsertDto dtoForUpdate)
        {
            var radnikPrijemFromDb = await _dbContext.RadniciPrijem
                                     .Include(x => x.Radnik)
                                     .FirstOrDefaultAsync(x => x.Id == id);

            if (radnikPrijemFromDb == null)
            {
                return(ServiceResult.NotFound($"Radnik sa ID-em {id} nije pronadjen"));
            }

            _mapper.Map(dtoForUpdate, radnikPrijemFromDb.Radnik);
            await _radnikService.Update(radnikPrijemFromDb.RadnikId, dtoForUpdate);

            return(new ServiceResult(_mapper.Map <RadnikPrijemDtoLL>(radnikPrijemFromDb)));
        }
Exemple #2
0
        public override async Task <ServiceResult> Update(int id, MedicinskiTehnicarUpsertDto dtoForUpdate)
        {
            var medicinskiTehnicarFromDb = await _dbContext.MedicinskiTehnicari
                                           .Include(x => x.Radnik)
                                           .FirstOrDefaultAsync(x => x.Id == id);

            if (medicinskiTehnicarFromDb == null)
            {
                return(ServiceResult.NotFound($"Medicinski tehnicar sa ID-em {id} nije pronadjen"));
            }

            _mapper.Map(dtoForUpdate, medicinskiTehnicarFromDb.Radnik);
            var radnikUpdated = await _radnikService.Update(medicinskiTehnicarFromDb.RadnikId, dtoForUpdate);

            return(new ServiceResult(_mapper.Map <MedicinskiTehnicarDtoLL>(medicinskiTehnicarFromDb)));
        }
Exemple #3
0
        public override async Task <ServiceResult> Update(int id, DoktorUpsertDto dtoForUpdate)
        {
            var getDoktorResult = await GetDoktor(id);

            if (!getDoktorResult.Succeeded)
            {
                return(ServiceResult.WithStatusCode(getDoktorResult.StatusCode, getDoktorResult.Message));
            }

            var doktorFromDb = getDoktorResult.doktor;

            if (!await _authService.CurrentUserIsInRoleAsync(RoleType.Administrator) && doktorFromDb.Radnik.KorisnickiNalogId != ((await _authService.LoggedInUser())?.Id ?? 0))
            {
                return(ServiceResult.Forbidden("Ne mozete vrsiti izmene na drugim profilima doktora."));
            }

            if (doktorFromDb.NaucnaOblastId != dtoForUpdate.NaucnaOblastId)
            {
                if (!await _dbContext.NaucneOblasti.AnyAsync(x => x.Id == dtoForUpdate.NaucnaOblastId))
                {
                    return(ServiceResult.NotFound(
                               $"Naucna oblast sa ID-em {dtoForUpdate.NaucnaOblastId} nije pronadjena."));
                }

                doktorFromDb.NaucnaOblastId = dtoForUpdate.NaucnaOblastId;
                await _dbContext.SaveChangesAsync();
            }

            _mapper.Map(dtoForUpdate, doktorFromDb.Radnik);
            var radnikUpdateResult = await _radnikService.Update(doktorFromDb.RadnikId, dtoForUpdate);

            if (!radnikUpdateResult.Succeeded)
            {
                return(ServiceResult.WithStatusCode(radnikUpdateResult.StatusCode, radnikUpdateResult.Message));
            }
            return(ServiceResult.OK(_mapper.Map <DoktorDtoLL>(doktorFromDb)));
        }