Esempio n. 1
0
        //private readonly Microsoft.AspNetCore.Identity.UserManager<User> _userManager;



        public Publication AddPublicationDB(CreatePublicationViewModel model, User user)
        {
            byte[] imageData  = null;
            byte[] imageData2 = null;
            using (var binaryReader = new BinaryReader(model.AvatarPost.OpenReadStream()))
            {
                imageData = binaryReader.ReadBytes((int)model.AvatarPost.Length);
            }
            using (var binaryReader = new BinaryReader(model.AvatarPost2.OpenReadStream()))
            {
                imageData2 = binaryReader.ReadBytes((int)model.AvatarPost2.Length);
            }

            var topic = _topic.GetTopicDB(model.TopicName);


            Publication publ = new Publication
            {
                PublicationName = model.PublicationName,
                Discription     = model.Discription,
                PublicationText = model.PublicationText,
                AvatarPost      = imageData,
                AvatarPost2     = imageData2,
                isFavorite      = model.isFavorite,
                TopicId         = topic.Id,
                Topic           = topic, //_topic.GetTopicDB(model.TopicName),
                User            = user,
            };

            publ.LikePost = 0;
            _publication.AddPublicationDB(publ);
            return(publ);
        }
Esempio n. 2
0
        public IActionResult CreatePost(CreatePublicationViewModel model)
        {
            byte[] imageData = null;
            // считываем переданный файл в массив байтов
            using (var binaryReader = new BinaryReader(model.AvatarPost.OpenReadStream()))
            {
                imageData = binaryReader.ReadBytes((int)model.AvatarPost.Length);
            }

            string      a    = _userManager.GetUserId(User);
            Publication publ = new Publication {
                PublicationName = model.PublicationName,
                Discription     = model.Discription,
                PublicationText = model.PublicationText,
                AvatarPost      = imageData,
                isFavorite      = model.isFavorite,
                TopicId         = _topic.GetTopicDB(model.TopicName).Id,
                Topic           = _topic.GetTopicDB(model.TopicName),
                User            = _user.GetUserDB(_userManager.GetUserId(User)),
            };

            _publication.AddPublicationDB(publ);
            return(RedirectToAction("CreatePost"));
        }