Beispiel #1
0
        public async Task DeleteById(int id)
        {
            PhotoCategory category = await _context.PhotoCategory.FindAsync(id);

            _context.PhotoCategory.Remove(category);
            _context.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi()
        {
            Browser = new Browser();

            Users    = new UsersCategory(this);
            Friends  = new FriendsCategory(this);
            Status   = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups   = new GroupsCategory(this);
            Audio    = new AudioCategory(this);
            Wall     = new WallCategory(this);
            Database = new DatabaseCategory(this);
            Utils    = new UtilsCategory(this);
            Fave     = new FaveCategory(this);
            Video    = new VideoCategory(this);
            Account  = new AccountCategory(this);
            Photo    = new PhotoCategory(this);
            Docs     = new DocsCategory(this);
            Likes    = new LikesCategory(this);
            Pages    = new PagesCategory(this);
            Gifts    = new GiftsCategory(this);
            Apps     = new AppsCategory(this);
            NewsFeed = new NewsFeedCategory(this);
            Stats    = new StatsCategory(this);
            Auth     = new AuthCategory(this);

            RequestsPerSecond = 3;
        }
Beispiel #3
0
        public async Task <PhotoCategory> CreateOne(PhotoCategory photoCategory)
        {
            await _context.PhotoCategory.AddAsync(photoCategory);

            _context.SaveChanges();
            return(photoCategory);
        }
        public void Calculate(
            string rootPath,
            PhotoCategory category,
            string baseFileName,
            string contentType,
            int count,
            bool isThumb,
            string expectedPath)
        {
            // Arrange
            rootPath     = rootPath.Replace("/", Path.DirectorySeparatorChar.ToString());
            expectedPath = expectedPath.Replace("/", Path.DirectorySeparatorChar.ToString());

            // Act
            var filePath = pathCalculator.CalculatePath(
                rootPath,
                category,
                baseFileName,
                contentType,
                count,
                isThumb);

            // Assert
            filePath.Should().Be(expectedPath);
        }
        public IActionResult Post(PhotoCategory data)
        {
            data.isActive = true;
            var createdAbout = service.Add(data);

            return(CreatedAtAction("Get", new { id = createdAbout.Data.Id }, createdAbout));
        }
Beispiel #6
0
        private async Task <PhotoIdentifier> AddThumbnail(
            [NotNull] Stream photoData,
            string filename,
            string contentType,
            PhotoCategory photoCategory)
        {
            if (photoData == null)
            {
                throw new ArgumentNullException(nameof(photoData));
            }

            var thumbnailPhotoData = await GeneratedThumbnailAsync(photoData, photoCategory, contentType);

            var photoIdentifier = new PhotoIdentifier(photoCategory, true, filename);

            photoData.Seek(0, 0);

            await photoStore.AddPhotoAsync(
                new Photo(
                    photoIdentifier,
                    "image/jpg",
                    thumbnailPhotoData));

            return(photoIdentifier);
        }
Beispiel #7
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi(ICaptchaSolver captchaSolver = null)
        {
            Browser = new Browser();

            Users    = new UsersCategory(this);
            Friends  = new FriendsCategory(this);
            Status   = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups   = new GroupsCategory(this);
            Audio    = new AudioCategory(this);
            Wall     = new WallCategory(this);
            Board    = new BoardCategory(this);
            Database = new DatabaseCategory(this);
            Utils    = new UtilsCategory(this);
            Fave     = new FaveCategory(this);
            Video    = new VideoCategory(this);
            Account  = new AccountCategory(this);
            Photo    = new PhotoCategory(this);
            Docs     = new DocsCategory(this);
            Likes    = new LikesCategory(this);
            Pages    = new PagesCategory(this);
            Gifts    = new GiftsCategory(this);
            Apps     = new AppsCategory(this);
            NewsFeed = new NewsFeedCategory(this);
            Stats    = new StatsCategory(this);
            Auth     = new AuthCategory(this);
            Markets  = new MarketsCategory(this);
            Execute  = new ExecuteCategory(this);

            RequestsPerSecond = 3;

            MaxCaptchaRecognitionCount = 5;
            _captchaSolver             = captchaSolver;
        }
Beispiel #8
0
        public async Task Enrich(Photo photo, SourceDataDto sourceData)
        {
            await Task.Run(() =>
            {
                photo.PhotoCategories = new List <PhotoCategory>();
                foreach (var category in sourceData.ImageAnalysis.Categories)
                {
                    var catModel = _categoryRepository.GetByCondition(t => t.Name == category.Name).FirstOrDefault();

                    if (catModel == null)
                    {
                        catModel = new Category
                        {
                            Name = category.Name
                        };
                    }

                    var photoCategory = new PhotoCategory()
                    {
                        Photo    = photo,
                        Category = catModel,
                        Score    = category.Score
                    };

                    photo.PhotoCategories.Add(photoCategory);
                }
            });
        }
Beispiel #9
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi()
        {
            Browser = new Browser();

            Users = new UsersCategory(this);
            Friends = new FriendsCategory(this);
            Status = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups = new GroupsCategory(this);
            Audio = new AudioCategory(this);
            Wall = new WallCategory(this);
            Database = new DatabaseCategory(this);
            Utils = new UtilsCategory(this);
            Fave = new FaveCategory(this);
            Video = new VideoCategory(this);
            Account = new AccountCategory(this);
            Photo = new PhotoCategory(this);
            Docs = new DocsCategory(this);
            Likes = new LikesCategory(this);
            Pages = new PagesCategory(this);
            Gifts = new GiftsCategory(this);
            Apps = new AppsCategory(this);
            NewsFeed = new NewsFeedCategory(this);
            Stats = new StatsCategory(this);
            Auth = new AuthCategory(this);
            Markets = new MarketsCategory(this);

            RequestsPerSecond = 3;
        }
Beispiel #10
0
        public CategoryViewModel BuildViewModel(PhotoCategory repositoryModel = null)
        {
            CategoryViewModel viewModel = new CategoryViewModel();

            if (repositoryModel == null)
            {
                viewModel.StatusText           = "Initialising category";
                viewModel.StatusCode           = CategoryStatusCodes.SettingUp;
                viewModel.PhotoNamingThemeCode = PhotoNamingThemes.ThemeCodes.Fruit;
            }
            else
            {
                viewModel.CategoryId           = repositoryModel.CategoryId;
                viewModel.CategoryName         = repositoryModel.CategoryName;
                viewModel.PhotoNamingThemeCode = repositoryModel.PhotoNamingThemeCode;
                if (CategoryStatusCodes.GetAll().Contains(repositoryModel.StatusCode))
                {
                    viewModel.StatusCode = repositoryModel.StatusCode;
                    viewModel.StatusText = repositoryModel.StatusText;
                }
                else
                {
                    viewModel.StatusText = "Initialising category";
                    viewModel.StatusCode = CategoryStatusCodes.SettingUp;
                }
            }
            viewModel = BuildViewModelDropdownCriteria(viewModel);
            return(viewModel);
        }
        public async Task <IActionResult> Add(CategoryViewModel viewModel)
        {
            if (viewModel == null)
            {
                ModelState.AddModelError(string.Empty, "View model is null");
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> categoryUniqueResult = await CategoryViewModelIsValid(viewModel);

                ModelState.AddProcessResultErrors(categoryUniqueResult);
            }

            if (ModelState.IsValid)
            {
                CategoryViewModelMapper mapper          = new CategoryViewModelMapper();
                PhotoCategory           repositoryModel = mapper.BuildRepositoryModel(viewModel, null);
                ProcessResult <bool>    saveResult      = _db.SaveAdditions(repositoryModel);
                ModelState.AddProcessResultErrors(saveResult);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                CategoryViewModelMapper mapper = new CategoryViewModelMapper();
                viewModel = mapper.BuildViewModelDropdownCriteria(viewModel);
                return(View(viewModel));
            }
        }
Beispiel #12
0
        public ActionResult Delete(int id)
        {
            PhotoCategory PhotoCategory = _PhotoCategoryService.GetByID(id);

            _PhotoCategoryService.Remove(PhotoCategory);
            return(Redirect("/SysAdmin/PhotoCategory/List"));
        }
Beispiel #13
0
        public ViewPhotosViewModel BuildViewModel(PhotoCategory category)
        {
            ViewPhotosViewModel viewModel = new ViewPhotosViewModel();

            viewModel.CategoryId = category.CategoryId;
            viewModel.StatusCode = category.StatusCode;
            return(viewModel);
        }
Beispiel #14
0
        public ActionResult CreatePhotoCategory(PhotoCategory photoCategory)
        {
            this.photoRepository.AddCategory(photoCategory);

            this.ViewData["categoyName"] = photoCategory.Name;

            return(this.RedirectToAction("CategoryCreated"));
        }
Beispiel #15
0
        /// <summary>Gets the category by id.</summary>
        /// <param name="id">The category id.</param>
        /// <returns>The photo category.</returns>
        public PhotoCategory GetCategoryById(int id)
        {
            PhotoCategory category = this.Session.Get <PhotoCategory>(id);

            this.Logger.Debug("Got category {0} for category id '{1}'", category, id);

            return(category);
        }
Beispiel #16
0
        public DeleteCategoryViewModel BuildViewModel(PhotoCategory repositoryModel)
        {
            DeleteCategoryViewModel viewModel = new DeleteCategoryViewModel();

            viewModel.CategoryId   = repositoryModel.CategoryId;
            viewModel.CategoryName = repositoryModel.CategoryName;
            return(viewModel);
        }
Beispiel #17
0
        public ActionResult Update(PhotoCategoryDTO PhotoCategoryDTO)
        {
            PhotoCategory PhotoCategory = _PhotoCategoryService.GetByID(PhotoCategoryDTO.ID);

            PhotoCategory.Name        = PhotoCategoryDTO.Name;
            PhotoCategory.Explanation = PhotoCategoryDTO.Explanation;
            _PhotoCategoryService.Update(PhotoCategory);
            return(Redirect("/SysAdmin/PhotoCategory/List"));
        }
 public IActionResult Update([FromBody] PhotoCategory data)
 {
     if (service.Get(x => x.Id == data.Id) != null)
     {
         data.isActive = true;
         return(Ok(service.Update(data)));
     }
     return(NotFound());
 }
        public async Task <IActionResult> Update(int id)
        {
            Album album = await _albumRepository.GetById(id);

            PhotoCategory        category   = album.Category;
            List <PhotoCategory> categories = await _categoryRepository.GetAll();

            ViewBag.Categories = new SelectList(categories, "Id", "Name", category);
            return(View(album));
        }
        public ActionResult CompleteUpload(PhotoCategory category, PhotoAlbum album)
        {
            album.Name          = album.Name.Trim();
            album.PhotoCategory = this.photoRepository.GetCategoryById(category.Id);

            MediaCommUser uploader = this.userRepository.GetUserByName(this.User.Identity.Name);

            this.photoRepository.AddPhotos(album, uploader);

            return(this.RedirectToAction("UploadSuccessFull"));
        }
Beispiel #21
0
        public async Task <IActionResult> Index(int categoryId)
        {
            PhotoCategory category = await _categoryRepository.GetById(categoryId);

            ViewBag.Category = category;

            List <Album> albums = await _albumRepository.GetAll();

            albums = albums.Where(x => x.CategoryId == categoryId).ToList();
            return(View(albums));
        }
Beispiel #22
0
        public CategoryListItemViewModel BuildViewModel(PhotoCategory repositoryModel)
        {
            CategoryListItemViewModel viewModel = new CategoryListItemViewModel();

            viewModel.CategoryId     = repositoryModel.CategoryId;
            viewModel.CategoryName   = repositoryModel.CategoryName;
            viewModel.StatusCode     = repositoryModel.StatusCode;
            viewModel.StatusCodeText = CategoryStatusCodes.GetStatusText(repositoryModel.StatusCode);
            viewModel.StatusText     = repositoryModel.StatusText;
            return(viewModel);
        }
Beispiel #23
0
        public async Task <PhotoCategory> UpdateOne(PhotoCategory photoCategory)
        {
            PhotoCategory category = await _context.PhotoCategory.FindAsync(photoCategory.Id);

            category.Name              = photoCategory.Name;
            category.Description       = photoCategory.Description;
            category.CoverPhotoId      = photoCategory.CoverPhotoId;
            category.BackgroundImageId = photoCategory.BackgroundImageId;
            _context.SaveChanges();
            return(category);
        }
Beispiel #24
0
 public PhotoCategory BuildRepositoryModel(CategoryViewModel viewModel, PhotoCategory existingRepositoryModel)
 {
     if (existingRepositoryModel == null)
     {
         existingRepositoryModel = new PhotoCategory();
     }
     existingRepositoryModel.CategoryName         = viewModel.CategoryName;
     existingRepositoryModel.StatusCode           = viewModel.StatusCode;
     existingRepositoryModel.StatusText           = viewModel.StatusText;
     existingRepositoryModel.PhotoNamingThemeCode = viewModel.PhotoNamingThemeCode;
     return(existingRepositoryModel);
 }
        public async Task <IActionResult> UpdateById(int id, bool isSuccess = false)
        {
            List <Photo> photos = await _photoRepository.GetAll();

            photos         = photos.Where(x => x.AlbumId == null).ToList();
            ViewBag.Photos = photos;

            PhotoCategory photoCategory = await _categoryRepository.GetById(id);

            ViewBag.IsSuccess = isSuccess;
            return(View(photoCategory));
        }
 private static string CombinePath(
     string rootPath,
     PhotoCategory category,
     bool isThumb,
     string fileName)
 {
     return(Path.Combine(
                rootPath,
                category.ToString().ToLower(),
                isThumb ? ThumbSubPath : "",
                fileName));
 }
Beispiel #27
0
        public ActionResult Update(int id)
        {
            PhotoCategory    PhotoCategory    = _PhotoCategoryService.GetByID(id);
            PhotoCategoryDTO PhotoCategoryDTO = new PhotoCategoryDTO()
            {
                ID          = PhotoCategory.ID,
                Explanation = PhotoCategory.Explanation,
                Name        = PhotoCategory.Name,
            };

            return(View(PhotoCategoryDTO));
        }
Beispiel #28
0
 public ActionResult Add(PhotoCategory _PhotoCategory)
 {
     _PhotoCategory.UserID = _UserService.GetByDefault(x => x.UserName == User.Identity.Name).ID;
     if (_PhotoCategoryService.Any(x => x.Name.ToLower() == _PhotoCategory.Name.ToLower()))
     {
         return(View());
     }
     else
     {
         _PhotoCategoryService.Add(_PhotoCategory);
         return(Redirect("/SysAdmin/PhotoCategory/List"));
     }
 }
Beispiel #29
0
        private async Task <PhotoAndThumbnailIdentifiers> AddPhotoWithThumbnail(PhotoCategory photoCategory,
                                                                                [NotNull] Stream photoData,
                                                                                string filename,
                                                                                string contentType)
        {
            if (photoData == null)
            {
                throw new ArgumentNullException(nameof(photoData));
            }

            return(new PhotoAndThumbnailIdentifiers(
                       await AddOriginalPhoto(photoData, filename, contentType, photoCategory),
                       await AddThumbnail(photoData, filename, contentType, photoCategory)));
        }
        public async Task <IActionResult> CreateOne(PhotoCategory photoCategory)
        {
            if (ModelState.IsValid)
            {
                PhotoCategory newCategory = await _categoryRepository.CreateOne(photoCategory);

                if (newCategory != null)
                {
                    return(RedirectToAction(nameof(CreateOne), new { isSuccess = true }));
                }
            }
            ModelState.AddModelError("", "创建失败,内容不符合规范,请重新输入。");
            return(View());
        }
        public async Task <IActionResult> Index(string categoryId = null)
        {
            List <Album> albums = await _albumRepository.GetAll();

            ViewBag.AllAlbumCount = (albums == null) ? 0 : albums.Count();
            //按照类型分组
            List <AlbumViewCategoryViewModel> categoryViewModelList = new List <AlbumViewCategoryViewModel>();
            var categoryGroups = albums.GroupBy(x => x.CategoryId).OrderBy(x => x.Key);

            foreach (var group in categoryGroups)
            {
                if (group.Key == null)
                {
                    categoryViewModelList.Add(new AlbumViewCategoryViewModel
                    {
                        CategoryId   = "null",
                        CategoryName = "未指定",
                        AlbumCount   = group.Count(),
                    });
                }
                else
                {
                    PhotoCategory category = await _categoryRepository.GetById((int)group.Key);

                    categoryViewModelList.Add(new AlbumViewCategoryViewModel
                    {
                        CategoryId   = group.Key.ToString(),
                        CategoryName = category.Name,
                        AlbumCount   = group.Count(),
                    });
                }
            }
            ViewBag.CategoryViewModel = categoryViewModelList;
            //接收传入的参数【类型】
            if (categoryId != null)
            {
                if (categoryId == "null")
                {
                    albums = albums.Where(x => x.CategoryId == null).ToList();
                }
                else
                {
                    int id = Int32.Parse(categoryId);
                    albums = albums.Where(x => x.CategoryId == id).ToList();
                }
            }

            return(View(albums));
        }
Beispiel #32
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi(ICaptchaSolver captchaSolver = null)
        {
            Browser = new Browser();

            Users = new UsersCategory(this);
            Friends = new FriendsCategory(this);
            Status = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups = new GroupsCategory(this);
            Audio = new AudioCategory(this);
            Wall = new WallCategory(this);
            Board = new BoardCategory(this);
            Database = new DatabaseCategory(this);
            Utils = new UtilsCategory(this);
            Fave = new FaveCategory(this);
            Video = new VideoCategory(this);
            Account = new AccountCategory(this);
            Photo = new PhotoCategory(this);
            Docs = new DocsCategory(this);
            Likes = new LikesCategory(this);
            Pages = new PagesCategory(this);
            Gifts = new GiftsCategory(this);
            Apps = new AppsCategory(this);
            NewsFeed = new NewsFeedCategory(this);
            Stats = new StatsCategory(this);
            Auth = new AuthCategory(this);
            Markets = new MarketsCategory(this);
            Execute = new ExecuteCategory(this);

            RequestsPerSecond = 3;

            MaxCaptchaRecognitionCount = 5;
            _captchaSolver = captchaSolver;
        }
Beispiel #33
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi()
        {
            Browser = new Browser();

            Users = new UsersCategory(this);
            Friends = new FriendsCategory(this);
            Status = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups = new GroupsCategory(this);
            Audio = new AudioCategory(this);
            Wall = new WallCategory(this);
            Database = new DatabaseCategory(this);
            Utils = new UtilsCategory(this);
            Fave = new FaveCategory(this);
            Video = new VideoCategory(this);
			Account = new AccountCategory(this);
            Photo = new PhotoCategory(this);
            Docs = new DocsCategory(this);
            Likes = new LikesCategory(this);
			
            RequestsPerSecond = 3;
            MaxCaptchaRecognitionCount = 5;
            AutoTokenRefresh = false;
        }
Beispiel #34
0
 private void CreatePhotoCategory()
 {
     var category = new PhotoCategory
     {
         Name = "Field",
         Description = "pictures of fields"
     };
     var category2 = new PhotoCategory
     {
         Name = "People",
         Description = "pictures of people"
     };
     _repository.Save(category);
     _repository.Save(category2);
 }
Beispiel #35
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="VkApi"/>.
        /// </summary>
        public VkApi()
        {
            Browser = new Browser();

            Users = new UsersCategory(this);
            Friends = new FriendsCategory(this);
            Status = new StatusCategory(this);
            Messages = new MessagesCategory(this);
            Groups = new GroupsCategory(this);
            Audio = new AudioCategory(this);
            Wall = new WallCategory(this);
            Database = new DatabaseCategory(this);
            Utils = new UtilsCategory(this);
            Fave = new FaveCategory(this);
            Video = new VideoCategory(this);
			Account = new AccountCategory(this);
            Photo = new PhotoCategory(this);
        }