public void Update_Work(Work work) { int oldTypeID = 0, newTypeID = 0; var workDB = Works.FirstOrDefault(x => x.ID == work.ID); if (workDB != null) { oldTypeID = workDB.WorkTypeID; newTypeID = work.WorkTypeID; } ChangeTracker.DetectChanges(); Works.AddOrUpdate(work); // todo была ошибка, проверить в истории if (oldTypeID != newTypeID) //При изменении типа! Удалить-перенести атрибуты типа { Update_AttrValuesFields_ForWork(work, (WorkTypeEnum)oldTypeID, (WorkTypeEnum)newTypeID); } SaveChanges(); }
public void SetInterventionToEdit() { TotalInfoSelectedEl = new TotalsIfo() { TotalHours = -SelectedInterventionDetails.LocalIntervention.DateHourDetail.Duration, TotalInverventions = -1, TotalRevenue = -SelectedInterventionDetails.LocalIntervention.Revenue, TotalProfit = -SelectedInterventionDetails.LocalIntervention.Percent }; SelectedArea = SelectedInterventionDetails.LocalIntervention.Area != null?Areas.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.Area.Id) : null; if (SelectedInterventionDetails.LocalIntervention.Location != null) { SelectedLocation = LocalLocations.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.Location.Id); } if (SelectedInterventionDetails.LocalIntervention.Material != null && Materials != null) { SelectedMaterial = Materials.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.Material.Id); } SelectedPatient = PatientsList.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.PatientId); SelectedWork = SelectedInterventionDetails.LocalIntervention.Lucrare != null?Works.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.Lucrare.Id) : new LocalWork(); Durata = SelectedInterventionDetails.Durata.TotalMinutes.ToString(); Date = SelectedInterventionDetails.LocalIntervention.DateHourDetail.Date; StartingHour = SelectedInterventionDetails.LocalIntervention.DateHourDetail.StartHour; Revenue = SelectedInterventionDetails.LocalIntervention.Revenue; Id = SelectedInterventionDetails.LocalIntervention.Id; LocalIntervention = SelectedInterventionDetails.LocalIntervention; Observation = SelectedInterventionDetails.Observations; IsInEditMode = true; WasPayedByDental = SelectedInterventionDetails.WasPayedByDental; SelectedTechnician = Technicians.FirstOrDefault(item => item.Id == SelectedInterventionDetails.LocalIntervention.TechnicianId); MaterialCost = SelectedInterventionDetails.MaterialCost; }