예제 #1
0
        // PUT api/Mission/5
        public async Task<IHttpActionResult> PutMission(int id, Mission mission)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != mission.Id)
            {
                return BadRequest();
            }

            _db.Entry(mission).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MissionExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public async Task<IHttpActionResult> PostMission(Mission mission)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _db.Missions.Add(mission);
            await _db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = mission.Id }, mission);
        }
예제 #3
0
        public async Task<ActionResult> Edit(Mission mission)
        {
            if (ModelState.IsValid)
            {
                db.Entry(mission).State = EntityState.Modified;

                if (mission.MediaIds != null)
                {
                    mission.Media = (from t in db.Medias where mission.MediaIds.Contains(t.Id) select t).ToList();
                }

                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            ViewBag.ListOfMedia = await db.Medias.ToListAsync();

            return View(mission);
        }