Ejemplo n.º 1
0
        public void Put( ToDoTask task )
        {
            var original = context.Tasks
                .SingleOrDefault( ( item ) => item.Id == task.Id );

            if ( original == null )
            {
                throw new HttpException( 404, "The database doesn't contains this item" );
            }

            context.Entry( original ).CurrentValues.SetValues( task );
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post( ToDoTask task )
        {
            if( task == null )
            {
                throw new HttpException( 400 , "Task cannot be null" );
            }

            task.UserName = WebSecurity.CurrentUserName;
            //task.Date = DateTime.Now;
            context.Tasks.Add( task );
            context.SaveChanges();

            return Request.CreateResponse<ToDoTask>( HttpStatusCode.OK , task );
        }