Example #1
0
        public async Task <IActionResult> PutDbCustomerCredentials(string username, CustomerCredentials credentials)
        {
            if (username != credentials.Customer.Username)
            {
                return(BadRequest());
            }

            DbCustomer customer = new DbCustomer();

            customer.toDbCustomer((Customer)credentials.Customer);
            _context.Entry(customer).State = EntityState.Modified;

            DbContactInfo ci = new DbContactInfo();

            ci.toDbContactInfo(credentials.Customer.ContactInfo, username);
            _context.Entry(ci).State = EntityState.Modified;

            DbCustomerCredentials dbCustomerCredentials = new DbCustomerCredentials();

            dbCustomerCredentials.toDbCustomerCredentials(credentials);
            _context.Entry(dbCustomerCredentials).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <DbCustomerCredentials> > PostDbCustomerCredentials(CustomerCredentials credentials)
        {
            DbCustomerCredentials dbCustomerCredentials = new DbCustomerCredentials();

            dbCustomerCredentials.toDbCustomerCredentials(credentials);
            _context.customerCredentials.Add(dbCustomerCredentials);

            DbCustomer cust = new DbCustomer();

            cust.toDbCustomer((Customer)credentials.Customer);
            _context.customers.Add(cust);

            DbContactInfo ci = new DbContactInfo();

            ci.toDbContactInfo(credentials.Customer.ContactInfo, credentials.Customer.Username);
            _context.contactInfo.Add(ci);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (DbCustomerCredentialsExists(dbCustomerCredentials.Username))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetDbCustomerCredentials", new { id = credentials.Customer.Username }, credentials));
            //hi
        }
Example #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());
        }
Example #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));
        }
