public ActionResult Create([Bind(Include = "VersionID, SignalId,CommentText, MetricIDs")] MetricComment metricComment) { metricComment.TimeStamp = DateTime.Now; ModelState.Clear(); metricComment.AllMetricTypes = null; if (metricComment.MetricTypeIDs == null) { metricComment.MetricTypeIDs = new List <int>(); } if (metricComment.MetricTypeIDs != null) { foreach (int metricID in metricComment.MetricIDs) { metricComment.MetricTypeIDs.Add(metricID); } } if (ModelState.IsValid) { try { commentRepository.Add(metricComment); } catch (Exception ex) { return(Content(ex.Message)); } return(PartialView("~/Views/Signals/EditorTemplates/MetricComment.cshtml", metricComment)); } return(View(metricComment)); }
public ActionResult CopyVersion(Signal signal) { //originalSignalVersion = SetDetectionTypes(originalSignalVersion); //MOE.Common.Models.Repositories.ISignalsRepository repository = // MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); //repository.AddOrUpdate(originalSignalVersion); Signal copyVersion = new Signal(); Signal originalSignalVersion = _signalsRepository.GetLatestVersionOfSignalBySignalID(signal.SignalID); if (originalSignalVersion != null) { copyVersion = Signal.CopyVersion(originalSignalVersion); copyVersion.VersionActionId = 4; copyVersion.Start = DateTime.Now; copyVersion.IPAddress = originalSignalVersion.IPAddress; copyVersion.Note = "Copy of Version " + originalSignalVersion.Note; } try { _signalsRepository.AddOrUpdate(copyVersion); var commentRepository = MOE.Common.Models.Repositories.MetricCommentRepositoryFactory.Create(); foreach (var origVersionComment in originalSignalVersion.Comments) { MetricComment metricComment = new MetricComment { CommentText = origVersionComment.CommentText, VersionID = copyVersion.VersionID, SignalID = originalSignalVersion.SignalID, TimeStamp = origVersionComment.TimeStamp, }; if (origVersionComment.MetricTypes != null) { metricComment.MetricTypeIDs = new List <int>(); foreach (var metricType in origVersionComment.MetricTypes) { metricComment.MetricTypeIDs.Add(metricType.MetricID); } } if (origVersionComment.MetricIDs != null) { metricComment.MetricIDs = (int[])origVersionComment.MetricIDs.Clone(); } metricComment.MetricTypes = origVersionComment.MetricTypes; //commentRepository.Add(metricComment); copyVersion.Comments.Add(metricComment); } _signalsRepository.AddOrUpdate(copyVersion); copyVersion = _signalsRepository.GetLatestVersionOfSignalBySignalID(copyVersion.SignalID); } catch (Exception ex) { return(Content("<h1>" + ex.Message + "</h1>")); } finally { AddSelectListsToViewBag(copyVersion); } return(PartialView("Edit", copyVersion)); }
public void AddOrUpdate(MetricComment metricComment) { var g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g != null) { try { db.Entry(g).CurrentValues.SetValues(metricComment); db.SaveChanges(); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.MetricCommentRepository"; error.Function = "AddOrUpdate"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { db.MetricComments.Add(metricComment); db.SaveChanges(); } }
public List <MetricType> GetMetricTypesByMetricComment(MetricComment metricComment) { var metricTypes = (from r in db.MetricTypes where metricComment.MetricTypeIDs.Contains(r.MetricID) select r).ToList(); return(metricTypes); }
public void Remove(MetricComment metricComment) { var g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g != null) { db.MetricComments.Remove(g); db.SaveChanges(); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MetricComment metricComment = commentRepository.GetMetricCommentByMetricCommentID(id.Value); if (metricComment == null) { return(HttpNotFound()); } return(View(metricComment)); }
public void Add(MetricComment metricComment) { var g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g == null) { if (metricComment.MetricTypes == null) { metricComment.MetricTypes = db.MetricTypes .Where(x => metricComment.MetricTypeIDs.Contains(x.MetricID)).ToList(); } try { db.MetricComments.Add(metricComment); db.SaveChanges(); } catch (DbEntityValidationException e) { var repository = ApplicationEventRepositoryFactory.Create(); var errorMessage = string.Empty; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { errorMessage += " Property:" + ve.PropertyName + " Error:" + ve.ErrorMessage; } } repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add", ApplicationEvent.SeverityLevels.Medium, errorMessage); throw new Exception(errorMessage); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add", ApplicationEvent.SeverityLevels.Medium, ex.Message); throw; } } else { AddOrUpdate(metricComment); } }
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); }
public ActionResult Create(string versionId) { MOE.Common.Models.Repositories.ISignalsRepository signalsRepository = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); Signal signal = signalsRepository.GetSignalVersionByVersionId(Convert.ToInt32(versionId)); List <MOE.Common.Models.MetricType> allMetricTypes = metricTyperepository.GetAllToDisplayMetrics(); MOE.Common.Models.MetricComment mc = new MetricComment(); mc.Signal = signal; mc.AllMetricTypes = allMetricTypes; if (mc.MetricTypeIDs != null) { mc.MetricTypes = metricTyperepository.GetMetricTypesByMetricComment(mc); } return(PartialView(mc)); }
public List <MetricType> GetMetricTypesByMetricComment(MetricComment metricComment) { throw new NotImplementedException(); }