/// <summary> /// Creates a view-model for the announcement /// </summary> /// <param name="announcement"></param> public AnnouncementViewModel(Announcement announcement) { Id = announcement.Id; Title = announcement.Title; Description = announcement.Description; CreatedOn = announcement.CreatedOn; Class = new ClassViewModel(announcement.Class); }
/// <summary> /// Creates a new announcement from the given model /// </summary> /// <param name="cam"></param> /// <returns></returns> public async Task<Announcement> CreateAnnouncement(CreateAnnouncementModel cam) { var @class = await _db.Classes.FindAsync(cam.ClassId); if(@class == null) { return null; } Announcement announcement = new Announcement { Title = cam.Title, CreatedOn = DateTime.UtcNow, Description = cam.Description, Class = @class }; _db.Announcements.Add(announcement); await _db.SaveChangesAsync(); return announcement; }