public EvaluationTool Update(UpdateEvaluationToolCommand command) { var evaluationTool = _repository.GetOne(command.Id); if (!string.IsNullOrEmpty(command.Author)) { evaluationTool.ChangeAuthor(command.Author); } if (!string.IsNullOrEmpty(command.Name)) { evaluationTool.ChangeName(command.Name); } if (command.Type != 0) { evaluationTool.ChangeType(command.Type); } if (command.Question.Count > 0) { foreach (var question in command.Question) { evaluationTool.AddQuestion(question); } } _repository.Update(evaluationTool); if (Commit()) { return(evaluationTool); } return(null); }
public Task <HttpResponseMessage> Put([FromBody] dynamic body) { var listQuestion = _serviceQuestion.AddToEvaluationTool(body.question, (ETypeEvaluationTool)body.type); var commandEvaluationTool = new UpdateEvaluationToolCommand( Guid.Parse((string)body.id), (string)body.name, (ETypeEvaluationTool)body.type, listQuestion ); _serviceQuestion.CheckQuestionRemoved(listQuestion, Guid.Parse((string)body.id)); var evaluationTool = _serviceEvaluationTool.Update(commandEvaluationTool); return(CreateResponse(HttpStatusCode.Created, evaluationTool)); }
public Task <HttpResponseMessage> Fill([FromBody] dynamic body) { if (body.role == "Coachee") { var commandFilledTool = new UpdateFilledToolCoacheeCommand( Guid.Parse((string)body.id), DateTime.Now, Guid.Parse((string)body.idEvaluationTool), Guid.Parse((string)body.idCoachee) ); var filledTool = _serviceFilledToolCoachee.Update(commandFilledTool); } else if (body.role == "Coach") { var commandFilledTool = new UpdateFilledToolCoachCommand( Guid.Parse((string)body.id), DateTime.Now, Guid.Parse((string)body.idEvaluationTool), Guid.Parse((string)body.idCoach) ); var filledTool = _serviceFilledToolCoach.Update(commandFilledTool); } else { return(CreateResponse(HttpStatusCode.BadRequest, null)); } var listQuestion = _serviceQuestion.AddToEvaluationTool(body.evaluationTool.question, (ETypeEvaluationTool)body.evaluationTool.type); var commandEvaluationTool = new UpdateEvaluationToolCommand( Guid.Parse((string)body.evaluationTool.id), (string)body.evaluationTool.name, (ETypeEvaluationTool)body.evaluationTool.type, listQuestion ); var evaluationTool = _serviceEvaluationTool.Update(commandEvaluationTool); return(CreateResponse(HttpStatusCode.OK, evaluationTool)); }