public ActionResult ViewStatus(int ReleaseId, int CPID = 0, bool IsDraft = true) { using (ReleaseCPRepository db = new ReleaseCPRepository()) { status = new StatusVM(); status.ReleaseID = ReleaseId; NavigationBreadCrums.SetSesionReleaseID(ReleaseId); List <StatusAreaText> statusAreaTexts; using (IStatusAreaTextRepository dbStatusAreaText = new StatusAreaTextRepository()) { statusAreaTexts = dbStatusAreaText.Where(a => a.ReleaseID == ReleaseId).ToList(); } using (IStatusTextRepository dbStatusText = new StatusTextRepository()) { StatusText statusText = dbStatusText.Where(a => a.ReleaseID == ReleaseId).FirstOrDefault(); if (statusText != null) { status.StatusText = new StatusTextVM() { ReleaseID = statusText.ReleaseID, HighLightText = statusText.HighLightText } } ; } using (IReleaseChecklistAnswerRepository dbChecklist = new ReleaseChecklistAnswerRepository()) { status.AreaScores = dbChecklist.GetStatus(ReleaseId).Select(q => new AreaScoreVM() { AreaID = q.Area.AreaID, ReleaseID = ReleaseId, Name = q.Area.Name, Score = q.Score, ScoreStatus = IndicatorList.First(i => q.Score >= i.Min && q.Score < i.Max).ScoreIMG, Trand = q.LastScore != null ? TrandCalculation(q.Score, (double)q.LastScore) : Trand.none, StatusAreaText = statusAreaTexts != null && statusAreaTexts.Where(s => s.AreaID == q.Area.AreaID).FirstOrDefault() != null ? statusAreaTexts.Where(s => s.AreaID == q.Area.AreaID).FirstOrDefault().AreaText : "", SubAreaScors = q.SubAreaScores.Select(s => new SubAreaScoreVM() { Name = s.SubArea.Name, Score = s.Score, ScoreStatus = IndicatorList.First(i => s.Score >= i.Min && s.Score < i.Max).ScoreIMG, SubAreaID = s.SubArea.SubAreaID, Trand = s.LastScore != null ? TrandCalculation(s.Score, (double)s.LastScore) : Trand.none, }).ToList() }).ToList(); } } status.Details = new ReleaseGeneralDetails() { ReleaseID = ReleaseId }; status.CPID = CPID; status.IsDraft = IsDraft; return(View(status)); }
public async Task <int> SaveStatus(StatusVM status) { try { int count = 0; StatusText statusText; using (IStatusTextRepository db = new StatusTextRepository()) { statusText = db.Where(a => a.ReleaseID == status.StatusText.ReleaseID).FirstOrDefault(); if (statusText != null)//edit { if (statusText.HighLightText != status.StatusText.HighLightText) { statusText.HighLightText = status.StatusText.HighLightText; db.Edit(statusText); count += await db.SaveAsync((WindowsPrincipal)User); } } else//create { statusText = new StatusText(); statusText.ReleaseID = status.StatusText.ReleaseID; statusText.HighLightText = status.StatusText.HighLightText; db.Add(statusText); count += await db.SaveAsync((WindowsPrincipal)User); } } if (status.AreaScores != null) { using (IStatusAreaTextRepository db = new StatusAreaTextRepository()) { status.AreaScores.ForEach(s => { var statusArea = db.Where(a => a.AreaID == s.AreaID && a.ReleaseID == status.StatusText.ReleaseID).FirstOrDefault(); if (statusArea != null)//edit { if (statusArea.AreaText != s.StatusAreaText) { statusArea.AreaText = s.StatusAreaText; db.Edit(statusArea); } } else//create { statusArea = new StatusAreaText() { AreaID = s.AreaID, ReleaseID = status.StatusText.ReleaseID, AreaText = s.StatusAreaText }; db.Add(statusArea); } }); count += await db.SaveAsync((WindowsPrincipal)User); } } return(count); } catch (Exception ex) { throw; } }