Ejemplo n.º 1
0
        public ResponseMessage <Assessment> UpdateAssessment(Assessment assessment, User user)
        {
            ResponseMessage <Assessment> assessmentResult = null;

            try
            {
                //consulta o cliente
                Assessment assessmentDb = Find(assessment).Object;

                if (assessmentDb != null)
                {
                    assessmentDb.State = EnmAssessmentState.Complete;

                    //update assessent
                    _repository.Update(assessmentDb);

                    string assessmentJson = JsonConvert.SerializeObject(assessmentDb, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                        NullValueHandling     = NullValueHandling.Ignore
                    });

                    //criar o histórico
                    var assessmentHistory = new AssessmentVersion()
                    {
                        IdAssessment   = assessmentDb.IdAssessment,
                        ChangeDate     = DateTime.Now,
                        Type           = EnmAssessmentVersion.AssessmentComplete,
                        IdUser         = user.IdUser,
                        Email          = user.Email,
                        Total          = assessmentDb.Total,
                        AssessmentData = assessmentJson,
                        Version        = assessmentDb.Version
                    };

                    //adicionar histórico
                    _repository.Add(assessmentHistory);

                    //commit
                    _repository.SaveChanges();

                    //objeto de retorno
                    assessmentResult = ResponseMessage <Assessment> .Ok(assessment);
                }
            }
            catch (Exception ex)
            {
                assessmentResult = ResponseMessage <Assessment> .Fault(ex.StackTrace);
            }

            return(assessmentResult);
        }
Ejemplo n.º 2
0
        public ResponseMessage <bool> CreateVersion(Assessment assessment, User user)
        {
            ResponseMessage <bool> responseMessage = null;

            try
            {
                Assessment assessmentDb = Find(assessment).Object;

                if (assessmentDb == null || assessmentDb.State != EnmAssessmentState.Complete)
                {
                    return(ResponseMessage <bool> .Fault("Orçamento não encontrado."));
                }

                assessmentDb.Version += 1;
                assessmentDb.State    = EnmAssessmentState.InProgress;

                string assessmentJson = JsonConvert.SerializeObject(assessmentDb, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    NullValueHandling     = NullValueHandling.Ignore
                });

                //criar o histórico
                var assessmentHistory = new AssessmentVersion()
                {
                    IdAssessment   = assessmentDb.IdAssessment,
                    ChangeDate     = DateTime.Now,
                    Type           = EnmAssessmentVersion.NewVersion,
                    IdUser         = user.IdUser,
                    Email          = user.Email,
                    Total          = assessmentDb.Total,
                    AssessmentData = assessmentJson,
                    Version        = assessmentDb.Version
                };

                //adicionar histórico
                _repository.Add(assessmentHistory);

                _repository.Update(assessmentDb);

                _repository.SaveChanges();


                responseMessage = ResponseMessage <bool> .Ok(true);
            }
            catch (Exception ex)
            {
                responseMessage = ResponseMessage <bool> .Fault(ex.StackTrace);
            }

            return(responseMessage);
        }