示例#1
0
            // POST: api/Users
            public List <Colloborator> UpdateCollaborator(AddCollaborator Colab)
            {
                //this is for an error that it can serialize the data that we send through
                db.Configuration.ProxyCreationEnabled = false;
                try
                {
                    //here I assign all the user to a temp user and colab to temp colab
                    Colloborator newcolabs = Colab.getcolab;
                    User         newuser   = Colab.getusers;

                    //then we searh the user table for the id and update the information
                    User presentuser = db.Users.Where(i => i.Username == newuser.Username && i.Password == newuser.Password).FirstOrDefault();
                    presentuser = newuser;
                    db.SaveChanges();
                    //the we search see if its a collaborator if it is we change the colabinfromation aswell
                    Colloborator presentcolab = db.Colloborators.Where(i => i.Users == presentuser.ID).FirstOrDefault();
                    if (presentcolab != null)
                    {
                        presentcolab = newcolabs;
                        db.SaveChanges();
                    }

                    //then we the add the colab details to the system and id that we got from above
                    List <Colloborator> colabList = db.Colloborators.ToList();
                    return(colabList);
                }
                catch (Exception e)
                {
                    string mesage = e.Message;
                    throw;
                }
            }
示例#2
0
        public IHttpActionResult PutColloborator(int id, Colloborator colloborator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public IHttpActionResult GetColloborator(int id)
        {
            Colloborator colloborator = db.Colloborators.Find(id);

            if (colloborator == null)
            {
                return(NotFound());
            }

            return(Ok(colloborator));
        }
示例#4
0
        public IHttpActionResult PostColloborator(Colloborator colloborator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Colloborators.Add(colloborator);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = colloborator.ID }, colloborator));
        }
示例#5
0
        public IHttpActionResult DeleteColloborator(int id)
        {
            Colloborator colloborator = db.Colloborators.Find(id);

            if (colloborator == null)
            {
                return(NotFound());
            }

            db.Colloborators.Remove(colloborator);
            db.SaveChanges();

            return(Ok(colloborator));
        }
示例#6
0
            public IHttpActionResult GetColloborator(int id)
            {
                db.Configuration.ProxyCreationEnabled = false;
                Colloborator colloborator = db.Colloborators.Find(id);

                if (colloborator == null)
                {
                    return(NotFound());
                }
                User            tempuser = db.Users.Find(colloborator.Users);
                AddCollaborator temp     = new AddCollaborator();

                temp.getcolab = colloborator;
                temp.getusers = tempuser;
                return(Ok(temp));
            }