public VARIATION_ITEMProjection() { VARIATION_ITEM = new VARIATION_ITEM(); BASELINE_ITEMJoinRATE = new BASELINE_ITEMProjection(); VARIATION_ITEM.ACTION = VariationAction.NoAction; }
/// <summary> /// Approves an entity. /// Since CollectionViewModelBase is a POCO view model, an the instance of this class will also expose the ApproveCommand property that can be used as a binding source in views. /// </summary> /// <param name="projectionEntity">An entity to approve.</param> public void Approve(VARIATION entity) { string errorMessage = string.Empty; if (entity == null) { errorMessage = "Nothing within variation to approve"; } else if (loadPROJECT == null) { errorMessage = "Project doesn't exists"; } else if (loadBASELINE == null) { errorMessage = "Live baseline doesn't exists"; } else if (loadPROGRESS == null) { errorMessage = "Live progress doesn't exists"; } if (errorMessage != string.Empty) { MessageBoxService.ShowMessage(errorMessage); return; } IBluePrintsEntitiesUnitOfWork unitOfWork = bluePrintsUnitOfWorkFactory.CreateUnitOfWork(); BASELINE LiveBASELINE = loadBASELINE; IEnumerable <VARIATION_ITEM> editVARIATION_ITEMS = unitOfWork.VARIATION_ITEMS.Where(x => x.GUID_VARIATION == entity.GUID).ToArray().AsEnumerable(); IEnumerable <BASELINE_ITEM> addBASELINE_ITEMS = unitOfWork.BASELINE_ITEMS.Where(x => x.GUID_VARIATION == entity.GUID && x.GUID_BASELINE == null).ToArray().AsEnumerable(); IQueryable <BASELINE_ITEM> editBASELINE_ITEMS = loaderCollection.GetCollection <BASELINE_ITEM>(); IEnumerable <PROGRESS_ITEM> livePROGRESS_ITEMS = loaderCollection.GetCollection <PROGRESS_ITEM>(); BASELINE newBASELINE = new BASELINE(); DataUtils.ShallowCopy(newBASELINE, LiveBASELINE); newBASELINE.GUID = Guid.Empty; newBASELINE.REVISION = ((char)(LiveBASELINE.REVISION.Last() + 1)).ToString(); //not saving new baseline as live yet because editBASELINE_ITEMS still depends on the current live baseline for copying BASELINE_ITEMS newBASELINE.STATUS = BaselineStatus.Superseded; CollectionViewModel <BASELINE, BASELINE, Guid, IBluePrintsEntitiesUnitOfWork> BASELINECollectionViewModel = (CollectionViewModel <BASELINE, BASELINE, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <BASELINE>(); CollectionViewModel <BASELINE_ITEM, BASELINE_ITEM, Guid, IBluePrintsEntitiesUnitOfWork> BASELINE_ITEMCollectionViewModel = (CollectionViewModel <BASELINE_ITEM, BASELINE_ITEM, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <BASELINE_ITEM>(); BASELINECollectionViewModel.Save(newBASELINE); entity.APPROVED = DateTime.Now; entity.GUID_ORIBASELINE = LiveBASELINE.GUID; entity.GUID_BASELINE = newBASELINE.GUID; MainViewModel.Save(entity); ObservableCollection <BASELINE_ITEM> newBASELINE_ITEMS = new ObservableCollection <BASELINE_ITEM>(); foreach (BASELINE_ITEM editBASELINE_ITEM in editBASELINE_ITEMS) { BASELINE_ITEM copyBASELINE_ITEM = new BASELINE_ITEM(); DataUtils.ShallowCopy(copyBASELINE_ITEM, editBASELINE_ITEM); VARIATION_ITEM editVARIATION_ITEM = editVARIATION_ITEMS.FirstOrDefault(x => x.GUID_ORIBASEITEM == editBASELINE_ITEM.GUID_ORIGINAL); if (editVARIATION_ITEM != null) { if (editVARIATION_ITEM.ACTION == VariationAction.Cancel) { decimal progressItemEARNED_UNITS = livePROGRESS_ITEMS.Where(x => x.GUID_ORIBASEITEM == editBASELINE_ITEM.GUID_ORIGINAL).Sum(y => y.EARNED_UNITS); if (progressItemEARNED_UNITS == 0) { copyBASELINE_ITEM.DC_HOURS = -1 * copyBASELINE_ITEM.ESTIMATED_HOURS; } else { copyBASELINE_ITEM.DC_HOURS = -1 * (copyBASELINE_ITEM.TOTAL_HOURS - progressItemEARNED_UNITS); } } else if (editVARIATION_ITEM.ACTION == VariationAction.Append) { copyBASELINE_ITEM.DC_HOURS += editVARIATION_ITEM.VARIATION_UNITS; } if (editVARIATION_ITEM.ACTION != VariationAction.NoAction) { copyBASELINE_ITEM.GUID_VARIATION = entity.GUID; } } copyBASELINE_ITEM.GUID = Guid.Empty; copyBASELINE_ITEM.GUID_BASELINE = newBASELINE.GUID; newBASELINE_ITEMS.Add(copyBASELINE_ITEM); } foreach (BASELINE_ITEM addBASELINE_ITEM in addBASELINE_ITEMS) { BASELINE_ITEM newBASELINE_ITEM = new BASELINE_ITEM(); DataUtils.ShallowCopy(newBASELINE_ITEM, addBASELINE_ITEM); newBASELINE_ITEM.GUID = Guid.Empty; newBASELINE_ITEM.GUID_BASELINE = newBASELINE.GUID; newBASELINE_ITEM.INTERNAL_NUM = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(this.loadPROJECT, newBASELINE_ITEM, newBASELINE_ITEMS, addBASELINE_ITEM.AREA, addBASELINE_ITEM.DISCIPLINE, addBASELINE_ITEM.DOCTYPE); VARIATION_ITEM editVARIATION_ITEM = editVARIATION_ITEMS.First(x => x.GUID_ORIBASEITEM == newBASELINE_ITEM.GUID_ORIGINAL); newBASELINE_ITEM.DC_HOURS = editVARIATION_ITEM.VARIATION_UNITS; newBASELINE_ITEM.GUID_VARIATION = entity.GUID; newBASELINE_ITEMS.Add(newBASELINE_ITEM); } foreach (BASELINE_ITEM newBASELINE_ITEM in newBASELINE_ITEMS) { BASELINE_ITEMCollectionViewModel.Save(newBASELINE_ITEM); } LiveBASELINE.STATUS = BaselineStatus.Superseded; BASELINECollectionViewModel.Save(LiveBASELINE); newBASELINE.STATUS = BaselineStatus.Live; BASELINECollectionViewModel.Save(newBASELINE); }