/// <summary> /// Creates the assignment. /// </summary> /// <param name="assignmentViewModel">The assignment view model.</param> public void CreateAssignment(AssignmentViewModel assignmentViewModel, int?userId = null) { try { if (assignmentViewModel != null) { Assignment assignment = ObjectMapper.Map <AssignmentViewModel, Model.Entities.Assignment>(assignmentViewModel); assignment = AssignmentManager.Add(assignment); if (assignment != null) { List <string> associations = new List <string>(); associations.Add("CourseModules"); associations.Add("CourseModules.Course"); associations.Add("CourseModules.Course.CourseRegistrations"); var module = ModuleManager.FindAll(associations).Where(m => m.Id.Equals(assignment.ModuleId)).FirstOrDefault(); List <Message> messages = new List <Message>(); messages = StudentMessageViewModelFactory.CreateTeacherAssignmentMessages(module, assignment, userId); MessageManager.AddMessages(messages); } } } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing); } }
public IActionResult Post([FromBody] Assignment assignment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Assignment newAssignment = assignmentManager.Add(assignment); return(Created($"assignments/{newAssignment.AgentId}/{newAssignment.RepId}/{newAssignment.PeriodId}", newAssignment)); } catch (Exception ex) { logger.LogError($"Failed to insert assignment: {ex}"); return(BadRequest(config["Error:Default"])); } }