public void Edit(Indicator entity) { lock (syncObj) { using (var context = GetContext()) { var existingIndicator = context.Indicators.FirstOrDefault(p => p.Id == entity.Id); if (existingIndicator == null) { throw new Exception("invalid Indicator id: " + entity.Id); } else { //get companies with the same name but different id var existingEntity = context.Indicators.FirstOrDefault(p => p.Name == entity.Name && p.Id != entity.Id); if (existingEntity != null) { throw new DuplicateEntityNameException(); } SetAllIndicatorsDefaultValue(context, entity); existingIndicator.Name = entity.Name; existingIndicator.Content = entity.Content; existingIndicator.IsDefault = entity.IsDefault; existingIndicator.CreatedTimestamp = entity.CreatedTimestamp; base.Commit(context); } } } }
public void Create(Indicator entity) { lock (syncObj) { using (var context = GetContext()) { var existingEntity = context.Indicators.FirstOrDefault(p => p.Name == entity.Name); if (existingEntity != null) { throw new DuplicateEntityNameException(); } SetAllIndicatorsDefaultValue(context, entity); Indicator soc = new Indicator() { Id = DbIdHelper.GetNextID(), Name = entity.Name, Content = entity.Content, CreatedTimestamp = entity.CreatedTimestamp, IsDefault = entity.IsDefault }; context.Indicators.AddObject(soc); base.Commit(context); entity.Id = soc.Id; } } }
private static void DeleteIndicator(Indicator entity) { try { IIndicatorRepository repository = new IndicatorRepository(); repository.Delete(entity.Id); } catch (Exception ex) { throw new DeleteEntityException<Indicator>(); } }
public void SetTaxIndicatorToEditFormula(object param) { currentTaxIndicator = param as Indicator; if (currentTaxIndicator != null) { Name = currentTaxIndicator.Name; //CS: do not add the default ones, show error if (currentTaxIndicator.Content == null) { WindowHelper.OpenErrorDialog(Messages.Error_LoadingData); //add the default indicators if none is present //AddDefaultIndicators(); } else { var dbIndicators = VmUtils.Deserialize<List<TaxIndicator>>(currentTaxIndicator.Content); TaxIndicators = new ObservableCollection<TaxIndicatorViewModel>(dbIndicators.ToVmList()); } if (currentTaxIndicator.IsDefault) { EditEnabled = false; } } }
public void SaveAsCallBackAction(Indicator newIndicator) { try { //the new formula was created - callback //replace the current indicator with the new one currentTaxIndicator = newIndicator; //save the formula data var taxIndicatorModelList = TaxIndicators.ToList().ToModelList(); currentTaxIndicator.Content = VmUtils.SerializeEntity(taxIndicatorModelList); indicatorRepository.Edit(currentTaxIndicator); } catch (Exception ex) { Logger.Instance.LogException(ex); WindowHelper.OpenErrorDialog(Messages.ErrorSavingInfo); } }
private void AddDefaultIndicator() { var currentEntity = new Indicator(); currentEntity.Name = "Structura initiala de indicatori"; currentEntity.IsDefault = true; currentEntity.Content = GetDefaultIndicators(); currentEntity.CreatedTimestamp = DateTime.Now; var allItems = indicatorRepository.GetAll(); if (allItems.Count == 0) { //force IsDefault; currentEntity.IsDefault = true; } indicatorRepository.Create(currentEntity); }
public void Save(object param) { try { if (IsValid()) { //update fields if (currentEntity == null || currentEntity.Id == 0) { //create currentEntity = new Indicator(); UpdateFields(); currentEntity.Content = GetDefaultIndicators(); currentEntity.CreatedTimestamp = DateTime.Now; var allItems = indicatorRepository.GetAll(); if (allItems.Count == 0) { //force IsDefault; currentEntity.IsDefault = true; } indicatorRepository.Create(currentEntity); } else { //edit UpdateFields(); indicatorRepository.Edit(currentEntity); } WindowHelper.OpenInformationDialog(Messages.InfoWasSaved); Mediator.Instance.SendMessage(MediatorActionType.CloseWindow, this.Guid); Mediator.Instance.SendMessage(MediatorActionType.RefreshList, this.Guid); if (saveAsCallBackAction != null) { saveAsCallBackAction(currentEntity); } } else { WindowHelper.OpenErrorDialog("Va rugam completati toate campurile"); } } catch (DuplicateEntityNameException dcne) { WindowHelper.OpenErrorDialog("Exista(sau a existat) un indicator cu acelasi nume!"); } catch (Exception ex) { Logger.Instance.LogException(ex); WindowHelper.OpenErrorDialog(Messages.ErrorSavingInfo); } }
public void SetEntityToEdit(object param) { IndicatorViewModel = new IndicatorViewModel(); if (param is Indicator) { this.Title = "Editare Indicator"; currentEntity = param as Indicator; IndicatorViewModel.Name = currentEntity.Name; IndicatorViewModel.IsDefault = currentEntity.IsDefault; IndicatorViewModel.IsDefaultEnabled = false; } else { this.Title = "Creare Indicator"; IndicatorViewModel.Name = ""; IndicatorViewModel.IsDefault = false; IndicatorViewModel.IsDefaultEnabled = true; } }
private static void SetAllIndicatorsDefaultValue(TaxCalculatorModelContainer context, Indicator entity) { if (entity.IsDefault) { var allIntems = context.Indicators.ToList(); //set everything as notDefault allIntems.ForEach(p => p.IsDefault = false); } }
public long EditWithHide(Indicator entity) { lock (syncObj) { using (var context = GetContext()) { var existingIndicator = context.Indicators.FirstOrDefault(p => p.Id == entity.Id); if (existingIndicator == null) { throw new Exception("invalid Indicator id: " + entity.Id); } else { //set the values for the new entity as the current one //create a new entity Indicator newEntity = new Indicator() { Id = DbIdHelper.GetNextID(), Name = entity.Name, Content = entity.Content, CreatedTimestamp = entity.CreatedTimestamp, IsDefault = entity.IsDefault }; context.Indicators.AddObject(newEntity); //SetAllIndicatorsDefaultValue(context, entity); //hide the current entity //add an entry in the settings file base.Commit(context); return newEntity.Id; } } } }
/// <summary> /// Create a new Indicator object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="createdTimestamp">Initial value of the CreatedTimestamp property.</param> /// <param name="isDefault">Initial value of the IsDefault property.</param> public static Indicator CreateIndicator(global::System.Int64 id, global::System.String name, global::System.DateTime createdTimestamp, global::System.Boolean isDefault) { Indicator indicator = new Indicator(); indicator.Id = id; indicator.Name = name; indicator.CreatedTimestamp = createdTimestamp; indicator.IsDefault = isDefault; return indicator; }
/// <summary> /// Deprecated Method for adding a new object to the Indicators EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToIndicators(Indicator indicator) { base.AddObject("Indicators", indicator); }