public override async Task <ServiceResult> Insert(RadnikPrijemUpsertDto request)
        {
            var radnikInsertResult = await _radnikService.Insert(request);

            if (!radnikInsertResult.Succeeded)
            {
                return(ServiceResult.WithStatusCode(radnikInsertResult.StatusCode, radnikInsertResult.Message));
            }
            var radnik = radnikInsertResult.Data as Radnik;

            if (radnik == null)
            {
                throw new NullReferenceException();
            }

            var rolesAddResult = await _korisnikService.AddInRoles(radnik.KorisnickiNalogId,
                                                                   new KorisnickiNalogRolesUpsertDto { RoleId = RoleType.RadnikPrijem.ToInt() });

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

            var entity = new RadnikPrijem {
                RadnikId = radnik.Id
            };

            await _dbContext.AddAsync(entity);

            await _dbContext.SaveChangesAsync();

            return(new ServiceResult(_mapper.Map <RadnikPrijemDtoLL>(entity)));
        }
        public async Task <IActionResult> AddInRoles(int id, KorisnickiNalogRolesUpsertDto request)
        {
            var result = await _korisnikService.AddInRoles(id, request);

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

            return(Ok(result.Data));
        }
Ejemplo n.º 3
0
        public override async Task <ServiceResult> Insert(DoktorUpsertDto request)
        {
            if (!await _dbContext.NaucneOblasti.AnyAsync(x => x.Id == request.NaucnaOblastId))
            {
                return(ServiceResult.NotFound($"Naucna oblast sa ID-em {request.NaucnaOblastId} nije pronadjena."));
            }

            var radnikInsertResult = await _radnikService.Insert(request);

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

            var radnik = radnikInsertResult.Data as Radnik;

            if (radnik == null)
            {
                throw new NullReferenceException();
            }

            var rolesAddResult = await _korisnikService.AddInRoles(radnik.KorisnickiNalogId,
                                                                   new KorisnickiNalogRolesUpsertDto { RoleId = RoleType.Doktor.ToInt() });

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

            var entity = _mapper.Map <Doktor>(request);

            entity.RadnikId = radnik.Id;

            await _dbContext.AddAsync(entity);

            await _dbContext.SaveChangesAsync();

            return(ServiceResult.OK(_mapper.Map <DoktorDtoLL>(entity)));
        }