Esempio n. 1
0
        public int AddNewVersion(string id)
        {
            var existingSignal = _signalsRepository.GetLatestVersionOfSignalBySignalID(id);
            //if (existingSignal == null)
            //{
            //    return Content("<h1>" +"No Signal Matches this SignalID" + "</h1>");
            //}

            Signal signal = _signalsRepository.CopySignalToNewVersion(existingSignal);

            signal.VersionList = _signalsRepository.GetAllVersionsOfSignalBySignalID(signal.SignalID);

            try
            {
                _signalsRepository.AddOrUpdate(signal);
                var commentRepository = MOE.Common.Models.Repositories.MetricCommentRepositoryFactory.Create();
                foreach (var origVersionComment in existingSignal.Comments)
                {
                    MetricComment metricComment = new MetricComment
                    {
                        CommentText = origVersionComment.CommentText,
                        VersionID   = signal.VersionID,
                        SignalID    = existingSignal.SignalID,
                        TimeStamp   = origVersionComment.TimeStamp,
                    };
                    if (origVersionComment.MetricTypes != null)
                    {
                        metricComment.MetricTypeIDs = new List <int>();
                        foreach (var metricType in origVersionComment.MetricTypes)
                        {
                            metricComment.MetricTypeIDs.Add(metricType.MetricID);
                        }
                    }
                    commentRepository.AddOrUpdate(metricComment);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
            finally
            {
                AddSelectListsToViewBag(signal);
            }
            return(signal.VersionID);
        }