Esempio n. 1
0
        public IHttpActionResult Putusers(int id, users users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != users.id)
            {
                return(BadRequest());
            }

            db.Entry(users).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!usersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IQueryable <projects> Getprojects()
        {
            // below code up until return goes into post method route
            ProjectManager mngr       = new ProjectManager();
            var            projectObj = mngr.CreateNewProject(1, "testing", "12345", "testing method with overloads", 150, 155, 150000, 150, "blue");

            try { entities.projects.Add(projectObj); entities.SaveChanges(); }
            catch
            {
                Debug.WriteLine("error");
            }
            return(entities.projects);
        }
Esempio n. 3
0
        public void AddUserToTeam(string TeamName, int Teamlead_id, int[] User_ids)
        {
            using (scheduler_v2Entities db = new scheduler_v2Entities())
            {
                UserManager umngr     = new UserManager();
                var         teamClass = new teams
                {
                    name        = TeamName,
                    teamlead_id = Teamlead_id
                };
                db.teams.Add(teamClass);
                db.teams.Attach(teamClass);
                var teamlead = new user_teams
                {
                    team_id = teamClass.id,
                    user_id = Teamlead_id
                };
                db.teams.Add(teamClass);
                db.user_teams.Add(teamlead);

                foreach (int id in User_ids)
                {
                    users person    = umngr.GetUser(id);
                    var   user_team = new user_teams
                    {
                        team_id = teamClass.id,
                        user_id = id
                    };
                    db.user_teams.Add(user_team);
                }

                db.SaveChanges();
            }
        }
Esempio n. 4
0
        public IHttpActionResult CreateAccount(RegistrationDTO userInput)
        {
            TextResult  httpResponse = new TextResult("There is already an account with that name!", message);
            UserManager manager      = new UserManager();

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!manager.IsValidEmail(userInput.Email))
            {
                httpResponse.ChangeHTTPMessage("Enter valid email!", message);
                return(httpResponse); // HTTP response if accountname already exists
            }

            if (manager.CheckIfAccountNameExists(userInput.Username))
            {
                return(httpResponse);
            }

            if (manager.CheckIfEmailExists(userInput.Email))
            {
                httpResponse.ChangeHTTPMessage("Email already exists!", message); // If email exists, HTTP response
                return(httpResponse);
            }

            var accountObject = manager.CreateAccount(userInput.Username, userInput.Password, userInput.Email);

            try
            {
                entities.users.Add(accountObject);
                entities.SaveChanges();
            }
            catch
            {
                httpResponse.ChangeHTTPMessage("Failed to create account!", message); // HTTP response if fails to savechanges to DB
                return(httpResponse);
            }
            return(Ok()); // returns login token if registration succesfull
        }