public void ThemChuongTrinh(ChuongTrinhHoatDongDto chuongTrinhDto) { var chuongTrinh = new ChuongTrinhHoatDong(chuongTrinhDto); DanhSachChuongTrinhHoatDong.Add(chuongTrinh); var thongBaoMoi = ThongBaoHoatDong.TaoThongBaoThemChuongTrinh(this); foreach (var sinhVien in DanhSachSinhVienTheoDoi.Select(td => td.SinhVien)) { sinhVien.ThongBaoHoatDong(thongBaoMoi); } }
public IHttpActionResult SaveChuongTrinhHoatDong(ChuongTrinhHoatDongDto chuongTrinhDto) { if (!ModelState.IsValid) { return(BadRequest()); } var userSinhVienId = User.Identity.GetSinhVienId(); ChuongTrinhHoatDong chuongTrinh; if (chuongTrinhDto.Id == 0) { //Lấy hoạt động var hoatDong = _context.DanhSachHoatDong.Include(hd => hd.DanhSachSinhVienTheoDoi.Select(tg => tg.SinhVien)) .SingleOrDefault(hd => hd.Id == chuongTrinhDto.HoatDongId); if (hoatDong == null) { return(NotFound()); } //Check quyền if (hoatDong.IdSinhVienTaoHd != userSinhVienId && !User.IsInRole("Admin") && !User.IsInRole("QuanLyHoatDong")) { return(BadRequest("Bạn không có thêm chương trình cho hoạt động này.")); } //Thêm hoạt động hoatDong.ThemChuongTrinh(chuongTrinhDto); _context.SaveChanges(); chuongTrinhDto.Id = hoatDong.DanhSachChuongTrinhHoatDong.Last().Id; return(Created(new Uri(Request.RequestUri + "/" + chuongTrinhDto.Id), chuongTrinhDto)); } //Lấy chương trình chuongTrinh = _context.DanhSachChuongTrinhHoatDong .Include(ct => ct.HoatDong) .SingleOrDefault(cthd => cthd.Id == chuongTrinhDto.Id); if (chuongTrinh == null) { return(NotFound()); } //Check quyền if (chuongTrinh.HoatDong.IdSinhVienTaoHd != userSinhVienId && !User.IsInRole("Admin") && !User.IsInRole("QuanLyHoatDong")) { return(BadRequest("Bạn không có quyền thay đổi chương trình cho hoạt động này.")); } //Thay đổi chương trình Mapper.Map(chuongTrinhDto, chuongTrinh); _context.SaveChanges(); return(Ok(chuongTrinhDto)); }
public ChuongTrinhHoatDong(ChuongTrinhHoatDongDto chuongTrinhDto) { Mapper.Map(chuongTrinhDto, this); }