Example #5
0
        public static void init(UserContext context)
        {
            //context.Database.EnsureCreated();

            /*List<string> techs = new List<string>();
             * techs.Add("Java");
             * techs.Add("C#");
             * techs.Add("C++");
             * techs.Add("Web Design");
             * techs.Add("Mobile apps");
             * ITProviderCredentials user = new ITProviderCredentials("147258", new ITProvider("ralu79", "Raluca-Elena Petrovici", "Find a flaw. I dare you.", 5, 10, techs, "individual",
             *  new ContactInfo("Kollegievaenget 5", "12345678", "*****@*****.**")));
             * techs.RemoveAt(4);
             * ITProviderCredentials user2 = new ITProviderCredentials("258147", new ITProvider("leksi12", "Aleksandra Angelova Aleksandrova", "Everything is better with Christmas decorations!!",
             *  5, 10, techs, "individual", new ContactInfo("Mollersgade 12", "12345678", "*****@*****.**")));
             * ITProviderCredentials user3 = new ITProviderCredentials("987654", new ITProvider("karla7", "Karla Jajic", "Got my facts on point.",
             *  5, 10, techs, "individual", new ContactInfo("Amaliegade 8", "12345678", "*****@*****.**")));
             * ITProviderCredentials user4 = new ITProviderCredentials("321654", new ITProvider("lenaB", "Lena Bojanowska", "A little party never killed anyone.",
             *  5, 10, techs, "individual", new ContactInfo("Hybenvej 10", "12345678", "*****@*****.**")));
             *
             * DbITProvider dbProvider = context.ITProviders.Find(user.provider.username);
             * context.ITProviders.Remove(dbProvider);
             * DbITProvider dbProvider4 = context.ITProviders.Find(user4.provider.username);
             * context.ITProviders.Remove(dbProvider4);
             * DbITProvider dbProvider2 = context.ITProviders.Find(user2.provider.username);
             * context.ITProviders.Remove(dbProvider2);
             * DbITProvider dbProvider3 = context.ITProviders.Find(user3.provider.username);
             * context.ITProviders.Remove(dbProvider3);
             * context.SaveChanges();
             *
             * DbITProviderCredentials cr = new DbITProviderCredentials();
             * DbITProviderCredentials cr2 = new DbITProviderCredentials();
             * DbITProviderCredentials cr3 = new DbITProviderCredentials();
             * DbITProviderCredentials cr4 = new DbITProviderCredentials();
             * cr.toDbITProviderCredentials(user);
             * cr2.toDbITProviderCredentials(user2);
             * cr3.toDbITProviderCredentials(user3);
             * cr4.toDbITProviderCredentials(user4);
             *
             * context.ITProviderCredentials.Add(cr);
             * context.ITProviderCredentials.Add(cr2);
             * context.ITProviderCredentials.Add(cr4);
             * context.SaveChanges();
             *
             * DbITProvider p = new DbITProvider();
             * DbITProvider p2 = new DbITProvider();
             * DbITProvider p3 = new DbITProvider();
             * DbITProvider p4 = new DbITProvider();
             * p.toDbITProvider(user.provider);
             * p2.toDbITProvider(user2.provider);
             * p3.toDbITProvider(user3.provider);
             * p4.toDbITProvider(user4.provider);
             *
             * context.ITProviders.Add(p);
             * context.ITProviders.Add(p2);
             * context.ITProviders.Add(p3);
             * context.ITProviders.Add(p4);
             * context.SaveChanges();
             *
             * DbContactInfo ci = new DbContactInfo();
             * DbContactInfo ci2 = new DbContactInfo();
             * DbContactInfo ci3 = new DbContactInfo();
             * DbContactInfo ci4 = new DbContactInfo();
             * ci.toDbContactInfo(user.provider.getContactInfo(), user.provider.username);
             * ci2.toDbContactInfo(user2.provider.getContactInfo(), user2.provider.username);
             * ci3.toDbContactInfo(user3.provider.getContactInfo(), user3.provider.username);
             * ci4.toDbContactInfo(user4.provider.getContactInfo(), user4.provider.username);
             *
             * context.contactInfo.Add(ci);
             * context.contactInfo.Add(ci2);
             * context.contactInfo.Add(ci3);
             * context.contactInfo.Add(ci4);
             * context.SaveChanges();
             *
             * foreach (string s in (user.provider).technologies)
             * {
             *  DbTechnologies t = new DbTechnologies();
             *  t.toDbTechnology(user.provider.username, s);
             *  context.technologies.Add(t);
             *  context.SaveChanges();
             * }
             *
             * foreach (string s in (user2.provider).technologies)
             * {
             *  DbTechnologies t = new DbTechnologies();
             *  t.toDbTechnology(user2.provider.username, s);
             *  context.technologies.Add(t);
             *  context.SaveChanges();
             * }
             *
             * foreach (string s in (user3.provider).technologies)
             * {
             *  DbTechnologies t = new DbTechnologies();
             *  t.toDbTechnology(user3.provider.username, s);
             *  context.technologies.Add(t);
             *  context.SaveChanges();
             * }
             *
             * foreach (string s in (user4.provider).technologies)
             * {
             *  DbTechnologies t = new DbTechnologies();
             *  t.toDbTechnology(user4.provider.username, s);
             *  context.technologies.Add(t);
             *  context.SaveChanges();
             * }*/

            CustomerCredentials c1 = new CustomerCredentials("kiril", new Customer("kiril21", "Kiril Iliev", "Rakiaaa", new ContactInfo("Amaliegade 20", "74684166", "*****@*****.**")));
            CustomerCredentials c2 = new CustomerCredentials("zoly", new Customer("zolyphoto", "Zoltan Vegh", "English m**********r, do you speak it?", new ContactInfo("Kollegievaenget 2", "77788899", "*****@*****.**")));
            CustomerCredentials c3 = new CustomerCredentials("harry", new Customer("justHarry", "Just Harry", "I like tea", new ContactInfo("Chr M Ostergaards Vej 5", "75723641", "*****@*****.**")));
            CustomerCredentials c4 = new CustomerCredentials("dovydas", new Customer("dovydass", "Dovydas", "Present", new ContactInfo("Kollegievaenget 10", "94758933", "*****@*****.**")));

            List <CustomerCredentials> list = new List <CustomerCredentials>();

            list.Add(c1);
            list.Add(c2);
            list.Add(c3);
            list.Add(c4);

            foreach (CustomerCredentials c in list)
            {
                DbCustomerCredentials credentials = new DbCustomerCredentials();
                credentials.toDbCustomerCredentials(c);

                DbCustomer customer = new DbCustomer();
                customer.toDbCustomer(c.Customer);

                DbContactInfo ci = new DbContactInfo();
                ci.toDbContactInfo(c.Customer.ContactInfo, c.Customer.Username);

                context.customerCredentials.Add(credentials);
                context.customers.Add(customer);
                context.contactInfo.Add(ci);
            }
            context.SaveChanges();
        }