コード例 #1
0
        public static void DeleteAlbum(UserContainer currContext, Album album)
        {
            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value, true);
                    if (gm.State != (byte)GroupMemberState.Moderator)
                    {
                        throw new BusinessLogicException("Только модераторы могут удалить альбом группы");
                    }
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                    {
                        throw new BusinessLogicException("Нельзя удалить чужой альбом");
                    }
                }
                else
                {
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
                }
            }

            DataService.PerThread.AlbumSet.DeleteObject(album);
            DataService.PerThread.SaveChanges();
        }
コード例 #2
0
        public static DateTime ToUserTime(this DateTime dateTime, UserContainer currUserContext)
        {
            if (currUserContext == null || dateTime == DateTime.MinValue)
                return dateTime;

            return dateTime + currUserContext.UTCOffset - TimeZoneInfo.Local.BaseUtcOffset;
        }
コード例 #3
0
        public static string ToFormattedUserTime(this DateTime dateTime, UserContainer currUserContext, string timeFormat = "HH:mm:ss", bool timeOnly = false)
        {
            var date = string.Empty;
            var time = string.Empty;

            dateTime = dateTime.ToUserTime(currUserContext);

            if (dateTime.Date == DateTime.Now.Date)
            {
                if (!timeOnly)
                    date = "Сегодня";
                if (!string.IsNullOrEmpty(timeFormat))
                    time = dateTime.ToString(timeFormat);
            }
            else if (dateTime.Year == DateTime.Now.Year)
            {
                if (!timeOnly)
                    date = dateTime.ToString("d MMMM");
                if (!string.IsNullOrEmpty(timeFormat))
                    time = dateTime.ToString(timeFormat);
            }
            else
            {
                if (!timeOnly)
                    date = dateTime.ToString("dd.MM.yy");
                if (!string.IsNullOrEmpty(timeFormat))
                    time = dateTime.ToString(timeFormat);
            }

            return (date + " " + time).Trim();
        }
コード例 #4
0
        public static DateTime ToUserTime(this DateTime dateTime, UserContainer currUserContext)
        {
            if (currUserContext == null || dateTime == DateTime.MinValue)
            {
                return(dateTime);
            }

            return(dateTime + currUserContext.UTCOffset - TimeZoneInfo.Local.BaseUtcOffset);
        }
コード例 #5
0
        public static bool RegisterNewUserContainer(string key, UserContainer user)
        {
            if (user != null)
            {
                if (!Context.ContainsKey(key))
                    Context.TryAdd(key, user);
                return true;
            }

            return false;
        }
コード例 #6
0
        public static Album DeleteItem(UserContainer currContext, Guid itemId)
        {
            var albumItem = DataService.PerThread.AlbumItemSet.SingleOrDefault(x => x.Id == itemId);

            if (albumItem == null)
            {
                throw new BusinessLogicException("Указан неверный идентификатор");
            }

            var album = albumItem.Album;

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                    {
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                    }

                    if (gm.State != (byte)GroupMemberState.Moderator)
                    {
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                    }
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                    {
                        throw new BusinessLogicException("Нельзя редактировать чужой альбом");
                    }
                }
                else
                {
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
                }
            }

            if (albumItem.Type == (byte)AlbumItemType.Image)
            {
                ImageService.DeleteImage <AlbumItem>(albumItem.Src);
            }

            albumItem.Album.ChangeDate = DateTime.Now;
            albumItem.Likes.Clear();

            DataService.PerThread.AlbumItemSet.DeleteObject(albumItem);
            DataService.PerThread.SaveChanges();

            return(album);
        }
コード例 #7
0
        public static bool RegisterNewUserContainer(string key, UserContainer user)
        {
            if (user != null)
            {
                if (!Context.ContainsKey(key))
                {
                    Context.TryAdd(key, user);
                }
                return(true);
            }

            return(false);
        }
コード例 #8
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static AlbumItem AddImage(UserContainer currContext, Guid albumId, string title, string description, string fileName)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);
            if (album == null)
                throw new BusinessLogicException("Указан неверный идентификатор");

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                        throw new BusinessLogicException("Вы не состоите в группе");

                    if (album.IsOpen)
                    {
                        if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
                            throw new BusinessLogicException("Только члены группы могут добавлять изображения в альбом");
                    }
                    else if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут добавлять изображения в альбом");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя добавлять изображения в чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            var albumItem = new AlbumItem
            {
                AlbumId = albumId,
                Title = title,
                Description = description,
                Type = (byte)AlbumItemType.Image,
                Src = fileName,
                CreationDate = DateTime.Now
            };

            DataService.PerThread.AlbumItemSet.AddObject(albumItem);
            DataService.PerThread.LoadProperty<AlbumItem>(albumItem, x => x.Album);

            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return albumItem;
        }
コード例 #9
0
        public static UserContainer CreateNewUserContainer(string key)
        {
            UserContainer result = null;
            Guid userId;

            if (Guid.TryParse(key, out userId))
            {
                var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == userId);
                if (user != null)
                    result = new UserContainer(user);
            }

            return result;
        }
