コード例 #1
0
ファイル: AlbumViewModel.cs プロジェクト: arbium/democratia2
        public AlbumViewModel(Album album)
        {
            if (album == null)
                return;

            Id = album.Id;
            GroupId = album.GroupId;
            UserId = album.UserId;
            Title = album.Title;
            Description = album.Description;
            ChangeDate = album.ChangeDate;
            IsOpen = album.IsOpen;
            IsEmpty = album.Items.Count == 0;

            Items = album.Items.Select(x => new AlbumItemViewModel(x)).ToList();
            AddItem = new AlbumAddItemViewModel(album);
        }
コード例 #2
0
ファイル: AlbumViewModel.cs プロジェクト: arbium/democratia2
        public AlbumViewModel(Album album)
        {
            if (album == null)
            {
                return;
            }

            Id          = album.Id;
            GroupId     = album.GroupId;
            UserId      = album.UserId;
            Title       = album.Title;
            Description = album.Description;
            ChangeDate  = album.ChangeDate;
            IsOpen      = album.IsOpen;
            IsEmpty     = album.Items.Count == 0;

            Items   = album.Items.Select(x => new AlbumItemViewModel(x)).ToList();
            AddItem = new AlbumAddItemViewModel(album);
        }
コード例 #3
0
ファイル: AlbumController.cs プロジェクト: arbium/democratia2
        public ActionResult AddImage(AlbumAddItemViewModel model, HttpPostedFileBase image)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            if (!ModelState.IsValid)
                return View(model);

            string fileName;
            AlbumItem albumItem;

            if (image != null)
            {
                if (UploadImageValidationService.ValidateImageAndGetNewName(image, out fileName))
                {
                    albumItem = AlbumService.AddImage(UserContext.Current, model.AlbumId, model.Title, model.Description, fileName);

                    var path = Path.Combine(Server.MapPath("~/MediaContent/Albums/Images/"), fileName);
                    image.SaveAs(path);
                }
                else
                    throw new BusinessLogicException("Неверный формат файла");
            }
            else if (!string.IsNullOrWhiteSpace(model.Url))
            {
                byte[] content;
                var hwReq = (HttpWebRequest)WebRequest.Create(model.Url);
                var wResp = hwReq.GetResponse();
                var stream = wResp.GetResponseStream();

                if (stream == null)
                    throw new BusinessLogicException("Произошла ошибка при открытии ссылки");

                using (var br = new BinaryReader(stream))
                {
                    content = br.ReadBytes(5242880); // Ограничение по размеру в 5Мб
                    br.Close();
                }
                wResp.Close();

                if (UploadImageValidationService.ValidateImageTypeAndGetNewName(wResp, out fileName))
                {
                    albumItem = AlbumService.AddImage(UserContext.Current, model.AlbumId, model.Title, model.Description, fileName);

                    var path = Path.Combine(Server.MapPath("~/MediaContent/Albums/Images/"), fileName);
                    var fs = new FileStream(path, FileMode.Create);
                    var w = new BinaryWriter(fs);

                    try
                    {
                        w.Write(content);
                    }
                    finally
                    {
                        fs.Close();
                        w.Close();
                    }
                }
                else
                    throw new ValidationException("Указана некорректная ссылка");
            }
            else
                throw new ValidationException("Изображение не выбрано");

            if (Request.UrlReferrer != null && Request.UrlReferrer.Segments[2] == "foreditor/")
                return RedirectToAction("itemforeditor", "album", new { id = albumItem.Id, groupId = model.GroupId });

            return RedirectToAction("item", new { id = albumItem.Id });
        }
コード例 #4
0
ファイル: AlbumController.cs プロジェクト: arbium/democratia2
        public ActionResult AddVideo(AlbumAddItemViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            if (!ModelState.IsValid)
                return View(model);

            var albumItem = AlbumService.AddVideo(UserContext.Current, model.AlbumId, model.Title, model.Description, model.Url, model.EmbedCode);

            if (Request.UrlReferrer != null && Request.UrlReferrer.Segments[2] == "foreditor/")
                return RedirectToAction("itemforeditor", "album", new { id = albumItem.Id, groupId = model.GroupId });

            return RedirectToAction("item", new { id = albumItem.Id });
        }