Пример #1
0
        public BinhLuan SuaBinhLuan(BinhLuan binhLuan)
        {
            if (binhLuan == null)
            {
                throw new ArgumentNullException("banTin", "Bản tin rỗng");
            }

            var thanhVien = ThanhVienStore.Get(binhLuan.ThanhVienId);

            if (thanhVien == null)
            {
                throw new Exception("Thành viên không tồn tại");
            }

            if (string.IsNullOrWhiteSpace(binhLuan.NoiDung))
            {
                throw new Exception("Bình luận phải có nội dung");
            }

            var binhLuanDb = BinhLuanStore.Get(binhLuan.BinhLuanId);

            if (binhLuanDb == null)
            {
                throw new Exception("Bình luận không tồn tại");
            }

            if (binhLuan.ThanhVienId != binhLuanDb.ThanhVienId)
            {
                throw new Exception("Bạn không có quyền sửa bản tin này");
            }

            // TODO: Cần lưu lại lịch sử sửa bản tin
            try
            {
                BanTinStore.Create(binhLuan);
                BanTinStore.SaveChanges();

                return(binhLuanDb);
            }
            catch (Exception ex)
            {
                throw new Exception("Chúng tôi đang gặp vấn đề khó về kỹ thuật khi đăng tin", ex);
            }
        }
Пример #2
0
        public void DangTuKhoa(BanTinTuKhoa banTinTK, TuKhoa tuKhoa)
        {
            if (banTinTK == null)
            {
                throw new ArgumentNullException("tuKhoa", "Tu Khoa rỗng");
            }

            var banTin = BanTinStore.Get(banTinTK.BanTinId);

            if (banTin == null)
            {
                throw new Exception("Ban tin không tồn tại");
            }

            var bantinTuKhoa = TuKhoaStore.Get(banTinTK.TuKhoaId);

            if (tuKhoa == null)
            {
                throw new Exception("Tu khoa khong ton tai");
            }
            if (string.IsNullOrWhiteSpace(tuKhoa.NoiDung))
            {
                throw new Exception("tu khoa phải có nội dung");
            }

            banTinTK.TuKhoaId = 1;

            try
            {
                BanTinTuKhoaStore.Create(banTinTK);
                BanTinTuKhoaStore.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("Chúng tôi đang gặp vấn đề khó về kỹ thuật khi đăng tin", ex);
            }
        }
Пример #3
0
        public BanTinTuKhoa SuaTuKhoa(BanTinTuKhoa banTinTK)
        {
            if (banTinTK == null)
            {
                throw new ArgumentNullException("banTin", "Bản tin rỗng");
            }

            var banTin = BanTinStore.Get(banTinTK.BanTinId);

            if (banTin == null)
            {
                throw new Exception("Ban tin không tồn tại");
            }

            var tuKhoaDb = TuKhoaStore.Get(banTinTK.TuKhoaId);

            if (banTinTK == null)
            {
                throw new Exception("Tu khoa khong ton tai");
            }

            //if (banTinTK.ThanhVienId != tuKhoaDb.ThanhVienId)
            //    throw new Exception("Bạn không có quyền sửa bản tin này");

            // TODO: Cần lưu lại lịch sử sửa bản tin
            try
            {
                BanTinTuKhoaStore.Create(banTinTK);
                BanTinTuKhoaStore.SaveChanges();
                return(banTinTK);
            }
            catch (Exception ex)
            {
                throw new Exception("Chúng tôi đang gặp vấn đề khó về kỹ thuật khi đăng tin", ex);
            }
        }