Пример #1
0
        public async Task <IActionResult> AddAnnouncement(Announcement announcement, IFormFile file)
        {
            var userId    = _userManager.GetUserId(User);
            var imageName = await _announcementControllerService.UploadImages(file, userId);

            if (ModelState.IsValid & imageName != null)
            {
                announcement.DateAdded        = DateTime.Now.ToString("dd/MM/yyyy HH:mm");
                announcement.AplicationUserId = userId;

                _announcementContext.Announcements.Add(announcement);
                _announcementContext.SaveChanges();

                Image image = new Image();
                image.Name = imageName;
                AnnouncementImage announcementImage = new AnnouncementImage();
                _announcementContext.Images.Add(image);
                _announcementContext.SaveChanges();

                announcementImage.AnnouncementId = announcement.AnnouncementId;
                announcementImage.Image          = image;
                _announcementContext.AnnouncementImages.Add(announcementImage);
                _announcementContext.SaveChanges();

                return(RedirectToActionPermanent("Index", "Home"));
            }

            ViewBag.Message = "Please upload the photo";
            return(View(new AnnouncementListViewModel
            {
                Announcement = announcement,
                Categories = _categoryRepository.AllCategories
            }));
        }
Пример #2
0
        public void AddAnnouncement()
        {
            GetInputOfAnnouncement();
            var announcement = new Announcement(InputTittle, InputDescription);

            _context.Announcements.Add(announcement);
            _context.SaveChanges();
        }
Пример #3
0
        public bool SaveAnnouncement(Announcement announcement)
        {
            _announcementContext.Announcements.Add(announcement);

            return(_announcementContext.SaveChanges() > 0);
        }
Пример #4
0
 public void SaveChanges()
 {
     db.SaveChanges();
 }