@@ -137,148 +137,6 @@ protected override void Dispose(bool disposing)
137
137
base . Dispose ( disposing ) ;
138
138
}
139
139
140
- private bool activityExists ( int id )
141
- {
142
- return db . activity . Count ( e => e . activityId == id ) > 0 ;
143
- }
144
- }
145
- }
146
- using System ;
147
- using System . Collections . Generic ;
148
- using System . Data ;
149
- using System . Data . Entity ;
150
- using System . Data . Entity . Infrastructure ;
151
- using System . Linq ;
152
- using System . Net ;
153
- using System . Net . Http ;
154
- using System . Threading . Tasks ;
155
- using System . Web . Http ;
156
- using System . Web . Http . Description ;
157
- using Zenergy . Models ;
158
- using Zenergy . Services ;
159
-
160
- namespace Zenergy . Controllers . ApiControllers
161
- {
162
- [ Authorize ]
163
- public class activitiesController : ApiController
164
- {
165
- private ZenergyContext db = new ZenergyContext ( ) ;
166
- private ActivityService activityServices ;
167
-
168
- public activitiesController ( )
169
- {
170
- activityServices = new ActivityService ( db ) ;
171
- }
172
-
173
- // GET: api/activities
174
- public IQueryable < activity > Getactivity ( )
175
- {
176
- return db . activity ;
177
- }
178
-
179
- // GET: api/activities/5
180
- [ ResponseType ( typeof ( activity ) ) ]
181
- public IHttpActionResult Getactivity ( int id )
182
- {
183
- activity activity = db . activity . Find ( id ) ;
184
- if ( activity == null )
185
- {
186
- return NotFound ( ) ;
187
- }
188
-
189
- return Ok ( activity ) ;
190
- }
191
-
192
- // GET: api/activities/findByManagerId/5
193
- [ Route ( "api/activities/findByManagerId/{managerId}" ) ]
194
- [ HttpGet ]
195
- [ ResponseType ( typeof ( activity [ ] ) ) ]
196
- public async Task < IHttpActionResult > findActivitiesByManagerId ( int managerId )
197
- {
198
- activity [ ] activities = await activityServices . findActivitiesByManagerId ( managerId ) ;
199
- if ( activities == null )
200
- {
201
- return NotFound ( ) ;
202
- }
203
-
204
- return Ok ( activities ) ;
205
- }
206
-
207
- // PUT: api/activities/5
208
- [ ResponseType ( typeof ( void ) ) ]
209
- public IHttpActionResult Putactivity ( int id , activity activity )
210
- {
211
- if ( ! ModelState . IsValid )
212
- {
213
- return BadRequest ( ModelState ) ;
214
- }
215
-
216
- if ( id != activity . activityId )
217
- {
218
- return BadRequest ( ) ;
219
- }
220
-
221
- db . Entry ( activity ) . State = EntityState . Modified ;
222
-
223
- try
224
- {
225
- db . SaveChanges ( ) ;
226
- }
227
- catch ( DbUpdateConcurrencyException )
228
- {
229
- if ( ! activityExists ( id ) )
230
- {
231
- return NotFound ( ) ;
232
- }
233
- else
234
- {
235
- throw ;
236
- }
237
- }
238
-
239
- return StatusCode ( HttpStatusCode . NoContent ) ;
240
- }
241
-
242
- // POST: api/activities
243
- [ ResponseType ( typeof ( activity ) ) ]
244
- public IHttpActionResult Postactivity ( activity activity )
245
- {
246
- if ( ! ModelState . IsValid )
247
- {
248
- return BadRequest ( ModelState ) ;
249
- }
250
-
251
- db . activity . Add ( activity ) ;
252
- db . SaveChanges ( ) ;
253
-
254
- return CreatedAtRoute ( "DefaultApi" , new { id = activity . activityId } , activity ) ;
255
- }
256
-
257
- // DELETE: api/activities/5
258
- [ ResponseType ( typeof ( activity ) ) ]
259
- public IHttpActionResult Deleteactivity ( int id )
260
- {
261
- activity activity = db . activity . Find ( id ) ;
262
- if ( activity == null )
263
- {
264
- return NotFound ( ) ;
265
- }
266
-
267
- db . activity . Remove ( activity ) ;
268
- db . SaveChanges ( ) ;
269
-
270
- return Ok ( activity ) ;
271
- }
272
-
273
- protected override void Dispose ( bool disposing )
274
- {
275
- if ( disposing )
276
- {
277
- db . Dispose ( ) ;
278
- }
279
- base . Dispose ( disposing ) ;
280
- }
281
-
282
140
private bool activityExists ( int id )
283
141
{
284
142
return db . activity . Count ( e => e . activityId == id ) > 0 ;
0 commit comments