using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using BeWo.Data.Access; using BeWo.Data.Entities; using BeWo.Service.Core; using BeWo.Service.DCEntityMapper; using BeWo.Service.ServiceContracts; using BS.Shared; using BS.Shared.DataContracts; using BS.Shared.Extensions; namespace BeWo.Service.ServiceImplementations { [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)] public class ValueListServiceImp : IValueListService { public void DeactivateValueListEntries(Dictionary pOid2Version) { try { ServiceLogic.SetActivationType(pOid2Version, ActivationTypeId.Deleted); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public void DeactivateValueListEntry(long pOid, long pVersion) { try { ServiceLogic.SetActivationType(new Dictionary { { pOid, pVersion } }, ActivationTypeId.Deleted); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } throw new NotImplementedException(); } public void DeleteValueListEntries(Dictionary pOid2Version) { try { var lOriginals = DAOFactory.GenericDAO.LoadByIDs(pOid2Version.Select(e => e.Key)); lOriginals.DoForEach(or => MapperFactory.ValueListEntryDC_ValueListEntry.ConcurrencyCheck(pOid2Version[or.Oid.Value], or)); DAOFactory.GenericDAO.Delete(lOriginals); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public void DeleteValueListEntry(long pOid, long pVersion) { try { this.DeleteValueListEntries(new Dictionary { { pOid, pVersion } }); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public ValueListEntryDC[] GetAllValueListEntrysByType(ValueListEntryType pType) { try { var list = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(DAOFactory.SearchDAO.FindValueListEntry(pType).Where(ve => ve.IsActive == ActivationTypeId.Active)).ToArray(); return list.OrderBy(ve => String.Format("{0}-{1}", ve.Abbreviation, ve.TypeDescription)).ToArray(); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public ValueListEntryDC[] GetAllValueListEntrysByTypes(List pTypes) { try { var list = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(DAOFactory.SearchDAO.FindValueListEntries(pTypes).Where(ve => ve.IsActive == ActivationTypeId.Active)).ToArray(); return list.OrderBy(ve => String.Format("{0}-{1}", ve.Abbreviation, ve.TypeDescription)).ToArray(); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public ValueListEntryDC GetValueListEntryByOid(long pOid) { try { return MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDC(DAOFactory.GenericDAO.LoadByID(pOid)); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List InsertNewValueListEntries(List pEntries) { try { var lEntities = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewEntities(pEntries); DAOFactory.GenericDAO.Insert(lEntities); return lEntities.Select(e => e.Oid.Value).ToList(); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List InsertAndLoadNewValueListEntries(IEnumerable pEntries) { try { var lEntities = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewEntities(pEntries); DAOFactory.GenericDAO.Insert(lEntities); return MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(lEntities); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public ValueListEntryDC InsertNewValueListEntry(ValueListEntryDC pEntry) { try { var lEntity = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewEntity(pEntry); DAOFactory.GenericDAO.Insert(lEntity); // Hier Fehler bei Komponente E return MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDC(lEntity); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public void UpdateValueListEntries(List pEntries) { try { var lOriginals = DAOFactory.GenericDAO.LoadByIDs(pEntries.Select(en => en.ValueListEntryOid.Value)); MapperFactory.ValueListEntryDC_ValueListEntry.MergeWithEntitys(pEntries, lOriginals); DAOFactory.GenericDAO.Update(lOriginals); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public ValueListEntryDC[] GetAllValueListEntriesByOidForType(long pOid) { var original = DAOFactory.GenericDAO.GetByID(pOid); return GetAllValueListEntrysByType(original.Type); } public List GetValueListEntriesByOids(IEnumerable oids) { try { var entities = DAOFactory.GenericDAO.LoadByIDs(oids); return MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(entities); } catch(Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetGoalCategoriesByOids(List oids) { try { var entities = DAOFactory.SearchDAO.GetGoalCategoriesByOids(oids); return MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(entities); } catch(Exception e) { throw Utils.CreateBeWoFaultException(e); } } } }