/// <summary>
        /// Pridá nové vyšetrenie do databázy na základe údajov. AutoMapper nevyužitý z dôvodu konštrukcie dát,
        /// a využité manuálne mapovanie pomocou lazy loadingu z proxy
        /// </summary>
        /// <param name="noveVysetrenie"></param>
        /// <returns></returns>
        public async Task <ServiceResponse <GetVysetrenieDto> > AddVysetrenie(AddVysetrenieDto noveVysetrenie)
        {
            ServiceResponse <GetVysetrenieDto> serviceResponse = new ServiceResponse <GetVysetrenieDto>();

            Vysetrenie vysetrenie = _context.CreateProxy <Vysetrenie>();

            vysetrenie.PacientId       = noveVysetrenie.PacientId;
            vysetrenie.ZPersonalId     = noveVysetrenie.ZPersonalId;
            vysetrenie.TypVysetreniaId = noveVysetrenie.TypVysetreniaId;
            vysetrenie.Ambulancia      = noveVysetrenie.Ambulancia;

            try
            {
                await _context.Vysetrenia.AddAsync(vysetrenie);

                await _context.SaveChangesAsync();

                serviceResponse.Data    = _mapper.Map <GetVysetrenieDto>(vysetrenie);
                serviceResponse.Success = true;
            }
            catch (Exception e)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = e.Message;
            }

            return(serviceResponse);
        }
Beispiel #2
0
        /// <summary>
        /// Pridá osobu na základe poskynutých dát
        /// </summary>
        /// <param name="novaOsoba"></param>
        /// <returns></returns>
        public async Task <ServiceResponse <List <GetOsobaDto> > > AddOsoba(AddOsobaDto novaOsoba)
        {
            ServiceResponse <List <GetOsobaDto> > serviceResponse = new ServiceResponse <List <GetOsobaDto> >();
            Osoba osoba = _mapper.Map <Osoba>(novaOsoba);
            await _context.Osoby.AddAsync(osoba);

            await _context.SaveChangesAsync();

            serviceResponse.Data = (_context.Osoby.Select(c => _mapper.Map <GetOsobaDto>(c))).ToList();
            return(serviceResponse);
        }
Beispiel #3
0
        /// <summary>
        /// Z formulára poskytnutom pri registrácií - RegisterDto, vytvorí jednotlivé záznamy na uloženie v databáze.
        /// Heslá sa hashujú a saltujú. Nedovoľuje vytvoriť užívateľa s už existujúcim emailom alebo rodným číslom
        /// </summary>
        /// <param name="novyUzivatelDto"></param>
        /// <returns></returns>
        public async Task <ServiceResponse <GetUzivatelDto> > RegisterUser(RegisterDto novyUzivatelDto)
        {
            ServiceResponse <GetUzivatelDto> serviceResponse = new ServiceResponse <GetUzivatelDto>();

            if (!_context.Osoby.Any(o => o.RodneCislo == novyUzivatelDto.RodneCislo) && !_context.Accounts.Any(a => a.Email == novyUzivatelDto.Email))
            {
                //Osoba
                Osoba osoba = _mapper.Map <Osoba>(novyUzivatelDto);
                await _context.Osoby.AddAsync(osoba);

                await _context.SaveChangesAsync();

                //Uzivatel
                Uzivatel uzivatel = _mapper.Map <Uzivatel>(novyUzivatelDto);
                uzivatel.OsobaId = osoba.Id;
                await _context.Uzivatelia.AddAsync(uzivatel);

                //Pacient
                Pacient pacient = new Pacient()
                {
                    OsobaId = osoba.Id
                };
                await _context.Pacienti.AddAsync(pacient);

                await _context.SaveChangesAsync();

                //Account info
                AccountInfo accountInfo = _mapper.Map <AccountInfo>(novyUzivatelDto);
                accountInfo.Uzivatel = uzivatel;
                var salt = GenerateSalt();
                var hash = Pbkdf2Hash(novyUzivatelDto.Heslo, salt);
                accountInfo.Salt     = salt;
                accountInfo.Password = hash;

                await _context.Accounts.AddAsync(accountInfo);

                await _context.SaveChangesAsync();

                serviceResponse.Data = _mapper.Map <GetUzivatelDto>(uzivatel);
            }
            else
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "User with this username or id number is already registered";
            }
            return(serviceResponse);
        }
        /// <summary>
        /// Pridá užívateľa podľa zadaných údajov
        /// </summary>
        /// <param name="novyUzivatel"></param>
        /// <returns></returns>
        public async Task <ServiceResponse <List <GetUzivatelDto> > > AddUzivatel(AddUzivatelDto novyUzivatel)
        {
            ServiceResponse <List <GetUzivatelDto> > serviceResponse = new ServiceResponse <List <GetUzivatelDto> >();

            try
            {
                Uzivatel uzivatel = _mapper.Map <Uzivatel>(novyUzivatel);
                await _context.Uzivatelia.AddAsync(uzivatel);

                await _context.SaveChangesAsync();

                serviceResponse.Data = (_context.Uzivatelia.Select(c => _mapper.Map <GetUzivatelDto>(c))).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }