public async Task <IdentityResult> CreateNewEntryAsync(
            User user,
            long dataModelId,
            MODIFICATION modificationType,
            MODEL_TYPE modelType,
            DATA_TYPE dataType,
            string oldValue    = "",
            string actualValue = "",
            int extensionIndex = -1)
        {
            ModificationEntry entry = new ModificationEntry()
            {
                DataModelId      = dataModelId,
                DateTime         = DateTime.Now,
                DataModelType    = modelType,
                ModificationType = modificationType,
                User             = user,
                ActualValue      = actualValue,
                DataType         = dataType,
                ExtensionIndex   = extensionIndex,
                OldValue         = oldValue
            };

            if (await CreateAsync(entry) != null)
            {
                return(IdentityResult.Success);
            }
            else
            {
                return(IdentityResult.Failed());
            }
        }
        public async Task <IdentityResult> SetEntriesToDeletionStateAsync(long id, MODEL_TYPE modelType, DATA_TYPE dataType, int extensionIndex = -1)
        {
            bool success = true;
            List <ModificationEntry> entries = await GetModificationEntriesByIdAndModelTypeAsync(id, modelType);

            foreach (ModificationEntry entry in entries)
            {
                if (entry.DataType == dataType && entry.ExtensionIndex == extensionIndex)
                {
                    entry.SetToDeletionState();
                    if (await UpdateAsync(entry) == null)
                    {
                        success = false;
                    }
                }
            }
            if (success)
            {
                return(IdentityResult.Success);
            }
            else
            {
                return(IdentityResult.Failed());
            }
        }
