コード例 #1
0
        public IHttpActionResult EditExistingBug(int id, EditBindingModel editingModel)
        {
            if (editingModel == null)
            {
                return this.BadRequest("Invalid model data.");
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var bug = db.Bugs.FirstOrDefault(b => b.Id == id);

            if (bug == null)
            {
                return this.NotFound();
            }

            if (editingModel.Title != null)
            {
                bug.Title = editingModel.Title;
            }

            if (editingModel.Description != null)
            {
                bug.Description = editingModel.Description;
            }

            if (editingModel.Status != null)
            {
                if (editingModel.Status == "Open") { bug.Status = Status.Open; }
                if (editingModel.Status == "InProgress") { bug.Status = Status.InProgress; }
                if (editingModel.Status == "Fixed") { bug.Status = Status.Fixed; }
                if (editingModel.Status == "Closed") { bug.Status = Status.Closed; }
            }

            db.SaveChanges();

            return this.Ok(new {Message = "Bug #" + bug.Id + " patched."});
        }