/// <summary> /// Store the label to the database and sets the default criteria string only if the id is 0. /// Otherwise just return a the record. /// </summary> /// <param name="labels">The label check if its new.</param> /// <param name="modifyUser">the user to log as the created or modified user</param> /// <param name="_repository">repository used for saving info</param> /// <returns></returns> private List <ApptLabelDto> StoreLabels(List <ApptLabelDto> labels, string modifyUser, IDataRepositoryCrudBase <ApptLabel> _repository) { List <ApptLabel> saveList = new List <ApptLabel>(); foreach (var label in labels) { ApptLabel lbl = label.ConvertTo <ApptLabel>(); if (label.Id == 0) { //then save the label, to get an ID, lbl = _repository.CreateUpdate(lbl, modifyUser); //then but also set the criteria to the correct value and save it again.. if (Type.GetType(lbl.UseInterfaceType) == typeof(IEntityWithStatusLabels)) { lbl.LabelCriteria = $"([LabelKey] = '{lbl.Id}')"; } } saveList.Add(lbl); } return(_repository.CreateUpdateList(saveList, modifyUser).ConvertAllTo <ApptLabelDto>().ToList()); }
private List <ApptStatusDto> StoreStatuses(List <ApptStatusDto> statuses, string modifyUser, IDataRepositoryCrudBase <ApptStatus> _repository) { List <ApptStatus> saveList = new List <ApptStatus>(); foreach (var status in statuses) { ApptStatus sts = status.ConvertTo <ApptStatus>(); if (sts.Id == 0) { //then save the label, to get an ID, sts = _repository.CreateUpdate(sts, modifyUser); //then but also set the criteria to the correct value and save it again.. if (Type.GetType(sts.UseInterfaceType) == typeof(IEntityWithStatusLabels)) { sts.StatusCriteria = $"([{nameof(IEntityWithStatusLabels.StatusKey)}] = '{sts.Id}')"; } } saveList.Add(sts); } return(_repository.CreateUpdateList(saveList, modifyUser).ConvertAllTo <ApptStatusDto>().ToList()); }