コード例 #10
0
        public static UserContainer CreateNewUserContainer(string key)
        {
            UserContainer result = null;
            Guid          userId;

            if (Guid.TryParse(key, out userId))
            {
                var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(u => u.Id == userId);
                if (user != null)
                {
                    result = new UserContainer(user);
                }
            }

            return(result);
        }
コード例 #11
0
        public static AlbumItem EditItem(UserContainer currContext, Guid itemId, string title, string description)
        {
            var albumItem = DataService.PerThread.AlbumItemSet.SingleOrDefault(x => x.Id == itemId);

            if (albumItem == null)
            {
                throw new BusinessLogicException("Указан неверный идентификатор");
            }

            if (currContext != null)
            {
                var album = albumItem.Album;

                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                    {
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                    }

                    if (gm.State != (byte)GroupMemberState.Moderator)
                    {
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                    }
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                    {
                        throw new BusinessLogicException("Нельзя редактировать чужой альбом");
                    }
                }
                else
                {
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
                }
            }

            albumItem.Title            = title;
            albumItem.Description      = description;
            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return(albumItem);
        }
コード例 #12
0
        public static string ToFormattedUserTime(this DateTime dateTime, UserContainer currUserContext, string timeFormat = "HH:mm:ss", bool timeOnly = false)
        {
            var date = string.Empty;
            var time = string.Empty;

            dateTime = dateTime.ToUserTime(currUserContext);

            if (dateTime.Date == DateTime.Now.Date)
            {
                if (!timeOnly)
                {
                    date = "Сегодня";
                }
                if (!string.IsNullOrEmpty(timeFormat))
                {
                    time = dateTime.ToString(timeFormat);
                }
            }
            else if (dateTime.Year == DateTime.Now.Year)
            {
                if (!timeOnly)
                {
                    date = dateTime.ToString("d MMMM");
                }
                if (!string.IsNullOrEmpty(timeFormat))
                {
                    time = dateTime.ToString(timeFormat);
                }
            }
            else
            {
                if (!timeOnly)
                {
                    date = dateTime.ToString("dd.MM.yy");
                }
                if (!string.IsNullOrEmpty(timeFormat))
                {
                    time = dateTime.ToString(timeFormat);
                }
            }

            return((date + " " + time).Trim());
        }
コード例 #13
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static AlbumItem AddVideo(UserContainer currContext, Guid albumId, string title, string description, string url, string embedCode)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);
            if (album == null)
                throw new BusinessLogicException("Указан неверный идентификатор");

            if (string.IsNullOrWhiteSpace(title))
                throw new BusinessLogicException("Не указано название видео");

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                        throw new BusinessLogicException("Вы не состоите в группе");

                    if (album.IsOpen)
                    {
                        if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
                            throw new BusinessLogicException("Только члены группы могут добавлять видео в альбом");
                    }
                    else if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут добавлять видео в альбом");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя добавлять видео в чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            string src;

            if (!string.IsNullOrWhiteSpace(embedCode))
            {
                using (var sgml = new SgmlReader())
                {
                    sgml.InputStream = new StringReader(embedCode);
                    sgml.Read();
                    src = sgml.GetAttribute("src");
                }
            }
            else if (!string.IsNullOrWhiteSpace(url))
            {
                var uri = new Uri(url);
                src = url; // TODO: мб лучше regexp для вычленения src

                switch (uri.Host.Replace("www.", string.Empty))
                {
                    case "youtube.com":
                        //src = uri.Scheme + "://" + uri.Host + "/embed/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First(); // это для iframe
                        src = uri.Scheme + "://" + uri.Host + "/v/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First();
                        break;

                    case "youtu.be":
                        //src = uri.Scheme + "://youtube.com/embed/" + uri.Segments[1]; // это для iframe
                        src = uri.Scheme + "://youtube.com/v/" + uri.Segments[1];
                        break;

                    /*case "vimeo.com":
                        src = uri.Scheme + "://" + "player." + uri.Host + "/video" + uri.PathAndQuery;
                        break;

                    case "dailymotion.com":
                        var query = uri.Fragment.Replace("#", string.Empty);
                        src = uri.Scheme + "://" + uri.Host + "/embed/video/" + HttpUtility.ParseQueryString(query).GetValues("videoId").First();
                        break;*/

                    case "e2-e4.tv":
                        src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                        break;

                    case "e2e4.tv":
                        src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                        break;
                }
            }
            else
                throw new BusinessLogicException("Источник видео не указан");

            var albumItem = new AlbumItem
            {
                AlbumId = albumId,
                Title = title,
                Description = description,
                Type = (byte)AlbumItemType.Video,
                Src = src,
                CreationDate = DateTime.Now
            };

            DataService.PerThread.AlbumItemSet.AddObject(albumItem);
            DataService.PerThread.LoadProperty(albumItem, x => x.Album);

            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return albumItem;
        }
