示例#1
0
        public async Task<IHttpActionResult> PutWorkItem(UpdateWorkItemViewModel workItemvm)
        {
            if(!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                await _workItemManager.UpdateWorkItem(workItemvm);
            }
            catch(Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        /// <summary>
        /// Updates a WorkItem using details in the given model
        /// </summary>
        /// <param name="uwvm">Model containing details of the WorkItem to update</param>
        public async Task UpdateWorkItem(UpdateWorkItemViewModel uwvm)
        {
            // Find the WorkItem and update its properties
            var workItem = await Db.WorkItems.FindAsync(uwvm.Id);
            if(workItem == null)
            {
                throw new Exception("No WorkItem with id: " + uwvm.Id);
            }

            // Update properties
            workItem.Title = uwvm.Title;
            workItem.Description = uwvm.Description;
            workItem.DueDate = uwvm.DueDate;
            workItem.MaxPoints = uwvm.MaxPoints;
            workItem.Type = uwvm.Type;
            _db.Entry(workItem).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch(DbUpdateConcurrencyException)
            {
                if(!WorkItemExists(workItem.Id))
                {
                    throw new Exception("No workitem with id: " + workItem.Id);
                }
            }
        }