Exemplo n.º 1
0
        public void DangTin(BanTin banTin, string noiDungTuKhoa)
        {
            if (banTin == null)
            {
                throw new ArgumentNullException("banTin", "Bản tin rỗng");
            }

            if (string.IsNullOrWhiteSpace(banTin.NoiDung))
            {
                throw new Exception("Bản tin phải có nội dung");
            }

            try
            {
                var thanhVien = ThanhVienRepository.Get(banTin.ThanhVienId);
                if (thanhVien == null)
                {
                    throw new Exception("Thành viên không tồn tại");
                }

                TuKhoa tuKhoa = null;
                if (!string.IsNullOrWhiteSpace(noiDungTuKhoa))
                {
                    noiDungTuKhoa = noiDungTuKhoa.Trim();
                    var tk = TuKhoaRepository.GetTuKhoaByNoiDung(noiDungTuKhoa);
                    if (tk == null)
                    {
                        tuKhoa         = new TuKhoa();
                        tuKhoa.NoiDung = noiDungTuKhoa;
                        TuKhoaRepository.Create(tuKhoa);
                        TuKhoaRepository.SaveChanges();
                    }
                    else
                    {
                        tuKhoa = tk;
                    }
                }

                banTin.ThoiGian = DateTime.Now;

                BanTinRepository.Create(banTin);
                BanTinRepository.SaveChanges();

                if (tuKhoa != null && tuKhoa.TuKhoaId > 0)
                {
                    var banTinTuKhoa = new BanTinTuKhoa
                    {
                        BanTinId = banTin.BanTinId,
                        TuKhoaId = tuKhoa.TuKhoaId
                    };
                    BanTinTuKhoaRepository.Create(banTinTuKhoa);
                }

                BanTinTuKhoaRepository.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);
            }
        }
Exemplo n.º 2
0
        public IActionResult Put(string id, [FromBody] TuKhoa tu_khoa)
        {
            DataResponse res = new DataResponse();

            try
            {
                res.success = true;
                //validate
                if (string.IsNullOrEmpty(tu_khoa.tu_khoa))
                {
                    res.success = false;
                    res.msg     = "Chưa có từ khóa";
                }
                //if (string.IsNullOrEmpty(tu_khoa.id_chien_dich))
                //{
                //    res.success = false;
                //    res.msg = "Chưa có chiến dịch";
                //}
                //if (string.IsNullOrEmpty(tu_khoa.id_quang_cao))
                //{
                //    res.success = false;
                //    res.msg = "Chưa có quảng cáo";
                //}
                if (!string.IsNullOrEmpty(tu_khoa.url_cuoi))
                {
                    if (!IsValidUri(tu_khoa.url_cuoi))
                    {
                        res.success = false;
                        res.msg     = "Url cuối chưa đúng định dạng";
                    }
                }
                if (!res.success)
                {
                    return(Ok(res));
                }
                tu_khoa.id = id;
                SetMetaData(tu_khoa, true);

                res.success = TuKhoaRepository.Instance.PartiallyUpdated(tu_khoa.id, (int)tu_khoa.trang_thai, tu_khoa.tu_khoa, (int)tu_khoa.kieu_doi_sanh, tu_khoa.url_cuoi);
                if (res.success)
                {
                    res.msg = "Sửa thành công";
                    //add id_tu_khoa va item quang_cao
                    //if (!QuangCaoRepository.Instance.UpdateIdTuKhoa(tu_khoa.id_quang_cao, tu_khoa.id, out string msg))
                    //{
                    //    res.success = false;
                    //    res.msg = $"Có lỗi: {msg}";
                    //}
                    //res.data = "";
                }
            }
            catch (Exception ex)
            {
                res.msg = ex.Message; res.success = false;
            }

            return(Ok(res));
        }
Exemplo n.º 3
0
        public bool Update(TuKhoa data)
        {
            if (data.kieu_doi_sanh == KieuDoiSanh.DOI_SANH_RONG)
            {
                data.query = new QueryStringQuery()
                {
                    Query = data.tu_khoa, DefaultField = "tu_khoa"
                };
            }
            var re = client.Update <TuKhoa>(data.id, u => u.Doc(data));

            return(re.Result == Result.Updated || re.Result == Result.Noop);
        }