Beispiel #3
0
        public async Task <IActionResult> GetSortedListByType(MODEL_TYPE modelDataType)
        {
            User userOfChange = await userService.FindByNameAsync(User.Identity.Name);

            List <ModificationEntry> entries = await modificationEntryRepository.GetSortedModificationEntriesByModelDataTypeAsync(modelDataType, userOfChange);

            if (entries != null)
            {
                return(Ok(mapper.Map <List <ModificationEntryDto> >(entries)));
            }
            else
            {
                return(NotFound());
            }
        }
 /// <summary>
 /// compare two plain fields together and decide whether to create a deletion entry or a creation one
 /// </summary>
 /// <param name="listWithCreation">list with objects to create</param>
 /// <param name="listWithDeletion">list with objects to delete (including all past values)</param>
 /// <param name="oldValue">the old value</param>
 /// <param name="newValue">the new value</param>
 /// <param name="id">the model id</param>
 /// <param name="modelType">the model type</param>
 /// <param name="dataType">the data type</param>
 /// <param name="userOfModification">who changed this?</param>
 /// <param name="deleteEntries">should the entries be deleted including all past values if empty?</param>
 private static void ComparePlainDataWithDeletionOption(List <ModificationEntry> listWithCreation, List <ModificationEntry> listWithDeletion, string oldValue, string newValue, long id,
                                                        MODEL_TYPE modelType, DATA_TYPE dataType, User userOfModification, bool deleteEntries)
 {
     if (!oldValue.Equals(newValue))
     {
         if (string.IsNullOrEmpty(newValue) && deleteEntries)
         {
             listWithDeletion.Add(GetNewModificationEntry(newValue, oldValue, id, modelType, dataType, userOfModification, MODIFICATION.DELETED, -1));
             listWithCreation.Add(GetNewModificationEntry("", "", id, modelType, dataType, userOfModification, MODIFICATION.DELETED, -1, true));
         }
         else
         {
             listWithCreation.Add(GetNewModificationEntry(newValue, oldValue, id, modelType, dataType, userOfModification, MODIFICATION.MODIFIED));
         }
     }
 }
        /// <summary>
        /// compare two addresses objects together.
        /// </summary>
        /// <param name="oldOne">the old one</param>
        /// <param name="newOne">the new one</param>
        /// <param name="idOfModel">the id of model</param>
        /// <param name="userOfModification">who made this change?</param>
        /// <param name="modelType">the model type</param>
        /// <returns></returns>
        private static List <ModificationEntry> GetModificationsForAddressObject(Address oldOne, Address newOne, long idOfModel, User userOfModification, MODEL_TYPE modelType)
        {
            List <ModificationEntry> list = new List <ModificationEntry>();

            ComparePlainFields(list, oldOne.City, newOne.City, idOfModel, modelType, DATA_TYPE.CITY, userOfModification, MODIFICATION.MODIFIED);
            ComparePlainFields(list, oldOne.Country, newOne.Country, idOfModel, modelType, DATA_TYPE.COUNTRY, userOfModification, MODIFICATION.MODIFIED);
            ComparePlainFields(list, oldOne.Street, newOne.Street, idOfModel, modelType, DATA_TYPE.STREET, userOfModification, MODIFICATION.MODIFIED);
            ComparePlainFields(list, oldOne.StreetNumber, newOne.StreetNumber, idOfModel, modelType, DATA_TYPE.STREETNUMBER, userOfModification, MODIFICATION.MODIFIED);
            ComparePlainFields(list, oldOne.Zipcode, newOne.Zipcode, idOfModel, modelType, DATA_TYPE.ZIPCODE, userOfModification, MODIFICATION.MODIFIED);
            return(list);
        }
 /// <summary>
 /// check the contact possibilities entries for changes.
 /// </summary>
 /// <param name="oldOne">the old ones</param>
 /// <param name="newOne">the new ones</param>
 /// <param name="idOfModel">the id of model</param>
 /// <param name="userOfModification">who made the changes?</param>
 /// <param name="deleteEntries">if true, then the deleted property will be unvisible for all older ones as well, if false the older values stay</param>
 /// <param name="listWithCreation">the list with entries which should be created afterwards</param>
 /// <param name="listWithDeletion">the list with modification entries which should be deleted afterwards</param>
 /// <param name="nextNewId">the next new index of modification entry of entities to consider</param>
 /// <param name="modelType">for which model type</param>
 private static void GetModificationsForContactEntriesObject(List <ContactPossibilitiesEntry> oldOne, List <ContactPossibilitiesEntry> newOne, long idOfModel, User userOfModification, bool deleteEntries,
                                                             List <ModificationEntry> listWithCreation, List <ModificationEntry> listWithDeletion, MODEL_TYPE modelType, int nextNewId)
 {
     foreach (ContactPossibilitiesEntry entryOld in oldOne)
     {
         DATA_TYPE dataType = DATA_TYPE.PHONE_EXTENDED;
         if (new MailValidator().IsValid(entryOld.ContactEntryValue))
         {
             dataType = DATA_TYPE.MAIL_EXTENDED;
         }
         ContactPossibilitiesEntry newEntryToFind = newOne.Find(a => a.Id == entryOld.Id);
         if (newEntryToFind == null && deleteEntries)
         {
             listWithDeletion.Add(GetNewModificationEntry("", entryOld.ContactEntryValue, idOfModel, modelType, dataType, userOfModification, MODIFICATION.DELETED, (int)entryOld.Id));
             listWithCreation.Add(GetNewModificationEntry("", "", idOfModel, modelType, dataType, userOfModification, MODIFICATION.DELETED, (int)entryOld.Id, true));
         }
         else
         {
             if (newEntryToFind == null || !newEntryToFind.ContactEntryName.Equals(entryOld.ContactEntryName) || !newEntryToFind.ContactEntryValue.Equals(entryOld.ContactEntryValue))
             {
                 string newValue = string.Empty;
                 string newName  = string.Empty;
                 if (newEntryToFind != null)
                 {
                     newName  = newEntryToFind.ContactEntryName;
                     newValue = newEntryToFind.ContactEntryValue;
                 }
                 listWithCreation.Add(GetNewModificationEntry(newName + ":" + newValue, entryOld.ContactEntryName + ":" + entryOld.ContactEntryValue, idOfModel, modelType, dataType, userOfModification, MODIFICATION.MODIFIED, (int)entryOld.Id));
             }
         }
     }
     foreach (ContactPossibilitiesEntry entryNew in newOne)
     {
         if (oldOne.Find(a => a.Id == entryNew.Id) == null)
         {
             DATA_TYPE dataType = DATA_TYPE.PHONE_EXTENDED;
             if (new MailValidator().IsValid(entryNew.ContactEntryValue))
             {
                 dataType = DATA_TYPE.MAIL_EXTENDED;
             }
             listWithCreation.Add(GetNewModificationEntry(entryNew.ContactEntryName + ":" + entryNew.ContactEntryValue, "", idOfModel, modelType, dataType, userOfModification, MODIFICATION.ADDED, nextNewId++));
         }
     }
 }
 /// <summary>
 /// check contact possibilities object for differences.
 /// </summary>
 /// <param name="oldOne">the old one</param>
 /// <param name="newOne">the new one</param>
 /// <param name="idOfModel">the id of model</param>
 /// <param name="userOfModification">who made a change?</param>
 /// <param name="deleteEntries">if true, then the deleted property will be unvisible for all older ones as well, if false the older values stay</param>
 /// <param name="listWithCreation">the list with entries which should be created afterwards</param>
 /// <param name="listWithDeletion">the list with modification entries which should be deleted afterwards</param>
 /// <param name="nextNewId">the next new index of modification entry of entities to consider</param>
 /// <param name="modelType">for which model type</param>
 private static void GetModificationsForContactPossibilitiesObject(ContactPossibilities oldOne, ContactPossibilities newOne, long idOfModel, User userOfModification, bool deleteEntries,
                                                                   List <ModificationEntry> listWithCreation, List <ModificationEntry> listWithDeletion, MODEL_TYPE modelType, int nextNewId)
 {
     ComparePlainDataWithDeletionOption(listWithCreation, listWithDeletion, oldOne.Fax, newOne.Fax, idOfModel, modelType, DATA_TYPE.FAX, userOfModification, deleteEntries);
     ComparePlainDataWithDeletionOption(listWithCreation, listWithDeletion, oldOne.Mail, newOne.Mail, idOfModel, modelType, DATA_TYPE.MAIL, userOfModification, deleteEntries);
     ComparePlainDataWithDeletionOption(listWithCreation, listWithDeletion, oldOne.PhoneNumber, newOne.PhoneNumber, idOfModel, modelType, DATA_TYPE.PHONE, userOfModification, deleteEntries);
     GetModificationsForContactEntriesObject(oldOne.ContactEntries, newOne.ContactEntries, idOfModel, userOfModification, deleteEntries, listWithCreation, listWithDeletion, modelType, nextNewId);
 }
 /// <summary>
 /// compare simple fields together
 /// </summary>
 /// <param name="listEntries">the list where to add a new modification entry if necessary</param>
 /// <param name="oldValue">the old value</param>
 /// <param name="newValue">the new value</param>
 /// <param name="id">the model id</param>
 /// <param name="modelType">the modelType</param>
 /// <param name="dataType">the dataType</param>
 /// <param name="userOfModification">who made this change?</param>
 /// <param name="modification">the modification type</param>
 private static void ComparePlainFields(List <ModificationEntry> listEntries, string oldValue, string newValue, long id, MODEL_TYPE modelType, DATA_TYPE dataType, User userOfModification, MODIFICATION modification)
 {
     if (oldValue == null || !oldValue.Equals(newValue))
     {
         listEntries.Add(GetNewModificationEntry(newValue, oldValue, id, modelType, dataType, userOfModification, modification));
     }
 }
        public async Task <List <ModificationEntry> > GetSortedModificationEntriesByModelDataTypeAsync(MODEL_TYPE dataType, User user)
        {
            List <ModificationEntry> list = await Entities.Include(u => u.User).Where(x => x.DataModelType == dataType).ToListAsync();

            List <ModificationEntry> listToDelete = new List <ModificationEntry>();

            foreach (ModificationEntry entry in list)
            {
                if (entry.ModificationType == MODIFICATION.DELETED && entry.DataType == DATA_TYPE.NONE)
                {
                    listToDelete.AddRange(list.FindAll(a => a.DataModelId == entry.DataModelId));
                }
            }
            if (dataType == MODEL_TYPE.CONTACT)
            {
                List <Contact> allContacts = await contactRepository.GetAllUnapprovedContactsWithAllIncludesAsync();

                if (allContacts != null && allContacts.Any())
                {
                    foreach (ModificationEntry entry in list)
                    {
                        if (allContacts.Any(b => !user.IsSuperAdmin && b.Id == entry.DataModelId && b.CreatedByUser != user.Id))
                        {
                            listToDelete.Add(entry);
                        }
                    }
                }
            }
            listToDelete.ForEach(y => list.Remove(y));
            list.Sort((x, y) => { return(DateTime.Compare(y.DateTime, x.DateTime)); });
            return(list);
        }
