예제 #1
0
        private ITProviderCredentials toUser(DbITProviderCredentials credential)
        {
            DbITProvider dbProvider = _context.ITProviders.Single(prov => prov.Username == credential.Username);

            if (dbProvider == null)
            {
                return(null);
            }
            DbContactInfo         contactInfo = _context.contactInfo.Single(contactInfo => contactInfo.Username == credential.Username);
            ITProvider            provider;
            List <DbTechnologies> technologies = new List <DbTechnologies>();

            technologies = _context.technologies.Where(technology => technology.Username == credential.Username).ToList <DbTechnologies>();
            provider     = dbProvider.toITProvider(contactInfo, technologies);

            ITProviderCredentials pc = new ITProviderCredentials(credential.Password, provider);

            return(pc);
        }
예제 #2
0
 public void toDbITProviderCredentials(ITProviderCredentials cr)
 {
     this.Username = cr.Provider.Username;
     this.Password = cr.Password;
 }
예제 #3
0
        public async Task <IActionResult> PutDbITProviderCredentials(string username, ITProviderCredentials credentials)
        {
            if (username != credentials.Provider.Username)
            {
                return(BadRequest());
            }
            DbITProviderCredentials dbCredentials = new DbITProviderCredentials();

            dbCredentials.toDbITProviderCredentials(credentials);

            DbITProvider          provider = new DbITProvider();
            List <DbTechnologies> techs    = provider.toDbITProvider(credentials.Provider);

            DbContactInfo ci = new DbContactInfo();

            ci.toDbContactInfo(credentials.Provider.ContactInfo, credentials.Provider.Username);

            List <DbTechnologies> toDeleteTechs = _context.technologies.Where(tec => tec.Username == username).ToList <DbTechnologies>();

            foreach (DbTechnologies t in toDeleteTechs)
            {
                _context.technologies.Remove(t);
            }
            await _context.SaveChangesAsync();

            foreach (DbTechnologies t in techs)
            {
                _context.technologies.Add(t);
            }



            _context.Entry(dbCredentials).State = EntityState.Modified;
            _context.Entry(provider).State      = EntityState.Modified;
            _context.Entry(ci).State            = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbITProviderCredentialsExists(username))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <ActionResult <DbITProviderCredentials> > PostDbITProviderCredentials(ITProviderCredentials credentials)
        {
            DbITProviderCredentials dbCredentials = new DbITProviderCredentials();

            dbCredentials.toDbITProviderCredentials(credentials);
            _context.ITProviderCredentials.Add(dbCredentials);

            DbITProvider          provider = new DbITProvider();
            List <DbTechnologies> techs    = provider.toDbITProvider(credentials.Provider);

            _context.ITProviders.Add(provider);
            foreach (DbTechnologies tec in techs)
            {
                _context.technologies.Add(tec);
            }

            DbContactInfo ci = new DbContactInfo();

            ci.toDbContactInfo(credentials.Provider.ContactInfo, credentials.Provider.Username);
            _context.contactInfo.Add(ci);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (DbITProviderCredentialsExists(credentials.Provider.Username))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetDbITProviderCredentials", new { id = credentials.Provider.Username }, credentials));
        }