Exemplo n.º 1
0
        public async Task <IActionResult> Create(WeetCreateModel model, string returnUrl)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            await this.weetsService.Create(model, user);

            return(this.Redirect(returnUrl));
        }
Exemplo n.º 2
0
        public async Task Create(WeetCreateModel model, ApplicationUser user)
        {
            var entity = new Weet()
            {
                Id      = Guid.NewGuid().ToString(),
                Author  = user,
                Content = model.Content,
            };

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                entity.Tags = await this.ConvertToTags(entity.Id, model.Tags);
            }

            var imageName = Guid.NewGuid().ToString();
            var imageUrl  = await ApplicationCloudinary.UploadImage(this.cloudinary, model.Image, imageName);

            if (!string.IsNullOrEmpty(imageUrl))
            {
                entity.Image = new Media()
                {
                    Url     = imageUrl,
                    Name    = imageName,
                    Creator = user,
                };

                var tagId = await this.tagsService.GetTagId("Images");

                entity.Tags.Add(new WeetTag()
                {
                    TagId = tagId, WeetId = entity.Id
                });
            }

            await this.weetRepository.AddAsync(entity);

            await this.weetRepository.SaveChangesAsync();
        }