Exemplo n.º 1
0
        public async Task <string> Save(JObject data)
        {
            dynamic groupDto     = data;
            int     groupId      = groupDto.GroupId;
            int     entityTypeId = groupDto.EntityTypeId;
            string  groupName    = groupDto.Name;

            if (!AuthorizeManager.AuthorizeActionOnEntityId(groupId, (int)EntityIdentity.Group,
                                                            (int)ActionKey.EditGroup))
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidAccessToEditGroup, groupName));
            }

            JArray sremovedListArray = groupDto.RemovedList;
            var    removedList       = sremovedListArray.ToObject <List <int> >();
            JArray addedListArray    = groupDto.AddedList;
            var    addedList         = addedListArray.ToObject <List <int> >();

            foreach (var item in addedList)
            {
                if (entityTypeId == 101)
                {
                    var group = new EntityGroup()
                    {
                        GroupId      = groupId,
                        EntityTypeId = entityTypeId,
                        LinkId       = item
                    };
                    _contentManagementContext.EntityGroups.Add(group);
                }
                else
                {
                    var group = new EntityGroup()
                    {
                        GroupId              = groupId,
                        EntityTypeId         = entityTypeId,
                        MasterDataKeyValueId = item
                    };
                    _contentManagementContext.EntityGroups.Add(group);
                }
            }

            if (removedList.Count > 0)
            {
                if (entityTypeId == 101)
                {
                    _contentManagementContext.EntityGroups.Where(eg => removedList.Contains(eg.LinkId ?? 0) && eg.GroupId == groupId).Delete();
                }
                else
                {
                    _contentManagementContext.EntityGroups.Where(eg => removedList.Contains(eg.MasterDataKeyValueId ?? 0) && eg.GroupId == groupId).Delete();
                }
            }

            await _contentManagementContext.SaveChangesAsync();

            return(entityTypeId == 101 ? "link":"masterData");
        }
Exemplo n.º 2
0
        public bool DownlodFromUrl(int baseUrlId, string url, string filePath, string fileName)
        {
            filePath = AuthorizeManager.AuthorizeActionOnPath(filePath
                                                              .Replace(Config.UrlDelimeter, Helper.RootUrl), ActionKey.WriteToDisk);
            if (AuthorizeManager.AuthorizeActionOnEntityId(baseUrlId, (int)EntityIdentity.Urls,
                                                           (int)ActionKey.DownloadFromAddress))
            {
                var baseUrl = _contentManagementContext.MasterDataKeyValues.AsNoTracking()
                              .SingleOrDefault(md => md.TypeId == (int)EntityIdentity.Urls && md.Id == baseUrlId);
                if (baseUrl == null)
                {
                    throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.CodeNotFound));
                }

                var downloadUrl = "";
                if (baseUrl.PathOrUrl[baseUrl.PathOrUrl.Length - 1] == '/')
                {
                    if (url[0] == '/')
                    {
                        downloadUrl = baseUrl.PathOrUrl + url.Substring(1);
                    }
                    else
                    {
                        downloadUrl = baseUrl.PathOrUrl + url;
                    }
                }
                else
                {
                    if (url[0] == '/')
                    {
                        downloadUrl = baseUrl.PathOrUrl + url;
                    }
                    else
                    {
                        downloadUrl = baseUrl.PathOrUrl + "/" + url;
                    }
                }

                if (filePath[filePath.Length - 1] == '/')
                {
                    filePath += fileName;
                }
                else
                {
                    filePath += "/" + fileName;
                }

                _fileSystemManager.DownlodFromUrl(downloadUrl,
                                                  filePath);
            }
            return(true);
        }