Ejemplo n.º 1
0
        public async Task <IActionResult> PublishPost(AdvertisingViewModel model)
        {
            try
            {
                foreach (var item in model.ImageFile)
                {
                    if (item.Length > 0)
                    {
                        using (var stream = new MemoryStream())
                        {
                            await item.CopyToAsync(stream);

                            model.Image = stream.ToArray();
                        }
                    }
                }

                var partner = await _partnerRepository.GetByIdAsync(model.PartnerId);

                if (partner == null)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                Advertising post = _converter.ToAdvertising(model, true, partner);

                //send notification
                await _notificationHelper.CreateNotificationAsync(post.PostGuidId, UserType.SuperUser, "", NotificationType.Advertising);

                post.CreatedBy = await GetCurrentUser();

                post.CreateDate = DateTime.UtcNow;

                await _advertisingRepository.CreateAsync(post);

                return(RedirectToAction(nameof(NewsIndex)));
            }

            catch (Exception exception)
            {
                ModelState.AddModelError(string.Empty, exception.Message);
            }
            return(RedirectToAction(nameof(NewsIndex)));
        }