Exemplo n.º 4
0
        public TuKhoaMap Map(TuKhoa tu_khoa, Dictionary <string, ChienDich> dic_chien_dich, Dictionary <string, QuangCao> dic_quang_cao)
        {
            TuKhoaMap tu_khoa_map = new TuKhoaMap()
            {
                chi_phi               = tu_khoa.chi_phi,
                id                    = tu_khoa.id,
                id_chien_dich         = tu_khoa.id_chien_dich,
                id_quang_cao          = tu_khoa.id_quang_cao,
                kieu_doi_sanh         = tu_khoa.kieu_doi_sanh,
                luot_chuyen_doi       = tu_khoa.luot_chuyen_doi,
                luot_click            = tu_khoa.luot_click,
                luot_hien_thi         = tu_khoa.luot_hien_thi,
                ngay_sua              = tu_khoa.ngay_sua,
                ngay_tao              = tu_khoa.ngay_tao,
                nguoi_sua             = tu_khoa.nguoi_sua,
                nguoi_tao             = tu_khoa.nguoi_tao,
                trang_thai            = tu_khoa.trang_thai,
                tu_khoa               = tu_khoa.tu_khoa,
                url_cuoi              = tu_khoa.url_cuoi,
                ty_le_tuong_tac       = tu_khoa.ty_le_tuong_tac,
                cpc_trung_binh        = tu_khoa.cpc_trung_binh,
                trang_thai_chien_dich = tu_khoa.trang_thai_chien_dich,
                trang_thai_quang_cao  = tu_khoa.trang_thai_quang_cao
            };

            try
            {
                if (dic_chien_dich == null)
                {
                    dic_chien_dich = new Dictionary <string, ChienDich>();
                }
                if (dic_quang_cao == null)
                {
                    dic_quang_cao = new Dictionary <string, QuangCao>();
                }

                if (dic_chien_dich.TryGetValue(tu_khoa.id_chien_dich, out ChienDich cd))
                {
                    tu_khoa_map.chien_dich = cd.ten;
                }
                if (dic_quang_cao.TryGetValue(tu_khoa.id_quang_cao, out QuangCao qc))
                {
                    tu_khoa_map.quang_cao = qc.ten_hien_thi;
                }
            }
            catch (Exception)
            {
            }
            return(tu_khoa_map);
        }
Exemplo n.º 5
0
        public string IndexRetId(TuKhoa data)
        {
            if (data.kieu_doi_sanh == KieuDoiSanh.DOI_SANH_RONG)
            {
                data.query = new QueryStringQuery()
                {
                    Query = data.tu_khoa, DefaultField = "tu_khoa"
                };
            }


            if (Index(_DefaultIndex, data, string.Empty, out string id))
            {
                return(id);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        public IActionResult Post([FromBody] TuKhoa tu_khoa)
        {
            DataResponse res = new DataResponse();

            try
            {
                res.success = true;
                //validate
                if (string.IsNullOrEmpty(tu_khoa.tu_khoa))
                {
                    res.success = false;
                    res.msg     = "Chưa có từ khóa";
                }
                if (string.IsNullOrEmpty(tu_khoa.id_chien_dich))
                {
                    var id_chien_dich = QuangCaoRepository.Instance.GetById(tu_khoa.id_quang_cao, new[] { "id_chien_dich" }).id_chien_dich;
                    //res.success = false;
                    //res.msg = "Chưa có chiến dịch";

                    tu_khoa.id_chien_dich = id_chien_dich;
                }

                if (!string.IsNullOrEmpty(tu_khoa.id_chien_dich))
                {
                    var chien_dich = ChienDichRepository.Instance.GetById(tu_khoa.id_chien_dich, new[] { "*" });

                    tu_khoa.dia_diem_muc_tieu = chien_dich.dia_diem_muc_tieu;
                    tu_khoa.dia_diem_loai_tru = chien_dich.dia_diem_loai_tru;
                }

                if (string.IsNullOrEmpty(tu_khoa.id_quang_cao))
                {
                    res.success = false;
                    res.msg     = "Chưa có quảng cáo";
                }
                if (!string.IsNullOrEmpty(tu_khoa.url_cuoi))
                {
                    if (!IsValidUri(tu_khoa.url_cuoi))
                    {
                        res.success = false;
                        res.msg     = "Url cuối chưa đúng định dạng";
                    }
                }
                if (!res.success)
                {
                    return(Ok(res));
                }

                SetMetaData(tu_khoa, false);

                string ret_id = TuKhoaRepository.Instance.IndexRetId(tu_khoa);
                res.success = !string.IsNullOrEmpty(ret_id);
                if (res.success)
                {
                    //add id_tu_khoa va item quang_cao
                    if (!QuangCaoRepository.Instance.UpdateIdTuKhoa(tu_khoa.id_quang_cao, ret_id, out string msg))
                    {
                        res.success = false;
                        res.msg     = $"Có lỗi: {msg}";
                    }

                    var select_tu_khoa = TuKhoaRepository.Instance.GetById(ret_id, new[] { "*" });
                    if (select_tu_khoa != null)
                    {
                        var trang_thai_quang_cao  = QuangCaoRepository.Instance.GetById(select_tu_khoa.id_quang_cao, new[] { "*" })?.trang_thai;
                        var trang_thai_chien_dich = ChienDichRepository.Instance.GetById(select_tu_khoa.id_chien_dich, new[] { "*" })?.trang_thai;
                        TuKhoaRepository.Instance.UpdateTrangThaiTkTheoQuangCao(ret_id, (int)trang_thai_quang_cao);
                        TuKhoaRepository.Instance.UpdateTrangThaiTkTheoChienDich(ret_id, (int)trang_thai_chien_dich);
                    }

                    res.data = ret_id;
                }
            }
            catch (Exception ex)
            {
                res.msg = ex.Message; res.success = false;
            }

            return(Ok(res));
        }
Exemplo n.º 8
0
 public void Create(TuKhoa tuKhoa)
 {
     Db.TuKhoas.Add(tuKhoa);
 }
Exemplo n.º 9
0
 public void CreateTuKhoa(TuKhoa tuKhoa)
 {
     throw new NotImplementedException();
 }