public bool UpdateEntity(EntityFinanceSummary entity, List<EntityItemExpens> entityItemExpenses ) { if (entity.EntityFinanceSummaryID == -1) { int EntityFinanceSummaryID = UpdateEntitySummary(entity); foreach(EntityItemExpens entityItemExpense in entityItemExpenses) { entityItemExpense.EntityFinanceSummaryID = EntityFinanceSummaryID; orgMaintEntitiesContext.EntityItemExpenses.Add(entityItemExpense); } } orgMaintEntitiesContext.SaveChanges(); return true; }
public int UpdateEntitySummary(EntityFinanceSummary entity) { int newEntityFinanceSummaryID = -1; decimal budgetRequired = 0; EntityFinanceSummary updateEntityRecord = null; if (entity.EntityFinanceSummaryID == -1) { updateEntityRecord = new EntityFinanceSummary { EntityFinanceSummaryID = entity.EntityFinanceSummaryID, EntityName = entity.EntityName, BudgetAllocated = entity.BudgetAllocated, BudgetRequired = entity.BudgetRequired, BudgetUsed = entity.BudgetUsed, EntityCategory = entity.EntityCategory, Priority = entity.Priority, DateUpdated = DateTime.Now, Comments = entity.Comments }; orgMaintEntitiesContext.EntityFinanceSummaries.Add(updateEntityRecord); orgMaintEntitiesContext.SaveChanges(); newEntityFinanceSummaryID = updateEntityRecord.EntityFinanceSummaryID; budgetRequired = entity.BudgetRequired; } else { // updateEntityRecord = GetEntitySummary(entity.EntityFinanceSummaryID.ToString()); var query = (from entityFinanceSummariesElement in orgMaintEntitiesContext.EntityFinanceSummaries where entityFinanceSummariesElement.EntityFinanceSummaryID == entity.EntityFinanceSummaryID select entityFinanceSummariesElement).FirstOrDefault(); ; if (query != null) { query.EntityName = entity.EntityName; query.EntityCategory = entity.EntityCategory; query.Comments = entity.Comments; query.BudgetAllocated = entity.BudgetAllocated; query.BudgetRequired = entity.BudgetRequired; query.BudgetUsed = entity.BudgetUsed; query.Priority = entity.Priority; query.DateUpdated = DateTime.Now; orgMaintEntitiesContext.SaveChanges(); newEntityFinanceSummaryID = query.EntityFinanceSummaryID; } } updateEntityStatus(); //also updates budget status return newEntityFinanceSummaryID; }