Пример #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 ActionResult HandleAddCollaborator(
            [System.Web.Http.FromBody] Guid plan,
            [System.Web.Http.FromBody] string collaboratorUsername,
            [System.Web.Http.FromBody] string collaboratorRole)
        {
            if (string.IsNullOrEmpty(collaboratorUsername))
            {
                throw new ArgumentNullException(nameof(collaboratorUsername));
            }

            if (string.IsNullOrEmpty(collaboratorRole))
            {
                throw new ArgumentNullException(nameof(collaboratorRole));
            }


            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.Values.ToString()));
            }


            var planId = new PlanId(plan);

            var command = new AddCollaborator(planId, collaboratorUsername, collaboratorRole);

            Wiring.Proxy.SendCommand(command);

            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = command
            });
        }
Пример #3
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));
            }