Ejemplo n.º 1
0
        public async Task <Guid> CreateProject(string title)
        {
            if (title == null || title == "")
            {
                return(Guid.Empty);
            }

            PostProjIn body = new PostProjIn()
            {
                Title = title
            };

            var response = await api.MakeRequest <PostProjOut, PostProjIn>(MethodType.POST, "/api/projects", body);

            var code = response.Item2;

            switch (code)
            {
            case System.Net.HttpStatusCode.Created:
                string idRaw = response.Item1.Id;
                return(Guid.Parse(idRaw));

            default:
                return(Guid.Empty);
            }
        }
        public ActionResult <PostProjOut> CreateProject(PostProjIn projectTitle)
        {
            if (projectTitle == null || projectTitle.Title == "")
            {
                return(BadRequest());
            }

            User    currentUser = (User)HttpContext.Items["currentUser"];
            Project project     = new Project()
            {
                Id          = Guid.NewGuid(),
                Title       = projectTitle.Title,
                DateCreated = DateTime.Now,
                Owner       = currentUser.Id,
                Members     = new List <Guid>(),
                Tasks       = new List <Guid>()
            };

            IResource resources = new Resource();
            IDbClient db        = new DbClient(resources.GetString("db_base_path"));

            db.InsertRecord(resources.GetString("db_projects_path"), project);

            var projects = currentUser.Projects;

            projects.Add(project.Id);
            db.UpdateRecord <User, List <Guid> >(resources.GetString("db_users_path"), currentUser.Id, "Projects", projects);

            PostProjOut responseBody = new PostProjOut()
            {
                Id = project.Id
            };

            return(CreatedAtAction("createProject", responseBody));
        }