// POST api/programs
        public HttpResponseMessage Post(ProgramPublic newProgram)
        {
            if (ModelState.IsValid)
            {
                // Add the new program
                var p = r.AddNew(newProgram);

                // Build the response object
                var response = Request.CreateResponse<ProgramFull>(HttpStatusCode.Created, p);

                // Set the Location header
                // The "new Uri" object constructor needs a string argument
                // The ApiController.Url property provides that
                // Its Link() method takes two arguments...
                // A route name, which can be seen in App_Start/WebApiConfig.cs, and
                // A route value, which substitutes for the {id} placeholder
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = p.Id }));

                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add new
        /// </summary>
        /// <param name="newProgram">New ProgramPublic object</param>
        /// <returns>ProgramFull object</returns>
        public ProgramFull AddNew(ProgramPublic newProgram)
        {
            // Add the new Program object
            var p = ds.Programs.Add(Mapper.Map<Models.Program>(newProgram));
            ds.SaveChanges();

            return Mapper.Map<ViewModels.ProgramFull>(p);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add new
        /// </summary>
        /// <param name="newProgram">New ProgramPublic object</param>
        /// <returns>ProgramFull object</returns>
        public ProgramFull AddNew(ProgramPublic newProgram)
        {
            // Add the new Program object
            var p = ds.Programs.Add(Mapper.Map <Models.Program>(newProgram));

            ds.SaveChanges();

            return(Mapper.Map <ViewModels.ProgramFull>(p));
        }