Beispiel #10
0
 public ModelTypeEventArgs(MODEL_TYPE type)
 {
     ModelType = type;
 }
Beispiel #11
0
        public async Task <IActionResult> GetSortedListByTypeAndId([FromQuery] long id, [FromQuery] MODEL_TYPE modelDataType, [FromQuery] PaginationFilter filter)
        {
            if (filter == null)
            {
                List <ModificationEntry> fullResult = await modificationEntryRepository.GetModificationEntriesByIdAndModelTypeAsync(id, modelDataType);

                return(Ok(new PagedResponse <List <ModificationEntryDto> >(mapper.Map <List <ModificationEntryDto> >(fullResult), 0, 0, 0)));
            }
            PaginationFilter         validFilter = new PaginationFilter(filter.PageStart, filter.PageSize);
            List <ModificationEntry> entries     = await modificationEntryRepository.GetModificationEntriesByIdAndModelTypePaginationAsync(id, modelDataType, validFilter.PageStart, validFilter.PageSize);

            int totalRecords = await modificationEntryRepository.GetModificationEntriesByIdAndModelTypeCountAsync(id, modelDataType);

            return(Ok(new PagedResponse <List <ModificationEntryDto> >(mapper.Map <List <ModificationEntryDto> >(entries), validFilter.PageStart, validFilter.PageSize, totalRecords)));
        }
 public async Task <List <ModificationEntry> > GetModificationEntriesForCreationByModelType(MODEL_TYPE modelType)
 {
     return(await Entities.Where(entry => entry.DataModelType == modelType && entry.DataType == DATA_TYPE.NONE).ToListAsync());
 }
 public async Task <int> GetModificationEntriesByIdAndModelTypeCountAsync(long id, MODEL_TYPE dataType)
 {
     return(await Entities
            .Include(x => x.User)
            .Where(x => x.DataModelId == id && x.DataModelType == dataType)
            .CountAsync());
 }
 public async Task <List <ModificationEntry> > GetModificationEntriesByIdAndModelTypePaginationAsync(long id, MODEL_TYPE dataType, int pageStart, int pageSize)
 {
     return(await Entities
            .Include(x => x.User)
            .Where(x => x.DataModelId == id && x.DataModelType == dataType)
            .OrderByDescending(x => x.DateTime)
            .Skip(pageStart)
            .Take(pageSize)
            .ToListAsync());
 }
        /// <summary>
        /// create a new modification entry
        /// </summary>
        /// <param name="actualValue">the actual, new value</param>
        /// <param name="oldValue">the old value</param>
        /// <param name="idOfModel">the id of model</param>
        /// <param name="modelType">the model type</param>
        /// <param name="dataType">the data type</param>
        /// <param name="userOfModification">who made the change?</param>
        /// <param name="modification">the modification type</param>
        /// <param name="index">the id of contact possibilities entry</param>
        /// <param name="shouldBeDeleted">if true, then this object should not make visible its values</param>
        /// <returns></returns>
        private static ModificationEntry GetNewModificationEntry(string actualValue, string oldValue, long idOfModel, MODEL_TYPE modelType, DATA_TYPE dataType,
                                                                 User userOfModification, MODIFICATION modification, int index = -1, bool deleteInfo = false)
        {
            ModificationEntry entry = new ModificationEntry()
            {
                ActualValue      = actualValue,
                DataModelId      = idOfModel,
                DataModelType    = modelType,
                DataType         = dataType,
                DateTime         = DateTime.Now,
                ModificationType = modification,
                OldValue         = oldValue,
                User             = userOfModification,
                ExtensionIndex   = index
            };

            if (deleteInfo)
            {
                entry.SetToDeletionState();
            }
            return(entry);
        }
 private async Task CheckTagInternally(Tag tag, List <VerticalGroupedBarDto> list, MODEL_TYPE model)
 {
     await Task.Run(() =>
     {
         VerticalGroupedBarDto vDto = list.FirstOrDefault(a => a.Name.Equals(tag.Name));
         if (vDto == null)
         {
             vDto = new VerticalGroupedBarDto()
             {
                 Name = tag.Name
             };
             list.Add(vDto);
         }
         string enumName = EnumHelper.GetEnumMemberValue(model);
         VerticalGroupedBarDataSet vEntry = vDto.Series.FirstOrDefault(a => a.Name.Equals(enumName));
         if (vEntry == null)
         {
             vEntry = new VerticalGroupedBarDataSet()
             {
                 Name = enumName, Value = 0
             };
             vDto.Series.Add(vEntry);
         }
         vEntry.Value++;
     });
 }
 /// <summary>
 /// create a new modification entry for the info that either a new contact was added or removed from a list
 /// </summary>
 /// <param name="id">the model id</param>
 /// <param name="contactName">the contact to consider</param>
 /// <param name="wasDeleted">if true, then the contact was removed, otherwise it was added</param>
 /// <param name="userNameOfChange">who modified this?</param>
 /// <param name="modelType">the model type to consider</param>
 /// <returns></returns>
 private async Task ChangeContactsOfSource(long id, string contactName, bool wasDeleted, User userNameOfChange, MODEL_TYPE modelType)
 {
     if (wasDeleted)
     {
         await CreateNewEntryAsync(userNameOfChange, id, MODIFICATION.DELETED, modelType, DATA_TYPE.CONTACTS, contactName, "");
     }
     else
     {
         await CreateNewEntryAsync(userNameOfChange, id, MODIFICATION.ADDED, modelType, DATA_TYPE.CONTACTS, "", contactName);
     }
 }
        private async Task <bool> HandleInvitationResponseForObjectAsync(long id, long objectId, ParticipatedStatus state, MODEL_TYPE modelType)
        {
            Event eventToModify = await GetEventByIdWithAllIncludesAsync(id);

            if (eventToModify != null)
            {
                Participated partToChange = eventToModify.Participated.FirstOrDefault(x => x.ObjectId == objectId && x.ModelType == modelType);
                if (partToChange != null)
                {
                    partToChange.EventStatus = state;
                    await UpdateAsync(eventToModify);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
 /// <summary>
 /// Compare all tags
 /// </summary>
 /// <param name="listEntries"></param>
 /// <param name="tagsOld"></param>
 /// <param name="tagsNew"></param>
 /// <param name="modelId"></param>
 /// <param name="modelType"></param>
 /// <param name="userOfModification"></param>
 private static void CompareTagFields(List <ModificationEntry> listEntries, List <Tag> tagsOld, List <Tag> tagsNew, long modelId, MODEL_TYPE modelType, User userOfModification)
 {
     if (tagsNew.Count > tagsOld.Count)
     {
         string newTags = string.Empty;
         foreach (Tag tag in tagsNew)
         {
             if (tagsOld.Find(a => a.Name.Equals(tag.Name)) == null)
             {
                 newTags += tag.Name + " ";
             }
         }
         listEntries.Add(GetNewModificationEntry(newTags, "", modelId, modelType, DATA_TYPE.TAG, userOfModification, MODIFICATION.ADDED));
     }
     else if (tagsNew.Count < tagsOld.Count)
     {
         string removedTags = string.Empty;
         foreach (Tag tag in tagsOld)
         {
             if (tagsNew.Find(a => a.Name.Equals(tag.Name)) == null)
             {
                 removedTags += tag.Name + " ";
             }
         }
         listEntries.Add(GetNewModificationEntry("", removedTags, modelId, modelType, DATA_TYPE.TAG, userOfModification, MODIFICATION.DELETED));
     }
 }