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 })); }
public void AddAnnouncement() { GetInputOfAnnouncement(); var announcement = new Announcement(InputTittle, InputDescription); _context.Announcements.Add(announcement); _context.SaveChanges(); }
public bool SaveAnnouncement(Announcement announcement) { _announcementContext.Announcements.Add(announcement); return(_announcementContext.SaveChanges() > 0); }
public void SaveChanges() { db.SaveChanges(); }