コード例 #14
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static AlbumItem MoveItem(UserContainer currContext, Guid itemId, Guid albumId)
        {
            var albumItem = DataService.PerThread.AlbumItemSet.SingleOrDefault(x => x.Id == itemId);
            if (albumItem == null)
                throw new BusinessLogicException("Указан неверный идентификатор");

            if (currContext != null)
            {
                var album = albumItem.Album;

                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");

                    if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя редактировать чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            albumItem.AlbumId = albumId;
            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return albumItem;
        }
コード例 #15
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static Album EditAlbum(UserContainer currContext, Guid albumId, string title, string description, bool isOpen)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);
            if (album == null)
                throw new BusinessLogicException("Указан неверный идентификатор альбома");

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value, true);
                    if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут редактировать альбом группы");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя редактировать чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            album.Title = title;
            album.Description = description;
            album.IsOpen = isOpen;
            album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return album;
        }
コード例 #16
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static void DeleteAlbum(UserContainer currContext, Album album)
        {
            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value, true);
                    if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут удалить альбом группы");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя удалить чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            DataService.PerThread.AlbumSet.DeleteObject(album);
            DataService.PerThread.SaveChanges();
        }
コード例 #17
0
        public static AlbumItem AddVideo(UserContainer currContext, Guid albumId, string title, string description, string url, string embedCode)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);

            if (album == null)
            {
                throw new BusinessLogicException("Указан неверный идентификатор");
            }

            if (string.IsNullOrWhiteSpace(title))
            {
                throw new BusinessLogicException("Не указано название видео");
            }

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                    {
                        throw new BusinessLogicException("Вы не состоите в группе");
                    }

                    if (album.IsOpen)
                    {
                        if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
                        {
                            throw new BusinessLogicException("Только члены группы могут добавлять видео в альбом");
                        }
                    }
                    else if (gm.State != (byte)GroupMemberState.Moderator)
                    {
                        throw new BusinessLogicException("Только модераторы могут добавлять видео в альбом");
                    }
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                    {
                        throw new BusinessLogicException("Нельзя добавлять видео в чужой альбом");
                    }
                }
                else
                {
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
                }
            }

            string src;

            if (!string.IsNullOrWhiteSpace(embedCode))
            {
                using (var sgml = new SgmlReader())
                {
                    sgml.InputStream = new StringReader(embedCode);
                    sgml.Read();
                    src = sgml.GetAttribute("src");
                }
            }
            else if (!string.IsNullOrWhiteSpace(url))
            {
                var uri = new Uri(url);
                src = url; // TODO: мб лучше regexp для вычленения src

                switch (uri.Host.Replace("www.", string.Empty))
                {
                case "youtube.com":
                    //src = uri.Scheme + "://" + uri.Host + "/embed/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First(); // это для iframe
                    src = uri.Scheme + "://" + uri.Host + "/v/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First();
                    break;

                case "youtu.be":
                    //src = uri.Scheme + "://youtube.com/embed/" + uri.Segments[1]; // это для iframe
                    src = uri.Scheme + "://youtube.com/v/" + uri.Segments[1];
                    break;

                /*case "vimeo.com":
                 *  src = uri.Scheme + "://" + "player." + uri.Host + "/video" + uri.PathAndQuery;
                 *  break;
                 *
                 * case "dailymotion.com":
                 *  var query = uri.Fragment.Replace("#", string.Empty);
                 *  src = uri.Scheme + "://" + uri.Host + "/embed/video/" + HttpUtility.ParseQueryString(query).GetValues("videoId").First();
                 *  break;*/

                case "e2-e4.tv":
                    src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                    break;

                case "e2e4.tv":
                    src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                    break;
                }
            }
            else
            {
                throw new BusinessLogicException("Источник видео не указан");
            }

            var albumItem = new AlbumItem
            {
                AlbumId      = albumId,
                Title        = title,
                Description  = description,
                Type         = (byte)AlbumItemType.Video,
                Src          = src,
                CreationDate = DateTime.Now
            };

            DataService.PerThread.AlbumItemSet.AddObject(albumItem);
            DataService.PerThread.LoadProperty(albumItem, x => x.Album);

            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return(albumItem);
        }
コード例 #18
0
        public static AlbumItem AddImage(UserContainer currContext, Guid albumId, string title, string description, string fileName)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);

            if (album == null)
            {
                throw new BusinessLogicException("Указан неверный идентификатор");
            }

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                    {
                        throw new BusinessLogicException("Вы не состоите в группе");
                    }

                    if (album.IsOpen)
                    {
                        if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
                        {
                            throw new BusinessLogicException("Только члены группы могут добавлять изображения в альбом");
                        }
                    }
                    else if (gm.State != (byte)GroupMemberState.Moderator)
                    {
                        throw new BusinessLogicException("Только модераторы могут добавлять изображения в альбом");
                    }
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                    {
                        throw new BusinessLogicException("Нельзя добавлять изображения в чужой альбом");
                    }
                }
                else
                {
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
                }
            }

            var albumItem = new AlbumItem
            {
                AlbumId      = albumId,
                Title        = title,
                Description  = description,
                Type         = (byte)AlbumItemType.Image,
                Src          = fileName,
                CreationDate = DateTime.Now
            };

            DataService.PerThread.AlbumItemSet.AddObject(albumItem);
            DataService.PerThread.LoadProperty <AlbumItem>(albumItem, x => x.Album);

            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return(albumItem);
        }