Пример #1
0
        public List <EditableGridSaveResponse> UpdateRecords(IEnumerable <EditableGridModel> records)
        {
            // Execute Multiple Request is suggested in this context. - Rex
            List <EditableGridSaveResponse> recordsCreated = new List <EditableGridSaveResponse>();

            foreach (var item in records)
            {
                if (item.Id != Guid.Empty)
                {
                    Entity entity = _service.ServiceContext.Retrieve(item.Entity, item.Id, new ColumnSet(item.Entity + "id"));

                    //entity.GetAttributeValue
                    foreach (var list in item.Records)
                    {
                        entity[list.Attr] = XrmCommonHelper.ConvertField(new ClientEntity
                        {
                            type   = list.Type,
                            Value  = list.Value,
                            attr   = list.Attr,
                            entity = list.Reference
                        });
                    }

                    _service.ServiceContext.Update(entity);
                    continue;
                }
                Entity newEntity = new Entity(item.Entity);

                foreach (var list in item.Records)
                {
                    newEntity[list.Attr] = XrmCommonHelper.ConvertField(new ClientEntity
                    {
                        type  = list.Type,
                        Value = list.Value,
                        attr  = list.Attr
                    });
                }
                Guid newRecord = _service.ServiceContext.Create(newEntity);
                recordsCreated.Add(new EditableGridSaveResponse
                {
                    Id       = newRecord,
                    RowIndex = item.HotRowIndex
                });

                //_service.ServiceContext.Associate
            }

            return(recordsCreated);
        }
Пример #2
0
        public string GetEntityPluralName(string logicalName)
        {
            EntityMetadata entityData = XrmCommonHelper.GetEntityMetaData(_service, logicalName);

            return(entityData.DisplayCollectionName.UserLocalizedLabel.Label ?? "empty");
        }